pulumi-automation-api by pulumi/agent-skills
npx skills add https://github.com/pulumi/agent-skills --skill pulumi-automation-api在以下场景中调用此技能:
Automation API 提供了对 Pulumi 操作的程序化访问。无需从 CLI 运行 pulumi up,而是在代码中调用执行相同操作的函数。
import * as automation from "@pulumi/pulumi/automation";
// 创建或选择堆栈
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
projectName: "my-project",
program: async () => {
// 你的 Pulumi 程序写在这里
},
});
// 以编程方式运行 pulumi up
const upResult = await stack.up({ onOutput: console.log });
console.log(`更新摘要:${JSON.stringify(upResult.summary)}`);
多堆栈编排:
当将基础设施拆分为多个专注的项目时,Automation API 通过跨堆栈编排操作来帮助抵消增加的复杂性:
infrastructure → platform → application
↓ ↓ ↓
(VPC) (Kubernetes) (Services)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
Automation API 确保正确的执行顺序,无需人工干预。
自助服务平台:
构建内部工具,让开发人员无需学习 Pulumi 即可请求基础设施:
嵌入式基础设施:
可配置自身基础设施的应用程序:
替换脆弱的脚本:
如果你有 Bash 脚本或 Makefile 将多个 pulumi 命令拼接在一起,Automation API 提供:
本地源 - Pulumi 程序位于单独的文件中:
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
workDir: "./infrastructure", // 指向现有的 Pulumi 项目
});
适用场景:
内联源 - Pulumi 程序嵌入在编排器中:
import * as aws from "@pulumi/aws";
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
projectName: "my-project",
program: async () => {
const bucket = new aws.s3.Bucket("my-bucket");
return { bucketName: bucket.id };
},
});
适用场景:
Automation API 程序可以使用与其编排的 Pulumi 程序不同的语言:
编排器 (Go) → 管理 → Pulumi 程序 (TypeScript)
这使得平台团队可以使用他们偏好的语言,而应用团队使用他们自己的语言。
按依赖顺序部署多个堆栈:
import * as automation from "@pulumi/pulumi/automation";
async function deploy() {
const stacks = [
{ name: "infrastructure", dir: "./infra" },
{ name: "platform", dir: "./platform" },
{ name: "application", dir: "./app" },
];
for (const stackInfo of stacks) {
console.log(`正在部署 ${stackInfo.name}...`);
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
await stack.up({ onOutput: console.log });
console.log(`${stackInfo.name} 部署成功`);
}
}
async function destroy() {
// 按相反顺序销毁
const stacks = [
{ name: "application", dir: "./app" },
{ name: "platform", dir: "./platform" },
{ name: "infrastructure", dir: "./infra" },
];
for (const stackInfo of stacks) {
console.log(`正在销毁 ${stackInfo.name}...`);
const stack = await automation.LocalWorkspace.selectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
await stack.destroy({ onOutput: console.log });
}
}
以编程方式设置堆栈配置:
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
workDir: "./infrastructure",
});
// 设置配置值
await stack.setConfig("aws:region", { value: "us-west-2" });
await stack.setConfig("dbPassword", { value: "secret", secret: true });
// 然后部署
await stack.up();
部署后访问堆栈输出:
const upResult = await stack.up();
// 获取所有输出
const outputs = await stack.outputs();
console.log(`VPC ID:${outputs["vpcId"].value}`);
// 或从 up 结果中获取
console.log(`输出:${JSON.stringify(upResult.outputs)}`);
优雅地处理部署失败:
try {
const result = await stack.up({ onOutput: console.log });
if (result.summary.result === "failed") {
console.error("部署失败");
process.exit(1);
}
} catch (error) {
console.error(`部署错误:${error}`);
throw error;
}
当堆栈独立时,并行部署:
const independentStacks = [
{ name: "service-a", dir: "./service-a" },
{ name: "service-b", dir: "./service-b" },
{ name: "service-c", dir: "./service-c" },
];
await Promise.all(independentStacks.map(async (stackInfo) => {
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
return stack.up({ onOutput: (msg) => console.log(`[${stackInfo.name}] ${msg}`) });
}));
将配置外部化到文件或环境变量中:
import * as fs from "fs";
interface DeployConfig {
stacks: Array<{ name: string; dir: string; }>;
environment: string;
}
const config: DeployConfig = JSON.parse(
fs.readFileSync("./deploy-config.json", "utf-8")
);
for (const stackInfo of config.stacks) {
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: config.environment,
workDir: stackInfo.dir,
});
await stack.up();
}
这样可以在不暴露源代码的情况下分发编译后的二进制文件。
使用 onOutput 回调进行实时反馈:
await stack.up({
onOutput: (message) => {
process.stdout.write(message);
// 或发送到日志系统、websocket 等
},
});
| 场景 | 方法 |
|---|---|
| 现有 Pulumi 项目 | 使用 workDir 的本地源 |
| 新的嵌入式基础设施 | 使用 program 函数的内联源 |
| 不同团队 | 本地源以实现独立性 |
| 编译后的二进制文件分发 | 内联源或捆绑的本地源 |
| 多堆栈依赖 | 按顺序依次部署 |
| 独立堆栈 | 使用 Promise.all 并行部署 |
每周安装量
353
代码仓库
GitHub 星标数
30
首次出现
2026年1月28日
安全审计
安装于
opencode308
codex304
github-copilot303
gemini-cli294
amp288
kimi-cli286
Invoke this skill when:
Automation API provides programmatic access to Pulumi operations. Instead of running pulumi up from the CLI, you call functions in your code that perform the same operations.
import * as automation from "@pulumi/pulumi/automation";
// Create or select a stack
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
projectName: "my-project",
program: async () => {
// Your Pulumi program here
},
});
// Run pulumi up programmatically
const upResult = await stack.up({ onOutput: console.log });
console.log(`Update summary: ${JSON.stringify(upResult.summary)}`);
Multi-stack orchestration:
When you split infrastructure into multiple focused projects, Automation API helps offset the added complexity by orchestrating operations across stacks:
infrastructure → platform → application
↓ ↓ ↓
(VPC) (Kubernetes) (Services)
Automation API ensures correct sequencing without manual intervention.
Self-service platforms:
Build internal tools where developers request infrastructure without learning Pulumi:
Embedded infrastructure:
Applications that provision their own infrastructure:
Replacing fragile scripts:
If you have Bash scripts or Makefiles stitching together multiple pulumi commands, Automation API provides:
Local Source - Pulumi program in separate files:
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
workDir: "./infrastructure", // Points to existing Pulumi project
});
When to use:
Inline Source - Pulumi program embedded in orchestrator:
import * as aws from "@pulumi/aws";
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
projectName: "my-project",
program: async () => {
const bucket = new aws.s3.Bucket("my-bucket");
return { bucketName: bucket.id };
},
});
When to use:
The Automation API program can use a different language than the Pulumi programs it orchestrates:
Orchestrator (Go) → manages → Pulumi Program (TypeScript)
This enables platform teams to use their preferred language while application teams use theirs.
Deploy multiple stacks in dependency order:
import * as automation from "@pulumi/pulumi/automation";
async function deploy() {
const stacks = [
{ name: "infrastructure", dir: "./infra" },
{ name: "platform", dir: "./platform" },
{ name: "application", dir: "./app" },
];
for (const stackInfo of stacks) {
console.log(`Deploying ${stackInfo.name}...`);
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
await stack.up({ onOutput: console.log });
console.log(`${stackInfo.name} deployed successfully`);
}
}
async function destroy() {
// Destroy in reverse order
const stacks = [
{ name: "application", dir: "./app" },
{ name: "platform", dir: "./platform" },
{ name: "infrastructure", dir: "./infra" },
];
for (const stackInfo of stacks) {
console.log(`Destroying ${stackInfo.name}...`);
const stack = await automation.LocalWorkspace.selectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
await stack.destroy({ onOutput: console.log });
}
}
Set stack configuration programmatically:
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "dev",
workDir: "./infrastructure",
});
// Set configuration values
await stack.setConfig("aws:region", { value: "us-west-2" });
await stack.setConfig("dbPassword", { value: "secret", secret: true });
// Then deploy
await stack.up();
Access stack outputs after deployment:
const upResult = await stack.up();
// Get all outputs
const outputs = await stack.outputs();
console.log(`VPC ID: ${outputs["vpcId"].value}`);
// Or from the up result
console.log(`Outputs: ${JSON.stringify(upResult.outputs)}`);
Handle deployment failures gracefully:
try {
const result = await stack.up({ onOutput: console.log });
if (result.summary.result === "failed") {
console.error("Deployment failed");
process.exit(1);
}
} catch (error) {
console.error(`Deployment error: ${error}`);
throw error;
}
When stacks are independent, deploy in parallel:
const independentStacks = [
{ name: "service-a", dir: "./service-a" },
{ name: "service-b", dir: "./service-b" },
{ name: "service-c", dir: "./service-c" },
];
await Promise.all(independentStacks.map(async (stackInfo) => {
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: "prod",
workDir: stackInfo.dir,
});
return stack.up({ onOutput: (msg) => console.log(`[${stackInfo.name}] ${msg}`) });
}));
Externalize configuration into files or environment variables:
import * as fs from "fs";
interface DeployConfig {
stacks: Array<{ name: string; dir: string; }>;
environment: string;
}
const config: DeployConfig = JSON.parse(
fs.readFileSync("./deploy-config.json", "utf-8")
);
for (const stackInfo of config.stacks) {
const stack = await automation.LocalWorkspace.createOrSelectStack({
stackName: config.environment,
workDir: stackInfo.dir,
});
await stack.up();
}
This enables distributing compiled binaries without exposing source code.
Use onOutput callback for real-time feedback:
await stack.up({
onOutput: (message) => {
process.stdout.write(message);
// Or send to logging system, websocket, etc.
},
});
| Scenario | Approach |
|---|---|
| Existing Pulumi projects | Local source with workDir |
| New embedded infrastructure | Inline source with program function |
| Different teams | Local source for independence |
| Compiled binary distribution | Inline source or bundled local |
| Multi-stack dependencies | Sequential deployment in order |
| Independent stacks | Parallel deployment with Promise.all |
Weekly Installs
353
Repository
GitHub Stars
30
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode308
codex304
github-copilot303
gemini-cli294
amp288
kimi-cli286
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
100,500 周安装
Godot 游戏开发技能详解:场景树、节点类型、GDScript 与 MCP 工具
342 周安装
Polymarket API 与 WebSocket 实时数据客户端开发指南 | 预测市场集成
343 周安装
LangChain4J向量存储配置指南:Java RAG应用集成PostgreSQL/Pinecone等数据库
343 周安装
shadcn UI组件库:36个Radix UI + Tailwind CSS预构建组件,无缝集成json-render
343 周安装
react-grab:AI 开发助手,一键复制 React 组件上下文到剪贴板
343 周安装
风险评估插件:AI驱动风险矩阵与登记册生成工具,系统识别操作财务合规战略安全风险
344 周安装