pulumi
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePulumi Best Practices
Pulumi最佳实践
Comprehensive performance and reliability guide for Pulumi infrastructure as code, designed for AI agents and LLMs. Contains 46 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
专为AI Agent和大语言模型设计的Pulumi基础设施即代码性能与可靠性综合指南。包含8个类别下的46条规则,按影响优先级排序,可指导自动化重构与代码生成。
When to Apply
适用场景
Reference these guidelines when:
- Writing new Pulumi infrastructure code
- Designing component abstractions for reuse
- Configuring secrets and sensitive values
- Organizing stacks and cross-stack references
- Setting up CI/CD pipelines for infrastructure
在以下场景中参考本指南:
- 编写新的Pulumi基础设施代码
- 设计可复用的组件抽象
- 配置机密信息与敏感值
- 组织栈与跨栈引用
- 搭建基础设施的CI/CD流水线
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | State Management and Backend | CRITICAL | |
| 2 | Resource Graph Optimization | CRITICAL | |
| 3 | Component Design | HIGH | |
| 4 | Secrets and Configuration | HIGH | |
| 5 | Stack Organization | MEDIUM-HIGH | |
| 6 | Resource Options and Lifecycle | MEDIUM | |
| 7 | Testing and Validation | MEDIUM | |
| 8 | Automation and CI/CD | LOW-MEDIUM | |
| 优先级 | 类别 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 状态管理与后端 | 关键 | |
| 2 | 资源图优化 | 关键 | |
| 3 | 组件设计 | 高 | |
| 4 | 机密与配置 | 高 | |
| 5 | 栈组织 | 中高 | |
| 6 | 资源选项与生命周期 | 中 | |
| 7 | 测试与验证 | 中 | |
| 8 | 自动化与CI/CD | 中低 | |
Quick Reference
快速参考
1. State Management and Backend (CRITICAL)
1. 状态管理与后端(关键)
- - Use managed backend for production stacks
pstate-backend-selection - - Enable checkpoint skipping for large stacks
pstate-checkpoint-skipping - - Keep stacks under 500 resources
pstate-stack-size - - Use targeted refresh instead of full stack
pstate-refresh-targeting - - Use state export/import for migrations
pstate-export-import - - Import existing resources before managing
pstate-import-existing
- - 生产环境栈使用托管后端
pstate-backend-selection - - 大型栈启用检查点跳过
pstate-checkpoint-skipping - - 栈资源数量保持在500个以下
pstate-stack-size - - 使用定向刷新而非全栈刷新
pstate-refresh-targeting - - 迁移时使用状态导出/导入
pstate-export-import - - 管理前先导入现有资源
pstate-import-existing
2. Resource Graph Optimization (CRITICAL)
2. 资源图优化(关键)
- - Structure resources for maximum parallelism
graph-parallel-resources - - Use outputs to express true dependencies
graph-output-dependencies - - Use dependsOn only for external dependencies
graph-explicit-depends - - Avoid side effects in apply functions
graph-avoid-apply-side-effects - - Use conditional logic at resource level
graph-conditional-resources - - Minimize stack reference depth
graph-stack-references-minimal
- - 构建资源结构以实现最大并行度
graph-parallel-resources - - 使用输出表达真实依赖关系
graph-output-dependencies - - 仅对外部依赖使用dependsOn
graph-explicit-depends - - 避免在apply函数中产生副作用
graph-avoid-apply-side-effects - - 在资源层面使用条件逻辑
graph-conditional-resources - - 最小化栈引用深度
graph-stack-references-minimal
3. Component Design (HIGH)
3. 组件设计(高)
- - Use ComponentResource for reusable abstractions
pcomp-component-resources - - Pass parent option to child resources
pcomp-parent-child - - Use name prefix pattern for unique resource names
pcomp-unique-naming - - Register component outputs explicitly
pcomp-register-outputs - - Design components for multi-language consumption
pcomp-multi-language - - Use transformations for cross-cutting concerns
pcomp-transformations
- - 使用ComponentResource实现可复用抽象
pcomp-component-resources - - 向子资源传递parent选项
pcomp-parent-child - - 使用名称前缀模式确保资源名称唯一
pcomp-unique-naming - - 显式注册组件输出
pcomp-register-outputs - - 设计支持多语言调用的组件
pcomp-multi-language - - 使用转换处理横切关注点
pcomp-transformations
4. Secrets and Configuration (HIGH)
4. 机密与配置(高)
- - Use secret config for sensitive values
secrets-use-secret-config - - Prevent secret leakage in state
secrets-avoid-state-exposure - - Use external secret managers for production
secrets-external-providers - - Generate secrets with random provider
secrets-generate-random - - Rotate secrets provider when team members leave
secrets-provider-rotation - - Isolate secrets by environment
secrets-environment-isolation
- - 对敏感值使用机密配置
secrets-use-secret-config - - 防止机密信息泄露到状态中
secrets-avoid-state-exposure - - 生产环境使用外部机密管理器
secrets-external-providers - - 使用随机提供程序生成机密
secrets-generate-random - - 团队成员变动时轮换机密提供程序
secrets-provider-rotation - - 按环境隔离机密信息
secrets-environment-isolation
5. Stack Organization (MEDIUM-HIGH)
5. 栈组织(中高)
- - Separate stacks by deployment lifecycle
stack-separation-by-lifecycle - - Parameterize stack references
stack-references-parameterized - - Export only required outputs
stack-output-minimal - - Use consistent stack naming convention
stack-naming-conventions
- - 按部署生命周期拆分栈
stack-separation-by-lifecycle - - 对栈引用进行参数化
stack-references-parameterized - - 仅导出必要的输出
stack-output-minimal - - 使用统一的栈命名规范
stack-naming-conventions
6. Resource Options and Lifecycle (MEDIUM)
6. 资源选项与生命周期(中)
- - Protect stateful resources
lifecycle-protect-stateful - - Use deleteBeforeReplace for unique constraints
lifecycle-delete-before-replace - - Use retainOnDelete for shared resources
lifecycle-retain-on-delete - - Use ignoreChanges for externally managed properties
lifecycle-ignore-changes - - Use replaceOnChanges for immutable dependencies
lifecycle-replace-on-changes - - Use aliases for safe resource renaming
lifecycle-aliases - - Set custom timeouts for long-running resources
lifecycle-custom-timeouts
- - 保护有状态资源
lifecycle-protect-stateful - - 对唯一约束使用deleteBeforeReplace
lifecycle-delete-before-replace - - 对共享资源使用retainOnDelete
lifecycle-retain-on-delete - - 对外部管理的属性使用ignoreChanges
lifecycle-ignore-changes - - 对不可变依赖使用replaceOnChanges
lifecycle-replace-on-changes - - 使用别名实现安全的资源重命名
lifecycle-aliases - - 为长运行资源设置自定义超时
lifecycle-custom-timeouts
7. Testing and Validation (MEDIUM)
7. 测试与验证(中)
- - Use mocks for fast unit tests
test-unit-mocking - - Use policy as code for property testing
test-property-policies - - Use ephemeral stacks for integration tests
test-integration-ephemeral - - Assert on preview results before deployment
test-preview-assertions - - Mock stack references in unit tests
test-stack-reference-mocking
- - 使用模拟实现快速单元测试
test-unit-mocking - - 使用策略即代码进行属性测试
test-property-policies - - 使用临时栈进行集成测试
test-integration-ephemeral - - 部署前对预览结果进行断言
test-preview-assertions - - 单元测试中模拟栈引用
test-stack-reference-mocking
8. Automation and CI/CD (LOW-MEDIUM)
8. 自动化与CI/CD(中低)
- - Use Automation API for complex workflows
auto-automation-api-workflows - - Use inline programs for dynamic infrastructure
auto-inline-programs - - Run preview in PR checks
auto-ci-cd-preview - - Use Pulumi Deployments for GitOps
auto-deployments-api - - Use review stacks for PR environments
auto-review-stacks - - Enable drift detection for production
auto-drift-detection
- - 使用Automation API实现复杂工作流
auto-automation-api-workflows - - 使用内联程序实现动态基础设施
auto-inline-programs - - 在PR检查中运行预览
auto-ci-cd-preview - - 使用Pulumi Deployments实现GitOps
auto-deployments-api - - 使用评审栈作为PR环境
auto-review-stacks - - 生产环境启用漂移检测
auto-drift-detection
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
阅读单个参考文件获取详细说明与代码示例:
- 章节定义 - 类别结构与影响级别
- 规则模板 - 添加新规则的模板
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md包含所有扩展规则的完整指南:
AGENTS.md