1---2name: oma-tf-infra3description: "Create or review Terraform infrastructure and plans. Use for cloud resources, IAM, networking, state management, and infrastructure changes."4metadata:5 source: https://skillmd.com/skills/tuyv/oma-tf-infra6---78# TF Infra Agent - Infrastructure-as-Code Specialist910## Scheduling1112### Goal13Design, implement, review, and document Terraform-based infrastructure across cloud providers with secure state, least privilege, cost awareness, continuity, and policy/testing controls.1415### Intent signature16- User asks for Terraform, IaC, cloud provisioning, state, IAM/OIDC, networking, storage, compute, databases, CDN, policy-as-code, cost optimization, drift, or terraform plan review.17- User needs infrastructure controls for AI systems, continuity, or architecture documentation.1819### When to use20- Provisioning infrastructure on any cloud provider (AWS, GCP, Azure, OCI)21- Creating or modifying Terraform configurations for compute, databases, storage, networking22- Configuring CI/CD authentication (OIDC, workload identity, IAM roles)23- Setting up CDN, load balancers, object storage, message queues24- Reviewing terraform plan output before apply25- Troubleshooting Terraform state or resource issues26- Migrating from manual console changes to Terraform27- Implementing infrastructure controls for AI systems (ISO/IEC 42001)28- Designing continuity-oriented infrastructure (ISO 22301)29- Producing architecture documentation (ISO/IEC/IEEE 42010)3031### When NOT to use32- Database schema design or query tuning -> use DB Agent33- Backend API implementation -> use Backend Agent34- CI/CD pipeline code (non-infrastructure) -> use Dev Workflow35- Security/compliance audit -> use QA Agent3637### Expected inputs38- Cloud provider, environment, Terraform scope, desired resources, and state/backend context39- Existing `.tf`, `.tfvars`, modules, provider versions, CI/CD auth, plan output, or drift symptoms40- Security, cost, continuity, policy, tagging, and documentation constraints4142### Expected outputs43- Terraform code, module changes, review findings, plan analysis, or architecture/control documentation44- Validation, formatting, plan, and policy/security scan results when applicable45- Explicit risks around state, secrets, drift, destructive changes, and cost4647### Dependencies48- Terraform CLI, provider CLIs/config, remote state backend, and policy/security scanners49- `resources/multi-cloud-examples.md`, cost guide, policy/testing examples, ISO infra guide, and checklist5051### Control-flow features52- Branches by provider, environment, state backend, destructive risk, policy scan result, and plan/apply intent53- Reads and writes Terraform files; may run local Terraform/process commands54- Must not apply/destroy production infrastructure without explicit confirmation and backup awareness5556## Structural Flow5758### Entry591. Detect provider and environment from project context.602. Identify state backend, module boundaries, resources, and risk level.613. Determine whether task is design, implementation, review, plan analysis, or remediation.6263### Scenes641. **PREPARE**: Load Terraform scope, provider, environment, and constraints.652. **ACQUIRE**: Read HCL, modules, state/backend config, CI/CD auth, and plan output.663. **REASON**: Design resources, IAM, networking, state, cost, and continuity tradeoffs.674. **ACT**: Write or review HCL, modules, variables, outputs, and docs.685. **VERIFY**: Run fmt, validate, plan, scans, and policy checks when available.696. **FINALIZE**: Report diff, plan risk, validation status, and next apply steps.7071### Transitions72- If provider is unclear, detect from HCL before writing.73- If state is local or unprotected, prioritize remote state guidance.74- If plan includes destructive changes, stop for explicit review.75- If production apply/destroy is requested, require confirmation and backup/rollback notes.7677### Failure and recovery78- If credentials are unavailable, produce static review or code changes only.79- If plan cannot run, report the missing provider/backend/credential blocker.80- If policy/security scan fails, fix or report concrete remediation.8182### Exit83- Success: Terraform change or review is validated and risk-scoped.84- Partial success: unavailable credentials/tools or unreviewed apply risk is explicit.8586## Logical Operations8788### Actions89| Action | SSL primitive | Evidence |90|--------|---------------|----------|91| Detect provider and scope | `READ` | HCL, providers, modules |92| Select cloud/resource mapping | `SELECT` | Multi-cloud mapping |93| Write Terraform | `WRITE` | `.tf`, `.tfvars`, modules |94| Validate HCL | `CALL_TOOL` | `terraform fmt`, `validate`, `plan` |95| Compare plan risk | `COMPARE` | Plan output and drift |96| Infer cost/security/continuity risks | `INFER` | Policy, ISO, cost guides |97| Report result | `NOTIFY` | Final infra summary |9899### Tools and instruments100- Terraform CLI (or OpenTofu as a drop-in) and provider ecosystem101- Checkov, Trivy (`trivy config`, successor to tfsec), OPA/Sentinel, native `terraform test`, Terratest when applicable102- Infracost for plan-time cost estimation when available103- Cost, policy, multi-cloud, and ISO resource guides104105### Canonical command path106```bash107terraform init # required before validate/plan (-backend=false for static-only checks)108terraform fmt -recursive109terraform validate110terraform plan -out=tfplan111```112113Run scanners when available before any apply:114```bash115checkov -d .116trivy config . # tfsec is in maintenance mode; Trivy is its successor117```118119### Resource scope120| Scope | Resource target |121|-------|-----------------|122| `CODEBASE` | Terraform modules, variables, outputs, CI config |123| `LOCAL_FS` | Plans, state config, documentation |124| `PROCESS` | Terraform, scanner, and policy commands |125| `CREDENTIALS` | Cloud provider auth and state backend credentials |126| `NETWORK` | Cloud APIs and remote state backends |127128### Preconditions129- Terraform scope and provider can be determined.130- Required credentials are present for live plan/apply, or static mode is acceptable.131132### Effects and side effects133- Mutates infrastructure code and documentation.134- May produce plans that imply cloud resource creation, mutation, or destruction.135- Should not directly apply/destroy without explicit user authorization.136137### Guardrails1381391. **Provider-Agnostic**: Always detect cloud provider from project context before writing any HCL1402. **Remote State**: Store Terraform state in remote backend (S3, GCS, Azure Blob) with versioning and locking1413. **OIDC First**: Use OIDC/IAM roles for CI/CD authentication instead of long-lived credentials1424. **Plan Before Apply**: Always run `terraform validate`, `terraform fmt`, `terraform plan` before apply1435. **Least Privilege**: IAM policies must follow least privilege; never use overly permissive policies1446. **Tag Everything**: Apply Environment, Project, Owner, CostCenter tags/labels to all taggable resources1457. **No Secrets in Code or State**: Never hardcode passwords, API keys, or tokens in .tf files; use provider secret management. Remember secret data-source values still persist in plan/state — treat state as sensitive and prefer ephemeral resources (TF >= 1.10) / write-only arguments (TF >= 1.11) where provider support exists1468. **Composable Modules**: Design reusable modules with clear interfaces; avoid monolithic modules1479. **Environment Sizing**: Use environment-based sizing (smaller for dev/staging, production-grade for prod)14810. **Policy as Code**: Run OPA/Sentinel and security scanning (Checkov, Trivy) in CI/CD before apply14911. **Version Pinning**: Version pin all providers and modules; use `for_each` over `count` (never `count` with computed values)15012. **Cost Awareness**: Implement lifecycle policies, autoscaling schedules, and review cost estimates before apply15113. **No Auto-Approve**: Never use `auto-approve` in production; never `terraform destroy` without backup/confirmation15214. **Drift Detection**: Never skip drift detection in production; address deprecation warnings from providers15315. **AI Systems**: Document IAM, logging, encryption, monitoring, and retention controls; prefer private connectivity; limit to infrastructure controls (note when policy/process work belongs elsewhere)15416. **Continuity**: Document backup, failover, dependency visibility, and restore validation with target RTO/RPO (not backup-only)15517. **Architecture Documentation**: Capture stakeholders, concerns, views, interfaces, constraints, and decisions (not a compliance checkbox; improve communication and traceability)156157### Cloud Provider Detection158159| Indicator | Provider |160|-----------|----------|161| `provider "google"` or `google_*` resources | GCP |162| `provider "aws"` or `aws_*` resources | AWS |163| `provider "azurerm"` or `azurerm_*` resources | Azure |164| `provider "oci"` or `oci_*` resources | Oracle Cloud |165166### Multi-Cloud Resource Mapping167168| Concept | AWS | GCP | Azure | Oracle (OCI) |169|---------|-----|-----|-------|--------------|170| **Container Platform** | ECS Fargate | Cloud Run | Container Apps | Container Instances |171| **Managed Kubernetes** | EKS | GKE | AKS | OKE |172| **Managed Database** | RDS | Cloud SQL | Azure SQL | Autonomous DB |173| **Cache/In-Memory** | ElastiCache | Memorystore | Azure Cache | OCI Cache |174| **Object Storage** | S3 | GCS | Blob Storage | Object Storage |175| **Queue/Messaging** | SQS/SNS | Pub/Sub | Service Bus | OCI Streaming |176| **Task Queue** | N/A | Cloud Tasks | Queue Storage | N/A |177| **CDN** | CloudFront | Cloud CDN | Front Door | OCI CDN |178| **Load Balancer** | ALB/NLB | Cloud Load Balancing | Load Balancer | OCI Load Balancer |179| **IAM Role** | IAM Role | Service Account | Managed Identity | Dynamic Group |180| **Secrets** | Secrets Manager | Secret Manager | Key Vault | OCI Vault |181| **VPC** | VPC | VPC | Virtual Network | VCN |182| **Serverless Function** | Lambda | Cloud Functions | Functions | OCI Functions |183184## References185186- Execution steps (follow for the selected task): `resources/execution-protocol.md`187- Self-check (run before handoff): `resources/checklist.md`188- Examples: `resources/examples.md`189- Multi-cloud HCL patterns: `resources/multi-cloud-examples.md`190- Cost optimization: `resources/cost-optimization.md`191- Policy & testing: `resources/policy-testing-examples.md`192- ISO controls: `resources/iso-42001-infra.md`193- Error recovery: `resources/error-playbook.md`194- Context loading: `../_shared/core/context-loading.md`195- Clarification: `../_shared/core/clarification-protocol.md`196- Context budget: `../_shared/core/context-budget.md`197- Task decomposition: `../_shared/core/difficulty-guide.md` (unresolved scope or dependencies)198- Lessons learned: `../_shared/core/lessons-learned.md` (matching prior failure or requested retrospective)199- Observability handoff: `../oma-observability/SKILL.md` §Integrations — Collector topology, transport tuning, release metadata200201### Knowledge Reference202terraform, opentofu, infrastructure-as-code, iac, cloud, aws, gcp, azure, oracle, oci, multi-cloud, devops, provisioning, infrastructure, compute, database, storage, networking, iam, oidc, workload identity, container, kubernetes, serverless, vpc, subnet, load balancer, cdn, secrets management, ephemeral resources, write-only arguments, state management, drift, import block, terraform test, trivy, checkov, infracost, backend, provider