Purpose & When-To-Use
Trigger conditions:
- Infrastructure provisioning needed for new project
- Existing infrastructure requires IaC conversion (eliminate drift)
- Multi-environment deployment needs consistent infrastructure
- Cloud migration requires infrastructure templates
- Infrastructure security hardening requires declarative config
Use this skill when you need production-ready Infrastructure as Code templates with modules, variables, and remote state management.
Pre-Checks
Before execution, verify:
- Time normalization:
NOW_ET = 2025-10-26T01:33:56-04:00 (NIST/time.gov semantics, America/New_York)
- Input schema validation:
iac_tool is one of: terraform, cloudformation, pulumi, cdk
cloud_provider is one of: aws, azure, gcp, multi-cloud
resources contains valid resource types
environments list is non-empty if multi-environment support needed
- Source freshness: All cited sources accessed on
NOW_ET; verify documentation links current
- Tool compatibility: Verify IaC tool supports target cloud provider
Abort conditions:
- IaC tool doesn't support target cloud provider (e.g., CloudFormation for Azure)
- Resource types incompatible with cloud provider
- Circular dependencies in resource graph
Procedure
Tier 1 (Fast Path, ≤2k tokens)
Token budget: ≤2k tokens
Scope: Generate basic IaC templates for common resources in single environment.
Steps:
Analyze inputs and select modules (400 tokens):
- Determine IaC tool syntax and structure
- Map resources to cloud provider services
- Identify resource dependencies and ordering
- Select appropriate module structure
Generate IaC templates (1600 tokens):
- Create main configuration file
- Generate resource modules (VPC, compute, storage)
- Define input variables with types and defaults
- Configure output values for cross-module references
- Add remote state backend configuration (S3+DynamoDB for Terraform, etc.)
- Include inline documentation and comments
- Generate README with usage instructions
Decision point: If requirements include multiple environments, custom networking, or advanced security → escalate to T2.
Tier 2 (Extended Analysis, ≤6k tokens)
Token budget: ≤6k tokens
Scope: Multi-environment IaC with workspaces, advanced networking, security hardening, and compliance.
Steps:
Design multi-environment architecture (2000 tokens):
- Terraform (accessed 2025-10-26T01:33:56-04:00):
- Configure workspaces for environment isolation
- Remote state with S3 backend and DynamoDB locking
- Workspace-specific variable files (terraform.tfvars.dev, terraform.tfvars.prod)
- Module versioning and source references
- CloudFormation (accessed 2025-10-26T01:33:56-04:00):
- Stack sets for multi-account deployment
- Cross-stack references for shared resources
- Parameters and mappings for environment-specific values
- Pulumi (accessed 2025-10-26T01:33:56-04:00):
- Stack configuration files per environment
- Programmatic resource creation with language features
- State backend configuration (Pulumi Cloud or self-hosted)
- CDK (accessed 2025-10-26T01:33:56-04:00):
- Environment-specific context values
- Synthesized CloudFormation templates
- Asset management and bundling
Generate comprehensive templates (4000 tokens):
- Networking:
- VPC with public/private subnets across multiple AZs
- NAT gateways, internet gateways, route tables
- Network ACLs and security groups
- VPC peering and transit gateway (if multi-VPC)
- Compute:
- EC2 instances with auto-scaling groups
- Launch templates with user data scripts
- Load balancers (ALB/NLB)
- ECS/EKS clusters for containerized workloads
- Lambda functions for serverless
- Storage:
- S3 buckets with versioning, encryption, lifecycle policies
- EBS volumes with encryption
- EFS for shared file systems
- Database:
- RDS instances with multi-AZ, backups, encryption
- DynamoDB tables with autoscaling
- ElastiCache clusters
- Security:
- IAM roles and policies with least privilege
- KMS keys for encryption at rest
- Secrets Manager for credential storage
- Security group rules with minimal exposure
- VPC flow logs and CloudTrail
- Monitoring:
- CloudWatch alarms and dashboards
- SNS topics for alerts
- Log groups with retention policies
Sources cited (accessed 2025-10-26T01:33:56-04:00):
Tier 3 (Deep Dive, ≤12k tokens)
Token budget: ≤12k tokens
Scope: Enterprise IaC with policy-as-code, compliance automation, and multi-cloud orchestration.
Steps:
Policy-as-code integration (4000 tokens):
- Terraform: Sentinel or OPA policy enforcement
- CloudFormation: Guard rules for compliance validation
- Pulumi: Policy packs for resource validation
- Generate policies for:
- Resource tagging requirements
- Security best practices (encryption, public access)
- Cost controls (instance types, storage classes)
- Compliance requirements (HIPAA, PCI-DSS, FedRAMP)
Advanced orchestration (4000 tokens):
- Multi-cloud resource provisioning with cloud-agnostic abstractions
- Cross-region disaster recovery configurations
- Blue-green infrastructure for zero-downtime migrations
- Infrastructure testing with Terratest, Kitchen-Terraform, or CDK assertions
- Drift detection and automated remediation
- Cost estimation and budget alerts
Enterprise features (4000 tokens):
- Service catalog integration for self-service provisioning
- GitOps workflows with automated plan/apply on PR merge
- Secrets injection from external vaults (HashiCorp Vault, AWS Secrets Manager)
- Compliance artifact generation (resource inventories, security configs)
- Module registry and version management
- Documentation generation from IaC source
Additional sources (accessed 2025-10-26T01:33:56-04:00):
Decision Rules
IaC tool selection:
- Terraform: Multi-cloud, large community, declarative HCL syntax
- CloudFormation: AWS-native, tight integration, no external state
- Pulumi: Familiar languages (Python, TypeScript), programmatic flexibility
- CDK: AWS-native with programming languages, synthesizes to CloudFormation
Resource organization:
- Group related resources into logical modules (networking, compute, data)
- Use separate state files for independent infrastructure components
- Version modules for stability and testing
Environment strategy:
- Workspaces: Good for small differences between environments
- Separate state files: Better for production isolation
- Account separation: Best for regulatory compliance (dev/prod in different AWS accounts)
Escalation conditions:
- Multi-cloud orchestration with complex dependencies
- Custom compliance requirements requiring policy development
- Requirements exceed T3 scope (novel cloud services, experimental features)
Abort conditions:
- Resource dependencies create circular references
- Cloud provider quotas prevent required resource provisioning
- Conflicting security requirements (e.g., "publicly accessible" with "private only")
Output Contract
Required outputs:
{
"iac_templates": {
"type": "object",
"properties": {
"tool": "string (terraform|cloudformation|pulumi|cdk)",
"modules": [
{
"name": "string (networking, compute, storage, etc.)",
"file_path": "string (relative path to module)",
"content": "string (IaC code)",
"variables": ["array of input variable definitions"],
"outputs": ["array of output value definitions"]
}
]
}
},
"state_config": {
"type": "object",
"properties": {
"backend": "string (s3, azurerm, gcs, pulumi-cloud)",
"config": "object (backend-specific configuration)",
"content": "string (backend configuration code)"
}
}
}
Quality guarantees:
- IaC templates pass validation (terraform validate, cfn-lint, pulumi preview)
- All variables have types and descriptions
- Remote state backend configured for collaboration
- Security best practices applied (encryption, least privilege)
- Resource dependencies correctly defined
Examples
Example: Terraform AWS VPC module
# modules/networking/main.tf
variable "environment" {
type = string
description = "Environment name (dev, staging, prod)"
}
variable "vpc_cidr" {
type = string
description = "CIDR block for VPC"
}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "${var.environment}-vpc"
Environment = var.environment
}
}
output "vpc_id" {
value = aws_vpc.main.id
}
Quality Gates
Token budgets:
- T1: ≤2k tokens (basic single-environment IaC)
- T2: ≤6k tokens (multi-environment with security hardening)
- T3: ≤12k tokens (enterprise policy-as-code and orchestration)
Safety checks:
- No hardcoded secrets or credentials in templates
- All resources encrypted at rest (where applicable)
- IAM policies follow least privilege principle
- Public access explicitly controlled and justified
Auditability:
- All resource changes tracked in version control
- State file changes logged and backed up
- Resource tagging for cost allocation and ownership
Determinism:
- Same inputs produce identical IaC templates
- Module versions pinned for stability
- Provider versions locked in configuration
Resources
Official Documentation (accessed 2025-10-26T01:33:56-04:00):
Best Practices (accessed 2025-10-26T01:33:56-04:00):
Templates (in repository /resources/):
- Terraform modules for AWS, Azure, GCP
- CloudFormation templates for common architectures
- Pulumi examples in Python and TypeScript
1---2name: infrastructure-as-code-template-generator3description: Generate IaC templates for Terraform, CloudFormation, and Pulumi with modules for compute, storage, networking, and multi-environment support.4license: MIT5---67## Purpose & When-To-Use89**Trigger conditions:**1011- Infrastructure provisioning needed for new project12- Existing infrastructure requires IaC conversion (eliminate drift)13- Multi-environment deployment needs consistent infrastructure14- Cloud migration requires infrastructure templates15- Infrastructure security hardening requires declarative config1617**Use this skill when** you need production-ready Infrastructure as Code templates with modules, variables, and remote state management.1819---2021## Pre-Checks2223**Before execution, verify:**24251. **Time normalization**: `NOW_ET = 2025-10-26T01:33:56-04:00` (NIST/time.gov semantics, America/New_York)262. **Input schema validation**:27 - `iac_tool` is one of: `terraform`, `cloudformation`, `pulumi`, `cdk`28 - `cloud_provider` is one of: `aws`, `azure`, `gcp`, `multi-cloud`29 - `resources` contains valid resource types30 - `environments` list is non-empty if multi-environment support needed313. **Source freshness**: All cited sources accessed on `NOW_ET`; verify documentation links current324. **Tool compatibility**: Verify IaC tool supports target cloud provider3334**Abort conditions:**3536- IaC tool doesn't support target cloud provider (e.g., CloudFormation for Azure)37- Resource types incompatible with cloud provider38- Circular dependencies in resource graph3940---4142## Procedure4344### Tier 1 (Fast Path, ≤2k tokens)4546**Token budget**: ≤2k tokens4748**Scope**: Generate basic IaC templates for common resources in single environment.4950**Steps:**51521. **Analyze inputs and select modules** (400 tokens):53 - Determine IaC tool syntax and structure54 - Map resources to cloud provider services55 - Identify resource dependencies and ordering56 - Select appropriate module structure57582. **Generate IaC templates** (1600 tokens):59 - Create main configuration file60 - Generate resource modules (VPC, compute, storage)61 - Define input variables with types and defaults62 - Configure output values for cross-module references63 - Add remote state backend configuration (S3+DynamoDB for Terraform, etc.)64 - Include inline documentation and comments65 - Generate README with usage instructions6667**Decision point**: If requirements include multiple environments, custom networking, or advanced security → escalate to T2.6869---7071### Tier 2 (Extended Analysis, ≤6k tokens)7273**Token budget**: ≤6k tokens7475**Scope**: Multi-environment IaC with workspaces, advanced networking, security hardening, and compliance.7677**Steps:**78791. **Design multi-environment architecture** (2000 tokens):80 - **Terraform** (accessed 2025-10-26T01:33:56-04:00):81 - Configure workspaces for environment isolation82 - Remote state with S3 backend and DynamoDB locking83 - Workspace-specific variable files (terraform.tfvars.dev, terraform.tfvars.prod)84 - Module versioning and source references85 - **CloudFormation** (accessed 2025-10-26T01:33:56-04:00):86 - Stack sets for multi-account deployment87 - Cross-stack references for shared resources88 - Parameters and mappings for environment-specific values89 - **Pulumi** (accessed 2025-10-26T01:33:56-04:00):90 - Stack configuration files per environment91 - Programmatic resource creation with language features92 - State backend configuration (Pulumi Cloud or self-hosted)93 - **CDK** (accessed 2025-10-26T01:33:56-04:00):94 - Environment-specific context values95 - Synthesized CloudFormation templates96 - Asset management and bundling97982. **Generate comprehensive templates** (4000 tokens):99 - **Networking**:100 - VPC with public/private subnets across multiple AZs101 - NAT gateways, internet gateways, route tables102 - Network ACLs and security groups103 - VPC peering and transit gateway (if multi-VPC)104 - **Compute**:105 - EC2 instances with auto-scaling groups106 - Launch templates with user data scripts107 - Load balancers (ALB/NLB)108 - ECS/EKS clusters for containerized workloads109 - Lambda functions for serverless110 - **Storage**:111 - S3 buckets with versioning, encryption, lifecycle policies112 - EBS volumes with encryption113 - EFS for shared file systems114 - **Database**:115 - RDS instances with multi-AZ, backups, encryption116 - DynamoDB tables with autoscaling117 - ElastiCache clusters118 - **Security**:119 - IAM roles and policies with least privilege120 - KMS keys for encryption at rest121 - Secrets Manager for credential storage122 - Security group rules with minimal exposure123 - VPC flow logs and CloudTrail124 - **Monitoring**:125 - CloudWatch alarms and dashboards126 - SNS topics for alerts127 - Log groups with retention policies128129**Sources cited** (accessed 2025-10-26T01:33:56-04:00):130131- **Terraform Best Practices**: https://developer.hashicorp.com/terraform/cloud-docs/recommended-practices132- **AWS CloudFormation**: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/133- **Pulumi Architecture**: https://www.pulumi.com/docs/concepts/134- **AWS CDK Best Practices**: https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html135136---137138### Tier 3 (Deep Dive, ≤12k tokens)139140**Token budget**: ≤12k tokens141142**Scope**: Enterprise IaC with policy-as-code, compliance automation, and multi-cloud orchestration.143144**Steps:**1451461. **Policy-as-code integration** (4000 tokens):147 - **Terraform**: Sentinel or OPA policy enforcement148 - **CloudFormation**: Guard rules for compliance validation149 - **Pulumi**: Policy packs for resource validation150 - Generate policies for:151 - Resource tagging requirements152 - Security best practices (encryption, public access)153 - Cost controls (instance types, storage classes)154 - Compliance requirements (HIPAA, PCI-DSS, FedRAMP)1551562. **Advanced orchestration** (4000 tokens):157 - Multi-cloud resource provisioning with cloud-agnostic abstractions158 - Cross-region disaster recovery configurations159 - Blue-green infrastructure for zero-downtime migrations160 - Infrastructure testing with Terratest, Kitchen-Terraform, or CDK assertions161 - Drift detection and automated remediation162 - Cost estimation and budget alerts1631643. **Enterprise features** (4000 tokens):165 - Service catalog integration for self-service provisioning166 - GitOps workflows with automated plan/apply on PR merge167 - Secrets injection from external vaults (HashiCorp Vault, AWS Secrets Manager)168 - Compliance artifact generation (resource inventories, security configs)169 - Module registry and version management170 - Documentation generation from IaC source171172**Additional sources** (accessed 2025-10-26T01:33:56-04:00):173174- **Terraform Sentinel**: https://developer.hashicorp.com/sentinel175- **AWS CloudFormation Guard**: https://docs.aws.amazon.com/cfn-guard/latest/ug/176- **Pulumi CrossGuard**: https://www.pulumi.com/docs/using-pulumi/crossguard/177178---179180## Decision Rules181182**IaC tool selection:**183184- **Terraform**: Multi-cloud, large community, declarative HCL syntax185- **CloudFormation**: AWS-native, tight integration, no external state186- **Pulumi**: Familiar languages (Python, TypeScript), programmatic flexibility187- **CDK**: AWS-native with programming languages, synthesizes to CloudFormation188189**Resource organization:**190191- Group related resources into logical modules (networking, compute, data)192- Use separate state files for independent infrastructure components193- Version modules for stability and testing194195**Environment strategy:**196197- **Workspaces**: Good for small differences between environments198- **Separate state files**: Better for production isolation199- **Account separation**: Best for regulatory compliance (dev/prod in different AWS accounts)200201**Escalation conditions:**202203- Multi-cloud orchestration with complex dependencies204- Custom compliance requirements requiring policy development205- Requirements exceed T3 scope (novel cloud services, experimental features)206207**Abort conditions:**208209- Resource dependencies create circular references210- Cloud provider quotas prevent required resource provisioning211- Conflicting security requirements (e.g., "publicly accessible" with "private only")212213---214215## Output Contract216217**Required outputs:**218219```json220{221 "iac_templates": {222 "type": "object",223 "properties": {224 "tool": "string (terraform|cloudformation|pulumi|cdk)",225 "modules": [226 {227 "name": "string (networking, compute, storage, etc.)",228 "file_path": "string (relative path to module)",229 "content": "string (IaC code)",230 "variables": ["array of input variable definitions"],231 "outputs": ["array of output value definitions"]232 }233 ]234 }235 },236 "state_config": {237 "type": "object",238 "properties": {239 "backend": "string (s3, azurerm, gcs, pulumi-cloud)",240 "config": "object (backend-specific configuration)",241 "content": "string (backend configuration code)"242 }243 }244}245```246247**Quality guarantees:**248249- IaC templates pass validation (terraform validate, cfn-lint, pulumi preview)250- All variables have types and descriptions251- Remote state backend configured for collaboration252- Security best practices applied (encryption, least privilege)253- Resource dependencies correctly defined254255---256257## Examples258259**Example: Terraform AWS VPC module**260261```hcl262# modules/networking/main.tf263variable "environment" {264 type = string265 description = "Environment name (dev, staging, prod)"266}267268variable "vpc_cidr" {269 type = string270 description = "CIDR block for VPC"271}272273resource "aws_vpc" "main" {274 cidr_block = var.vpc_cidr275 enable_dns_hostnames = true276 enable_dns_support = true277278 tags = {279 Name = "${var.environment}-vpc"280 Environment = var.environment281 }282}283284output "vpc_id" {285 value = aws_vpc.main.id286}287```288289---290291## Quality Gates292293**Token budgets:**294295- **T1**: ≤2k tokens (basic single-environment IaC)296- **T2**: ≤6k tokens (multi-environment with security hardening)297- **T3**: ≤12k tokens (enterprise policy-as-code and orchestration)298299**Safety checks:**300301- No hardcoded secrets or credentials in templates302- All resources encrypted at rest (where applicable)303- IAM policies follow least privilege principle304- Public access explicitly controlled and justified305306**Auditability:**307308- All resource changes tracked in version control309- State file changes logged and backed up310- Resource tagging for cost allocation and ownership311312**Determinism:**313314- Same inputs produce identical IaC templates315- Module versions pinned for stability316- Provider versions locked in configuration317318---319320## Resources321322**Official Documentation** (accessed 2025-10-26T01:33:56-04:00):323324- Terraform: https://developer.hashicorp.com/terraform/docs325- CloudFormation: https://docs.aws.amazon.com/cloudformation/326- Pulumi: https://www.pulumi.com/docs/327- AWS CDK: https://docs.aws.amazon.com/cdk/328329**Best Practices** (accessed 2025-10-26T01:33:56-04:00):330331- Terraform Registry: https://registry.terraform.io/332- AWS Well-Architected Framework: https://aws.amazon.com/architecture/well-architected/333- Google Cloud Architecture Framework: https://cloud.google.com/architecture/framework334335**Templates** (in repository `/resources/`):336337- Terraform modules for AWS, Azure, GCP338- CloudFormation templates for common architectures339- Pulumi examples in Python and TypeScript