AI for Terraform
Design state, modules, providers, and workflows. Plan reviews, drift detection, large-state refactors, and policy-as-code with AI.
146 copy-paste prompts · 148 in-depth guides Jump to prompts Jump to guides
Prompts
- Advanced
Terraform Blue Green Deployment Pattern Prompt
Implement blue/green infrastructure deployments in Terraform with parallel resource sets, create_before_destroy, and weighted DNS or target-group cutover with rollback.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Checkov Custom Policy Authoring Prompt
Write custom Checkov policies for Terraform — Python checks extending BaseResourceCheck and YAML-based policies, a .checkov.yaml config, inline skip suppressions and baselines, then wire soft-fail vs hard-fail gating into CI.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Cloudflare DNS Module Design Prompt
Design a Cloudflare provider module that manages a zone and many DNS records via a for_each map while guarding apex and NS records from accidental deletion.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Datadog Monitors as Code Prompt
Design a reusable Terraform module that manages Datadog monitors, dashboards, and SLOs from a single typed map without triggering alert storms.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Ephemeral Preview Environments Prompt
Design per-PR ephemeral preview environments with Terraform — unique naming/tagging, TTL auto-destroy in CI, DNS/subdomain per env, cost caps, and safe teardown on PR close without nuking the wrong workspace.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform GitHub Org Management Module Prompt
Manage a GitHub organization as code with repos, teams, memberships, and branch protection via for_each, importing existing repos safely.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
HCP Terraform Agent Pool Design Prompt
Design HCP Terraform (Terraform Cloud) agent pools for private-network runs — tfe_agent_pool, allowed-workspaces scoping, agent tokens, self-hosted agent deployment, agent execution mode, scaling, and hardening the agent hosts.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform TFLint Custom Ruleset Authoring Prompt
Author a custom TFLint ruleset — .tflint.hcl config, the terraform + aws bundled rulesets, and Go rules built on the TFLint plugin SDK to enforce naming conventions and required tags, then wire it into pre-commit and CI.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Vault Provider Secrets Integration Prompt
Inject HashiCorp Vault secrets into Terraform via data sources and ephemeral resources without persisting plaintext to state.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform jsonencode Policy Rendering Review Prompt
Review IAM/resource policies built with jsonencode and templatefile in Terraform for correctness, injection risk, and plan-time diff noise.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform replace_triggered_by Design Review Prompt
Design and audit lifecycle replace_triggered_by rules so intentional replacements fire correctly without causing surprise destroy/recreate cascades.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Provider Rate-Limit & Throttling Strategy Prompt
Diagnose and tune Terraform applies that intermittently fail with cloud provider API throttling (429/Rate exceeded) on large state or high-concurrency runs.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Backend State Lock Timeout Tuning Prompt
Tune Terraform state locking — lock-timeout, DynamoDB/backend contention, CI concurrency, and safe recovery from stuck locks.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform External & HTTP Data Source Security Review Prompt
Review Terraform external, http, and local-exec data sources for injection, secret leakage, idempotency, and supply-chain risk.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Plan Noise Reduction & Refresh Strategy Prompt
Kill perpetual-diff noise in Terraform plans — refresh strategy, ignore_changes, provider default drift, and -refresh=false trade-offs.
- Claude
- ChatGPT
- Cursor
Open prompt - Intermediate
Terraform Azure Naming Convention Module Prompt
Design a Terraform naming/abbreviation module for Azure that produces compliant, length-limited, globally-unique resource names with deterministic outputs.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform CIDR & Subnet Calculation Design Prompt
Get cidrsubnet/cidrsubnets/cidrhost math right so subnet layouts are non-overlapping, correctly sized, and stable as the network grows.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform EKS Cluster Module Review Prompt
Review a Terraform-managed EKS cluster and node groups for upgrade safety, IRSA/access wiring, and changes that silently replace the control plane or nodes.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Forced-Replacement Cause Triage Prompt
Pinpoint exactly which argument forced a `-/+` replacement in a terraform plan, and whether it can be avoided with ignore_changes, a moved block, or a different value.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform GCP Project Factory Design Prompt
Design a Terraform project-factory pattern that provisions GCP projects consistently — folder placement, billing, APIs, IAM, and quotas — with for_each over a project map.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform helm_release Resource Review Prompt
Review helm_release resources managed in Terraform for value drift, noisy diffs, upgrade safety, and the provider-bootstrap ordering trap.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform IAM Policy Document Refactor Prompt
Refactor inline JSON IAM policies into composable aws_iam_policy_document data sources with least privilege, while keeping the rendered policy semantically identical.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform RDS Zero-Downtime Change Plan Prompt
Analyze an RDS/Aurora terraform plan to tell in-place modifications from replacements, and sequence changes so the database isn't recreated or taken offline.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform time_rotating Resource Design Prompt
Design safe rotation cadence with the time provider (time_rotating, time_offset) so credentials, certs, and tokens regenerate on schedule without thrashing every plan.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform VPC Network Module Design Prompt
Design a reusable, greenfield VPC/network module with clean variable inputs, computed subnet layout, and stable outputs other stacks can consume.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Check Block Scoped Data Source Prompt
Design `check` blocks that use scoped data sources to assert post-apply runtime health (endpoints, DNS, cert expiry) as non-blocking warnings instead of hard plan failures.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform for_each Set vs Map Keys Prompt
Decide whether a `for_each` should iterate a set of strings or a map of objects so instance keys stay stable, readable, and free of churn when the collection changes.
- Claude
- ChatGPT
- Cursor
Open prompt - Advanced
Terraform Aliased Provider Passing to Nested Modules Prompt
Wire aliased providers (multi-region, multi-account) down through nested module trees using explicit `configuration_aliases` and `providers = {}` maps instead of implicit inheritance.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Removed Block Forget-Only Prompt
Use a `removed` block with `lifecycle { destroy = false }` to drop a resource from Terraform management without destroying the real infrastructure — the declarative replacement for `terraform state rm`.
- Claude
- ChatGPT
Open prompt - Advanced
Sentinel Mock Data Authoring Prompt
Generate Sentinel mock data from real `terraform plan` JSON so policies can be tested offline with `sentinel test`, including both pass and intentional-fail fixtures.
- Claude
- ChatGPT
Open prompt - Advanced
OpenTofu State Encryption Key Rotation Prompt
Rotate OpenTofu state-encryption keys safely using the `fallback` method so existing encrypted state can still be read while new writes use the new key — with zero downtime.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Native Test Run Block Ordering Prompt
Sequence `run` blocks in a `.tftest.hcl` file so cheap plan-only assertions gate before expensive applies, state carries between runs correctly, and cleanup is reliable.
- Claude
- ChatGPT
- Cursor
Open prompt - Intermediate
Terraform Workspace State Isolation Audit Prompt
Audit a CLI-workspace setup for accidental cross-workspace coupling — shared resource names, hardcoded values, and missing `terraform.workspace` guards that let one workspace clobber another.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Write-Only Argument Migration Prompt
Migrate existing secret arguments that linger in state (passwords, tokens) to write-only arguments and their `_wo_version` triggers, so sensitive values stop being persisted in the state file.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform CLI Configuration (.terraformrc) Hardening Prompt
Audit and design a hardened CLI configuration file for provider mirrors, plugin cache, and credential helpers across dev and CI
- Claude
- ChatGPT
Open prompt - Intermediate
terraform_data Replacement for null_resource Prompt
Migrate legacy null_resource + triggers patterns to the built-in terraform_data resource without forcing spurious replacements
- Claude
- ChatGPT
Open prompt - Advanced
Dynamic Multi-Instance Provider Configuration with for_each Prompt
Use for_each on provider configurations (Terraform 1.9+) to fan resources out across many accounts or regions without hand-written aliases
- Claude
- ChatGPT
Open prompt - Advanced
Ephemeral Resource Design for Short-Lived Credentials Prompt
Design ephemeral resources and ephemeral values to fetch and pass short-lived secrets without ever writing them to state or plan
- Claude
- ChatGPT
Open prompt - Intermediate
Plan JSON Dependency Graph Export Analysis Prompt
Export and analyze the resource dependency graph from terraform graph and plan JSON to explain ordering and blast radius
- Claude
- ChatGPT
Open prompt - Intermediate
Partial Backend Configuration Patterns Prompt
Design partial backend configuration so the same root module initializes against different state backends per environment without hardcoding secrets
- Claude
- ChatGPT
Open prompt - Intermediate
Resource Precondition and Postcondition Design Prompt
Add lifecycle precondition and postcondition blocks that fail a plan or apply early with clear messages instead of producing broken infrastructure
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Stacks Deferred Changes Planning Prompt
Plan and reason about deferred changes across Stack components so unknown-count expansions apply safely in dependency order
- Claude
- ChatGPT
Open prompt - Beginner
Variable Definition Precedence Audit Prompt
Trace why a Terraform input variable resolves to an unexpected value by auditing the full tfvars and environment-variable precedence chain
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Conftest Plan-JSON Gating Prompt
Wire conftest (OPA/Rego) into CI to evaluate the `terraform show -json` plan output, so policy violations fail the pipeline on the actual planned changes rather than on static config — with clear pass/warn/deny tiers and readable failure messages.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Cross-State Resource Migration Prompt
Plan and execute moving resources between two separate Terraform state files — splitting a monolith state or consolidating stacks — using `terraform state mv -state-out` (or `removed`+`import`) safely, with locking, backups, and a verified zero-diff outcome.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Deprecation Warnings Triage Prompt
Systematically triage and resolve deprecation warnings from `terraform plan`/`init` — deprecated provider arguments, attributes, and interpolation patterns — turning a noisy warning stream into a prioritized, low-risk remediation plan before the next major upgrade breaks the build.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Mock Data Test Fixtures Prompt
Build reusable mock fixtures for the native test framework's `mock_provider`/`override_data` so module tests run fast and offline — exercising logic, validation, and outputs without hitting real cloud APIs or creating billable resources.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Multi-Region Fan-Out Design Prompt
Design a maintainable pattern for deploying the same stack across many regions using provider aliases and module fan-out — avoiding the dead-end where provider configurations cannot be created from `for_each` and copy-pasted per-region blocks proliferate.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Policy Bundle Rollout Strategy Prompt
Plan the staged, versioned rollout of a policy-as-code bundle (Sentinel/OPA/conftest) across many Terraform workspaces and teams — moving rules from advisory to soft-mandatory to hard-mandatory without blocking delivery or causing mass plan failures.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Provider-Defined Functions Authoring Prompt
Design, implement, and document provider-defined functions (Terraform 1.8+) in a Go provider so configs can call typed, side-effect-free helpers instead of brittle string-munging in HCL.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Removed Block Deletion Planning Prompt
Use the declarative `removed` block (Terraform 1.7+) to drop resources or modules from configuration without destroying the underlying infrastructure — or to plan an intentional, reviewable destroy — instead of risky `state rm` surgery.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Stack Component Decomposition Prompt
Decompose a sprawling Terraform stack into well-bounded components along state, blast-radius, and change-frequency seams — deciding what belongs in one state file versus separate stacks wired by remote-state outputs, without creating dependency tangles.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Conditional Resource Pattern Review Prompt
Review and fix conditional resource creation (count toggles, ternaries, optional features) for safety and idempotency.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Cross-Account Resource Migration Prompt
Plan moving Terraform-managed resources between cloud accounts or subscriptions without destroy/recreate or data loss.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Dependency Cycle Resolution Prompt
Diagnose and break Terraform 'Cycle' errors in the resource dependency graph without destroying working resources.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform ignore_changes Lifecycle Audit Prompt
Audit and right-size lifecycle ignore_changes rules that are silently hiding real drift in Terraform plans.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Module Version Pinning Audit Prompt
Audit module source version constraints across a Terraform estate to eliminate unpinned, drifting, and risky references.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Nested Module Flattening Prompt
Refactor deeply nested Terraform module hierarchies into a flatter, maintainable composition without recreating resources.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform OIDC CI Authentication Design Prompt
Replace long-lived cloud credentials in Terraform CI pipelines with short-lived OIDC-federated identity.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform State Bloat Reduction Prompt
Diagnose and reduce oversized Terraform state causing slow plans, lock contention, and wide blast radius.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform State Pull/Push Manual Edit Safety Prompt
Plan a safe manual state edit via pull/push when CLI state commands cannot fix a corrupted or mis-tracked entry.
- Claude
- ChatGPT
Open prompt - Advanced
OpenTofu Early Variable Evaluation in Backends Prompt
Use OpenTofu's early variable evaluation to parameterize backend and module-source configuration that stock Terraform forces you to hardcode.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform for_each Key Stability Audit Prompt
Diagnose why a for_each resource is destroying and recreating instances on every plan because its map keys are unstable or derived from computed values.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Module Passed Provider Configuration Prompt
Correctly pass aliased provider configurations into a child module via configuration_aliases so multi-region or multi-account modules work without hidden provider inheritance.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Monolith to Modules Refactor Prompt
Break a sprawling single root module into reusable child modules using moved blocks so addresses stay intact and no resource is destroyed.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Plan Cost Gate in CI Prompt
Add an automated cost-delta gate to a Terraform pipeline that blocks or flags pull requests whose plan increases monthly spend beyond a threshold.
- Claude
- Copilot
Open prompt - Advanced
Terraform Remote State Data Source Boundaries Prompt
Design clean consumption of one stack's outputs by another using terraform_remote_state, deciding what to expose versus reading provider data sources directly.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Targeted Replace Workflow Prompt
Decide when and how to force-recreate a single resource safely using terraform plan -replace instead of the deprecated taint command, with a back-out plan.
- Claude
- Cursor
Open prompt - Advanced
Terraform Test Provider Mocking Prompt
Write fast, offline terraform test suites that use mock_provider and overrides so module logic is validated without provisioning real cloud resources.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Variable Type Constraints Design Prompt
Design precise complex type constraints for module inputs using object, map, and optional() so misuse fails fast at plan time with clear errors.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform CI Concurrency and Run Queueing Prompt
Prevent concurrent Terraform runs from colliding on the same state by designing locking, queueing, and serialization across CI pipelines.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Known After Apply Debugging Prompt
Untangle plans where too many values show `(known after apply)`, causing unnecessary churn, cascading replacements, or unreviewable diffs.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Lock File Cross-Platform Hashes Prompt
Diagnose and fix `.terraform.lock.hcl` failures caused by missing per-platform provider hashes when developers and CI run on different OS/architectures.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Module Deprecation Path Prompt
Plan a non-breaking migration when a published Terraform module's interface or behavior must change, so existing consumers can upgrade gradually.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Optional Object Attributes Prompt
Design backward-compatible module interfaces using `optional()` object attributes with defaults instead of a sprawl of flat variables.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Output Consumption Pipeline Prompt
Safely consume `terraform output -json` in downstream scripts, pipelines, and other tools without leaking secrets or coupling to fragile parsing.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Saved Plan Artifact Security Prompt
Harden the handling of saved `tfplan` files in CI so plan artifacts do not leak secrets or get applied with stale or tampered contents.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Plan JSON to PR Comment Prompt
Turn raw `terraform show -json` plan output into a compact, scannable pull-request comment that a reviewer can approve or reject in under a minute.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Provider Plugin Cache Prompt
Speed up `terraform init` in CI and local dev by configuring a shared provider plugin cache without breaking lock-file integrity.
- Claude
- ChatGPT
Open prompt - Advanced
Atlantis Server Setup & Workflow Prompt
Stand up a self-hosted Atlantis server for pull-request Terraform automation — repo allowlist, server-side workflows, autoplan, apply locks, and policy checks — with sane security defaults.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Core Version Upgrade Prompt
Plan a safe upgrade of the Terraform CLI/core version across many stacks — required_version constraints, deprecation handling, state compatibility, and a staged rollout that won't strand teams.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Module Documentation Generation Prompt
Auto-generate clear, consistent module documentation with terraform-docs — inputs, outputs, requirements, usage examples — and enforce it in CI so READMEs never drift from the code.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Error Message Debugging Prompt
Diagnose cryptic Terraform plan/apply errors — provider API faults, cycle errors, type mismatches, unknown-value-at-plan-time, and inconsistent-final-plan — and get a concrete fix path.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform GitHub Actions Pipeline Prompt
Design a production-grade GitHub Actions workflow for Terraform that runs fmt/validate/plan on PRs, posts plan summaries as comments, and gates apply behind environments and OIDC cloud auth.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Self-Service Module Platform Prompt
Design a golden-path self-service platform where app teams provision infrastructure through curated, opinionated Terraform modules with guardrails, scaffolding, and a private registry — minimizing copy-paste and blast radius.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Sensitive Output Audit Prompt
Audit a Terraform codebase for leaked secrets — sensitive values landing in outputs, logs, state, or CI artifacts — and apply sensitive flags, ephemeral handling, and redaction to stop exposure.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Resource Tagging Strategy Prompt
Design and enforce a consistent resource tagging strategy in Terraform — default_tags, merged module tags, mandatory keys for cost allocation and ownership — without per-resource boilerplate.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Apply Performance Tuning Prompt
Diagnose and speed up slow `terraform plan`/`apply` runs on large states — provider rate limits, refresh cost, parallelism, targeted operations, and state splitting — without compromising safety.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Check Blocks & Post-Apply Assertions Prompt
Add `check` blocks with scoped data sources and assertions that validate live infrastructure after apply — endpoints reachable, TLS valid, DNS resolving — turning silent misconfigurations into loud plan/apply warnings.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform CI Log Secret Redaction Prompt
Stop secrets from leaking into CI logs and PR plan comments — audit where Terraform exposes sensitive values, enforce `sensitive`, mask provider output, and scrub `terraform show -json` before posting.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Module SemVer & Release Strategy Prompt
Define a semantic-versioning and release process for an internal Terraform module library — what counts as breaking, how to tag, deprecate inputs, and let consumers pin safely across a fleet of root modules.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Provider Development Scaffolding Prompt
Scaffold a custom Terraform provider with the Plugin Framework — resources, data sources, schema, CRUD, import, and acceptance tests — for wrapping an internal API that has no existing provider.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Resource Targeting Strategy Prompt
Use `-target`, `-replace`, and `-exclude` deliberately and safely — for surgical fixes, breaking dependency deadlocks, and forcing replacement — while understanding the partial-state risks each one introduces.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Stacks Deployments Design Prompt
Design a Terraform Stacks (HCP) configuration that splits components from deployments, so one set of modules fans out across regions, accounts, and environments with orchestrated dependency ordering.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform State Disaster Recovery & Rebuild Prompt
Recover from a lost, corrupted, or diverged Terraform state file — rebuild state via bulk import, reconcile against live infrastructure, and harden the backend so it never happens again.
- Claude
- ChatGPT
Open prompt - Advanced
Terragrunt to Native Stacks Migration Prompt
Evaluate and plan a migration from a Terragrunt DRY setup to native Terraform Stacks (or OpenTofu stacks) — mapping `terragrunt.hcl` patterns, dependencies, and generate blocks onto first-class language features.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform count-to-for_each Migration Prompt
Safely migrate index-based `count` resources to keyed `for_each` so inserting or removing one item stops recreating every resource after it — using `moved` blocks and state moves, with a zero-change plan as proof.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Ephemeral & Write-Only Secrets Prompt
Use Terraform 1.10+ ephemeral resources, ephemeral values, and write-only arguments to flow secrets through configuration without ever persisting them in state or plan files.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Import Block Generation Prompt
Bring existing, hand-created cloud resources under Terraform using config-driven `import` blocks and `-generate-config-out` — then refine the generated HCL until the plan is a clean no-op.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Monorepo Structure Prompt
Design an org-scale Terraform monorepo — root modules, shared modules, environment boundaries, ownership via CODEOWNERS, and path-scoped CI — so hundreds of stacks stay navigable and changes have a tight blast radius.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Native Test Framework Prompt
Write `.tftest.hcl` tests using Terraform's built-in test framework — `run` blocks, `command = plan` vs `apply`, assertions, mocks, and providers — to validate modules in CI without third-party tooling.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Plan Output Summarization Prompt
Turn a noisy 4,000-line `terraform plan` into a crisp, reviewer-friendly summary — grouped by action, risk-ranked, with the dangerous changes surfaced first — for PR comments and approvals.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Provider Mirror for Air-Gapped CI Prompt
Set up a Terraform provider mirror (filesystem or network mirror) and `.terraformrc` so `terraform init` works in air-gapped or rate-limited CI without reaching the public registry.
- Claude
- ChatGPT
Open prompt - Advanced
Spacelift Stack & Policy Design Prompt
Design Spacelift stacks, spaces, contexts, and Rego policies for a Terraform org — trigger graphs, drift detection, approval gates, and least-privilege access — instead of bolting GitOps onto raw CI.
- Claude
- ChatGPT
Open prompt - Advanced
Terragrunt DRY Configuration Prompt
Restructure a sprawling multi-account, multi-region Terraform repo into a DRY Terragrunt layout — root config, includes, dependency wiring, and run-all orchestration — without breaking existing state.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Brownfield Adoption Prompt
Bring existing, hand-built cloud infrastructure under Terraform management safely — discovery, prioritized import waves, codegen, reconciling drift, and proving the first plan is a clean no-op.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Change Blast Radius Analysis Prompt
Before approving a Terraform PR, quantify the blast radius — which resources replace vs update in place, hidden cascade effects, downtime windows, and cross-module ripple — so reviewers approve with eyes open.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Dependency Lock File Management Prompt
Tame the `.terraform.lock.hcl` file — multi-platform hashes, controlled provider bumps, CI verification with `-lockfile=readonly`, and resolving the merge conflicts and 'checksum not in lock' errors that follow.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Drift Remediation Runbook Prompt
Turn detected drift into a safe, decision-driven remediation runbook — classify each drift, decide code-wins vs reality-wins, handle out-of-band changes, and codify guardrails so the same drift doesn't recur.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Locals & Expression Readability Prompt
Refactor gnarly Terraform expressions into clear, testable locals — taming nested for/conditionals, flatten/setproduct patterns, type coercion, and the unreadable one-liners that hide bugs.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Module Output Contracts Prompt
Design stable, well-typed module outputs that downstream modules can depend on — output naming, sensitive marking, object vs flat outputs, and versioning the contract so consumers don't break on every refactor.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Module Registry Publishing Prompt
Publish a reusable module to a public or private registry the right way — repo naming and structure, semantic version tags, examples and docs, automated release, and a consumer-friendly versioning policy.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Provisioners & local-exec Escape Hatch Prompt
Decide when (rarely) to use Terraform provisioners and how to do it safely — local-exec vs remote-exec vs null_resource, idempotency, failure handling, and the native alternatives that almost always beat them.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform State Encryption at Rest Prompt
Design end-to-end encryption for Terraform state — backend-side KMS, OpenTofu native state encryption, secrets that leak into state, and a key-rotation plan that won't lock you out.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Remote Backend Migration Prompt
Move Terraform state from one backend to another (local → S3, S3 → Terraform Cloud, or cross-account/region) with locking intact, zero state loss, and a tested rollback at every step.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Cost Estimation with Infracost Prompt
Wire per-PR cost estimation into Terraform reviews — surface the monthly delta of every plan, set budget guardrails, and turn cost into a first-class part of code review instead of a surprise on the bill.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Data Sources Design Prompt
Decide when to wire infrastructure together with data sources vs remote-state outputs vs hardcoded values — avoiding hidden coupling, plan-time failures, and the dreaded 'data source depends on a resource not yet created' trap.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Dependency Graph Debugging Prompt
Diagnose cycle errors, unexpected resource ordering, and 'value not known until apply' problems by reading Terraform's dependency graph and reshaping references instead of guessing with `depends_on`.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Destroy Safety Prompt
Tear down infrastructure deliberately — guarding stateful resources, ordering deletes correctly, draining dependencies, and proving exactly what will be destroyed before anything irreversible happens.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Moved & Import Blocks Prompt
Use declarative `moved` and `import` blocks to refactor and adopt resources without manual `terraform state mv`/`import` — keeping every change reviewable in a plan and reproducible in CI.
- Claude
- ChatGPT
Open prompt - Beginner
Terraform Pre-Commit & Linting Toolchain Prompt
Stand up a layered Terraform quality gate — fmt, validate, tflint, tfsec/checkov, terraform-docs, and trivy — wired through pre-commit so the same checks run on laptops and in CI without bikeshedding.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Provider Version Upgrade Prompt
Plan and execute a safe major-version provider upgrade (e.g. AWS 4.x → 5.x) by reading the changelog, mapping breaking changes to your code, and staging the rollout so no plan ever silently destroys resources.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Workspace-Per-Tenant Design Prompt
Design a scalable workspace strategy for multi-tenant or many-account fleets — deciding between CLI workspaces, separate state files, and TFC/TFE workspaces so you can manage hundreds of near-identical stacks without copy-paste sprawl.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform AWS Provider Patterns Prompt
Common Terraform AWS patterns — VPC + subnets, EKS, RDS, ALB, S3, IAM roles, naming conventions.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Secrets & Sensitive Variables Prompt
Manage secrets in Terraform — sensitive flag, ephemeral resources, external secret managers, plan/state masking.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Variable Validation Prompt
Add Terraform variable validation — types, validation blocks, sensitive, nullable, custom error messages.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Dynamic Blocks Prompt
Generate nested blocks dynamically — security group rules, tags, conditional blocks, complex iteration.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform `for_each` vs `count` Prompt
Choose between for_each and count for resource iteration — key stability, addition/removal behavior, when to use each.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Drift Detection Prompt
Detect Terraform drift — scheduled plans, refresh, drift reporting, alerting, distinguishing manual changes from external mutations.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Policy-as-Code (Sentinel / OPA / Checkov) Prompt
Implement policy-as-code for Terraform — Sentinel (TFC), OPA/Conftest, Checkov, tfsec, enforce security and compliance.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform → OpenTofu Migration Prompt
Migrate from Terraform to OpenTofu — state compatibility, provider replacement, CI updates, feature differences.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform CI/CD: Atlantis, Cloud, GitOps Prompt
Choose and configure Terraform CI/CD — Atlantis, Terraform Cloud, Spacelift, custom CI; plan/apply workflows, approvals.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Large State Refactor Prompt
Refactor large Terraform state — moved/removed blocks, splitting state files, extracting modules without destroy.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Plan Review Checklist Prompt
Review Terraform plan output — read 'destroy', 'replace', 'create', identify dangerous changes, automate review.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Cloud Provider Authentication Best Practices Prompt
Authenticate Terraform to cloud providers safely — AWS IAM roles, GCP service accounts, Azure managed identity, OIDC from CI.
- Claude
- ChatGPT
Open prompt - Intermediate
CloudFormation to Terraform Conversion Prompt
Convert an AWS CloudFormation template (YAML or JSON) into idiomatic Terraform HCL — preserving behavior, improving readability.
- Claude
- ChatGPT
- Cursor
Open prompt - Intermediate
Dangerous Terraform Changes Review Prompt
Scan a `terraform plan` output for changes that will silently destroy data, cause outages, or trigger irreversible mutations.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Module Review Prompt
Get a senior-engineer review of a Terraform module — variable hygiene, state safety, security defaults, drift resistance.
- Claude
- ChatGPT
- Cursor
Open prompt - Intermediate
Terraform Provider Configuration & Aliases Prompt
Configure Terraform providers — version constraints, aliases for multi-region/multi-account, required_providers.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform Module Testing Prompt
Test Terraform modules — terraform test (1.6+), terratest (Go), unit vs integration, mocking providers.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Module Composition Prompt
Design Terraform modules — input/output contracts, composition, versioning, public vs private registry, when to abstract.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Multi-Environment Design Prompt
Design Terraform for multiple environments — dev/staging/prod separation, tfvars patterns, account boundaries, promotion workflow.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform Workspaces vs Directory Structure Prompt
Choose between Terraform workspaces and directory-per-env — when each is appropriate, migration patterns.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform State Locking Debug Prompt
Diagnose Terraform state lock issues — DynamoDB / GCS / Azure lease locks, stuck locks, force-unlock, multi-runner contention.
- Claude
- ChatGPT
Open prompt - Advanced
Terraform State Surgery & Import Prompt
Perform Terraform state operations — terraform state mv/rm/import, replace, large-scale imports via import block.
- Claude
- ChatGPT
Open prompt - Intermediate
Terraform State Backend Design Prompt
Design Terraform state backend — S3+DynamoDB, GCS, Azure Blob, encryption, locking, versioning, cross-account access.
- Claude
- ChatGPT
Open prompt
Guides
- · 10 min read
Terraform vs OpenTofu: Which Should You Choose in 2026?
Terraform vs OpenTofu compared for 2026: licensing, CLI and state compatibility, state encryption, provider-defined functions, HCP ecosystem, and a per-team verdict.
Read guide - · 8 min read
Terraform Error: check block assertion failed during plan/apply
Understand Terraform 'Check block assertion failed' warnings: how check{} assert conditions and data-source scoping work, why they don't block apply, and how to fix a failing assertion.
Read guide - · 8 min read
Terraform Error: HCP Terraform cloud block workspace not found
Fix Terraform 'workspace not found' with the cloud block: wrong org/workspace name, missing tags, an unauthorized token, or a workspace that has not been created in HCP Terraform yet.
Read guide - · 8 min read
Terraform Error: 'Duplicate object key' in a for expression collision
Fix Terraform's 'Duplicate object key' error in a for expression: two iterations produce the same key. Diagnose the collision and build unique keys for maps, for_each, and objects.
Read guide - · 8 min read
Terraform Error: S3 Backend 'ResourceNotFoundException' — DynamoDB Lock Table Missing
Fix Terraform's S3 backend 'ResourceNotFoundException' error: create the DynamoDB state-lock table with a LockID key, fix dynamodb_table config, region mismatch, and IAM permissions.
Read guide - · 8 min read
Terraform Error: 'Error in function call' from cidrsubnet / cidrhost (prefix beyond 32 bits)
Fix Terraform cidrsubnet/cidrhost errors like 'would extend prefix to 33 bits, which is invalid': size your newbits and host numbers so the subnet fits inside the base CIDR.
Read guide - · 8 min read
Terraform Error: import block config generation failed on plan
Fix Terraform 'generate-config-out' failures for import blocks: missing -generate-config-out flag, existing resource declaration, or provider attributes that can't be generated.
Read guide - · 8 min read
Terraform Error: 'Invalid combination of arguments' (ConflictsWith / ExactlyOneOf)
Fix Terraform's 'Invalid combination of arguments' error from ConflictsWith and ExactlyOneOf provider rules: find the mutually exclusive attributes and set exactly the right one.
Read guide - · 8 min read
Terraform Error: 'Invalid ignore_changes' cannot ignore a required argument
Fix Terraform's 'Invalid ignore_changes' error: ignore_changes references an unknown attribute or a required argument, or uses all incorrectly. Diagnose and correct the lifecycle block.
Read guide - · 8 min read
Terraform Error: 'Error in function call' from jsondecode (invalid character)
Fix Terraform jsondecode errors like 'invalid character ... looking for beginning of value': locate the malformed JSON (trailing commas, single quotes, empty input) and correct it.
Read guide - · 8 min read
Terraform Error: 'reference to undeclared provider' Aliased Provider Not Configured
Fix Terraform's 'reference to undeclared provider' / invalid provider alias error: declare the aliased provider, wire configuration_aliases in modules, and pass providers correctly.
Read guide - · 8 min read
Terraform Error: 'Invalid version constraint' Malformed required_version String
Fix Terraform's 'Invalid version constraint' error: correct malformed required_version and provider version strings, use valid operators like ~> and >=, and quote constraints properly.
Read guide - · 8 min read
Terraform Error: 'Error in function call' from yamldecode (invalid YAML on line N)
Fix Terraform yamldecode errors like 'on line 3, column 1: did not find expected key': locate the malformed YAML (tabs, indentation, unquoted colons) and correct the input string.
Read guide - · 8 min read
Terraform Error: 'moved' block invalid reference (both endpoints exist)
Fix Terraform 'moved' block errors like 'Unable to move ... both refer to existing objects' and 'Invalid moved block address': point from an old, gone address to a new one.
Read guide - · 8 min read
Terraform Error: 'workspace ... does not exist' Selected Workspace Missing
Fix Terraform's 'workspace does not exist' error: list and create workspaces, understand TF_WORKSPACE, and select the right state workspace before plan or apply.
Read guide - · 8 min read
Terraform Error: 'Output refers to sensitive values' Missing sensitive = true
Fix Terraform's 'Output refers to sensitive values' error: mark outputs sensitive = true, understand sensitivity propagation, and safely surface secrets without leaking them to logs.
Read guide - · 8 min read
Terraform Error: 'refresh-only plan cannot be applied' When Applying a Saved Plan
Fix Terraform's 'plan was created with the -refresh-only option and cannot be applied' error: understand refresh-only mode, apply state changes correctly, and regenerate a normal plan.
Read guide - · 8 min read
Terraform Error: 'Instance cannot be destroyed' Due to lifecycle prevent_destroy
Fix Terraform's 'Instance cannot be destroyed' error from lifecycle prevent_destroy: understand the guard, safely remove or override it, and handle destroy/replace and terraform destroy.
Read guide - · 8 min read
Terraform Error: Call to unknown function for a provider-defined function
Fix Terraform 'Call to unknown function' for provider::<name>::<fn> calls: missing required_providers entry, wrong provider local name, or a provider too old to expose functions.
Read guide - · 8 min read
Terraform Error: 'no available provider ... matches constraints' Version Conflict
Fix Terraform's 'no available provider matches version constraints' error: reconcile conflicting required_providers across modules, update the lock file, and align version constraints.
Read guide - · 9 min read
Terraform Error: 'local-exec provisioner error' command exited with a non-zero status
Fix Terraform's local-exec provisioner 'Error running command ... exit status N' failure: diagnose the underlying command, PATH, working directory, and interpreter issues, and recover state.
Read guide - · 9 min read
Terraform Error: 'remote-exec provisioner error' timeout waiting for SSH connection
Fix Terraform's remote-exec 'timeout - last error: dial tcp ... connection refused / i/o timeout' failure: diagnose SSH connectivity, security groups, keys, and boot timing, then recover.
Read guide - · 8 min read
Terraform Error: '401 Unauthorized' from the Remote/Cloud Backend
Fix Terraform's remote/cloud backend '401 Unauthorized' error: diagnose invalid API tokens, missing credentials blocks, wrong hostname, and TF_TOKEN environment variables.
Read guide - · 8 min read
Terraform Error: 'removed' block still declared in configuration
Fix Terraform's 'Removed resource still present' error: a removed block must target a resource whose resource/module declaration has actually been deleted from your config.
Read guide - · 9 min read
Terraform Error: S3 Backend 'AccessDenied' Reading or Writing State
Fix Terraform's S3 backend 'AccessDenied' error: diagnose missing IAM permissions, wrong bucket policy, KMS key access, bucket ownership, and region mismatches on the state object.
Read guide - · 8 min read
Terraform Error: 'Call to function templatefile failed' invalid template syntax
Fix Terraform's templatefile() 'call to function ... failed' error: diagnose undefined variables, bad directive syntax, and literal ${} escaping in the template file, then render it correctly.
Read guide - · 9 min read
Using mock_provider with configuration_aliases in Terraform Tests
Mock aliased providers in Terraform tests: declare configuration_aliases in required_providers, wire provider aliases in run blocks, and use mock_provider with alias for multi-region modules.
Read guide - · 9 min read
How to Use mock_provider in Terraform Tests (.tftest.hcl)
Use mock_provider in Terraform tests (.tftest.hcl) to fake AWS providers, run terraform test with command = plan, and avoid real API calls. Examples, gotchas, and when to mock.
Read guide - · 9 min read
mock_provider vs override_resource vs override_data in Terraform Tests
Decide between mock_provider, override_resource, and override_data in .tftest.hcl. When to mock a whole provider vs override a single resource or data source in Terraform 1.7+ tests.
Read guide - · 9 min read
Mocking terraform_remote_state in Terraform Tests (.tftest.hcl)
Mock terraform_remote_state in Terraform tests with override_data and mock_provider. Fix data.terraform_remote_state failures in .tftest.hcl unit tests for Terraform 1.7+.
Read guide - · 9 min read
Terraform Tests: Mock Data Sources with mock_provider and override_data
Mock data sources in Terraform tests using mock_provider and override_data, including terraform_remote_state. Pin data source values in .tftest.hcl run blocks with real HCL examples.
Read guide - · 9 min read
Passing mock_provider Through the providers Block in Terraform Tests
Wire mock_provider into modules with the providers = { aws = aws.mock } block in .tftest.hcl. Fix aliased mock providers not reaching child modules in Terraform 1.7+ tests.
Read guide - · 9 min read
Terraform Error Guide: 'Backend initialization required, please run "terraform init"' — Re-Init the Backend
Fix 'Backend initialization required' in Terraform: run terraform init, adding -reconfigure or -migrate-state when the backend changes or .terraform is gone.
Read guide - · 9 min read
Terraform Error Guide: 'Conflicting configuration arguments' — Remove the Mutually Exclusive Argument
Fix Terraform 'Conflicting configuration arguments': two mutually exclusive fields are set together. Keep one, delete the other, split inline vs standalone.
Read guide - · 9 min read
Terraform Error Guide: 'Duplicate variable declaration' — Remove the Redeclared Variable Block
Fix Terraform 'Duplicate variable declaration': the same variable name is declared twice across your .tf files. Find both blocks and delete the duplicate.
Read guide - · 9 min read
Terraform Error Guide: 'Failed to get existing workspaces' — Fix Backend Credentials, IAM, and Bucket Config
Fix Terraform 'Failed to get existing workspaces': grant s3:ListBucket, fix credentials, correct the bucket and region, and check DynamoDB lock permissions.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid default value for variable' — Align the Default With the Type Constraint
Fix 'Invalid default value for variable' in Terraform by matching the default to its type constraint: string vs number, list vs set, and object attributes.
Read guide - · 9 min read
Terraform Error Guide: 'Missing newline after argument' — Fix HCL Syntax and Run terraform fmt
Fix Terraform 'Missing newline after argument': two arguments share a line, a comma is missing in a list or map, or a stray token slipped in. Correct the HCL.
Read guide - · 9 min read
Terraform Error Guide: 'Reference to undeclared module' — Declare or Rename the Module Block and Re-init
Fix Terraform 'Reference to undeclared module': declare the missing module block, match the name in your module.<name> references, then run terraform init.
Read guide - · 9 min read
Terraform Error Guide: 'state data in S3 does not have the expected content' — Reconcile the DynamoDB Digest
Fix 'state data in S3 does not have the expected content' in Terraform: reconcile the DynamoDB digest against S3, wait out S3 delays, then repair the lock row.
Read guide - · 9 min read
Terraform Error Guide: 'Variables not allowed' — Use Literals or Partial Backend Config
Fix 'Variables not allowed' in Terraform: replace var./local. references in backend and terraform{} blocks with literals or a -backend-config partial config.
Read guide - · 8 min read
Terraform Error Guide: 'Argument or block definition required' — Fix HCL Syntax
Fix Terraform 'Argument or block definition required' errors: repair broken HCL syntax, missing equals signs, stray braces, unquoted values, and malformed blocks that fail parsing.
Read guide - · 9 min read
Terraform Error Guide: 'Call to unknown function' — Fix Wrong or Missing Functions
Fix Terraform 'Call to unknown function' errors: correct misspelled built-ins, add the provider:: prefix for provider-defined functions, run terraform init, and match core versions.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid resource type' — Fix Missing or Wrong Provider
Fix Terraform 'Invalid resource type' errors: correct the resource name, add or pin the right provider in required_providers, run terraform init, and align provider versions.
Read guide - · 9 min read
Terraform Error Guide: 'Cannot import non-existent remote object' — fix the import ID
Fix 'Cannot import non-existent remote object' in Terraform: correct the import ID format, target the right region/account and provider, and verify the resource actually exists before importing.
Read guide - · 9 min read
Terraform Error Guide: 'state snapshot was created by Terraform vX which is newer than current' — upgrade the CLI
Fix 'state snapshot was created by a newer Terraform version': upgrade your CLI to match, stop mixed-version applies, pin the toolchain in CI, and recover a state written by a newer binary.
Read guide - · 9 min read
Terraform Error Guide: 'Unsupported Terraform Core version' — align the required_version constraint
Fix 'Unsupported Terraform Core version' in Terraform: reconcile the required_version constraint with the CLI you run locally and in CI, pin versions with tfenv, and avoid split-brain toolchains.
Read guide - · 10 min read
Terraform Error Guide: '# forces replacement' — Stop Accidental Resource Destroys
Understand Terraform's '# forces replacement' plan diff: find the immutable attribute driving destroy-and-create, and use lifecycle, ignore_changes, moved blocks and -target to avoid data loss.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid value for variable' — Fix Type & Validation Failures
Fix Terraform's 'Invalid value for variable' error: understand type constraints and validation blocks, trace -var and tfvars precedence, read the error_message, and correct the offending input.
Read guide - · 9 min read
Terraform Error Guide: 'Missing required argument' — Fix Omitted Resource Arguments
Fix Terraform's 'Missing required argument' error: read the block and line it cites, check the provider schema for required vs optional arguments, add nested blocks, and pass module inputs.
Read guide - · 9 min read
Terraform Error Guide: 'Duplicate resource configuration' (two blocks with the same type and name)
Fix Terraform's 'Duplicate resource configuration' error caused by copy-paste, re-included files, or leftover blocks after a refactor.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid count argument' (count depends on values not known until apply)
Fix Terraform's 'Invalid count argument' error when count depends on apply-time values: use plan-time values, for_each, or a two-stage targeted apply.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid template interpolation value' (interpolating non-string types into strings)
Fix Terraform's 'Invalid template interpolation value' by converting lists, maps, and objects to strings with jsonencode, join, lookup, or tostring.
Read guide - · 9 min read
Terraform Error Guide: 'Error locking state: ConditionalCheckFailedException' (S3 backend DynamoDB lock table)
Fix Terraform 'Error locking state: ConditionalCheckFailedException' from the S3 backend DynamoDB lock table — stale locks, concurrent runs, and safe unlocks.
Read guide - · 9 min read
Terraform Error Guide: 'Provider configuration not present' (removed or aliased provider during destroy/refactor)
Fix Terraform's 'Provider configuration not present' error caused by removed or aliased providers during refactors and module deletions.
Read guide - · 9 min read
Terraform Error Guide: 'Reference to undeclared input variable' (missing or mistyped variable declarations)
Fix Terraform's Reference to undeclared input variable error caused by typos, a missing variables.tf, renames, or module-scoped variables.
Read guide - · 9 min read
Terraform Error Guide: 'Unsupported attribute' (reading an attribute that does not exist on an object)
Fix Terraform's 'Unsupported attribute' error: correct typo'd attribute names, use map index syntax, declare module outputs, and match provider versions.
Read guide - · 9 min read
Terraform Error Guide: 'Unsupported block type' (invalid or misplaced configuration blocks)
Fix Terraform's 'Unsupported block type' error caused by typos, block-vs-argument confusion, wrong schema, or provider version mismatches.
Read guide - · 9 min read
Terraform Error Guide: 'value depends on resource attributes that cannot be determined until apply' (apply-time unknowns)
Fix Terraform apply-time unknown values that break for_each keys, dynamic blocks, and conditionals using known keys and staged -target applies.
Read guide - · 9 min read
Terraform Error Guide: 'authentication failed' — provider credentials for AWS, Azure, GCP
Fix Terraform provider authentication errors: refresh expired SSO/STS tokens, set AWS/ARM/GOOGLE env vars, pick the right profile, and repair assume-role and OIDC in CI.
Read guide - · 9 min read
Terraform Error Guide: 'Backend configuration changed' — init -reconfigure vs -migrate-state
Fix Terraform's 'Backend configuration changed' error: back up state, then choose terraform init -reconfigure or -migrate-state correctly so you never lose or duplicate state.
Read guide - · 9 min read
Terraform Error Guide: 'error configuring Terraform AWS Provider' on plan/apply
Fix Terraform's 'error configuring provider' failure: supply valid config args, avoid unknown values in provider blocks, order resources with depends_on, and set the right region.
Read guide - · 9 min read
Terraform Error Guide: 'Failed to download module' source and auth fix
Fix Terraform's 'Failed to download module' error: correct the source address, set up git/SSH auth and tokens, pin a real ref, and re-run terraform init -upgrade.
Read guide - · 9 min read
Terraform Error Guide: 'Failed to install provider' (checksum mismatch) on init
Fix Terraform's 'Failed to install provider' error: resolve lock-file checksum mismatches, clear corrupted downloads and plugin cache, add platform hashes, and re-init cleanly.
Read guide - · 9 min read
Terraform Error Guide: 'Failed to load state' — corrupt, missing, or newer-version state
Fix Terraform's 'Failed to load state' error: recover truncated JSON, restore from backend versioning or .tfstate.backup, align Terraform versions, and clear stale locks.
Read guide - · 9 min read
Terraform Error Guide: 'Failed to query available provider packages' on init
Fix Terraform's 'Failed to query available provider packages' error: reconcile version constraints, correct source addresses, regen the lock file, and clear registry/proxy blocks.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid expression' (HCL syntax token and character errors)
Fix Terraform's 'Invalid expression' error: balance braces and quotes, add missing commas, drop stray ${} wrappers, correct heredocs, then run terraform fmt and validate.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid function argument' (bad type or value passed to a function)
Fix Terraform's 'Invalid function argument' error: convert types with tostring/tonumber/tolist, fix cidrsubnet ranges, guard inputs with try()/can(), test in console.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid index' (the given key does not identify an element)
Fix Terraform's 'Invalid index' error: match count.index vs each.key, guard missing keys with try() and lookup(), and stop indexing empty or computed collections.
Read guide - · 9 min read
Terraform Error Guide: 'Module not installed' run terraform init
Fix Terraform's 'Module not installed' error: run terraform init or terraform get, stop committing .terraform, and add an init step to CI on fresh checkouts.
Read guide - · 9 min read
Terraform Error Guide: 'No value for required variable' (input variable is not set)
Fix Terraform's 'No value for required variable' error: pass values via tfvars, -var, or TF_VAR_ env, add sensible defaults, and wire variables correctly in CI.
Read guide - · 9 min read
Terraform Error Guide: 'Provider produced inconsistent result after apply' (apply-time provider bug)
Fix Terraform's 'Provider produced inconsistent result after apply' error: upgrade the provider, use ignore_changes for eventual-consistency drift, retry, and report upstream.
Read guide - · 9 min read
Terraform Error Guide: 'timeout while waiting for state to become available'
Fix Terraform apply timeouts: raise the timeouts block, check the cloud console for the real status, handle throttling, and treat the underlying failure not the symptom.
Read guide - · 9 min read
Terraform Error Guide: 'Unsupported argument' (an argument is not expected here)
Fix Terraform's 'Unsupported argument' error: correct typo'd names, match provider versions, separate nested blocks from attributes, and pass module inputs right.
Read guide - · 9 min read
Auditing Terraform Workspace State Isolation Before It Bites Production
CLI workspaces isolate state, not config — so one hardcoded name lets dev clobber prod. Here's how to audit a workspace setup for the cross-environment coupling that causes outages.
Read guide - · 10 min read
Terraform Check Blocks With Scoped Data Sources for Live Health Assertions
Terraform check blocks can carry their own scoped data source to probe live infrastructure as a non-blocking warning. Here's how to assert runtime health without failing every plan.
Read guide - · 10 min read
for_each Set vs Map Keys in Terraform: Stop the Churn
The set-vs-map choice behind a Terraform for_each decides your instance addresses — and whether the next edit is a no-op or a destroy. Here's how to pick keys that survive change.
Read guide - · 9 min read
Forgetting Terraform Resources With the removed Block (Without Destroying Them)
The removed block can destroy a resource or just forget it — and one line of HCL separates the two. Here's how to drop resources from Terraform management while leaving the real infra running.
Read guide - · 11 min read
Migrating Terraform Secrets to Write-Only Arguments
Sensitive doesn't keep secrets out of state — it only hides them in output. Here's how to migrate existing secret arguments to write-only variants so plaintext stops landing in state.
Read guide - · 10 min read
Ordering run Blocks in Terraform Native Tests for Fast, Reliable Suites
Terraform native tests run top to bottom, share state, and mix free plan checks with billable applies. Here's how to order run blocks so suites stay fast, cheap, and trustworthy.
Read guide - · 10 min read
Passing Aliased Providers Into Terraform Modules the Right Way
Implicit provider inheritance breaks the moment a module needs two regions or accounts. Here's how to wire aliased providers explicitly with configuration_aliases and provider maps.
Read guide - · 11 min read
Rotating OpenTofu State Encryption Keys Without Locking Yourself Out
OpenTofu state encryption is easy to turn on and easy to brick during a key rotation. Here's the two-phase fallback method that rotates keys with zero downtime and a safe rollback.
Read guide - · 9 min read
Terraform Error Guide: 'Error acquiring the state lock' on plan/apply
Fix Terraform's 'Error acquiring the state lock': diagnose stale DynamoDB/blob locks, abandoned CI runs, expired credentials, and safely force-unlock state.
Read guide - · 9 min read
Terraform Error Guide: 'Cycle' dependency cycle detected on plan
Fix Terraform's 'Cycle' error: break circular dependencies between resources, modules, and data sources using indirection, depends_on, and split applies.
Read guide - · 9 min read
Terraform Error Guide: 'Inconsistent dependency lock file' on init/plan
Fix Terraform's 'Inconsistent dependency lock file' error: reconcile .terraform.lock.hcl hashes, missing platforms, version bumps, and CI -lockfile=readonly runs.
Read guide - · 9 min read
Terraform Error Guide: 'Invalid for_each argument' (values cannot be determined) on plan
Fix Terraform's 'Invalid for_each argument' error: handle computed keys, unknown values until apply, null/sensitive maps, and use -target or static keys to break it.
Read guide - · 8 min read
Terraform Error Guide: 'Provider produced inconsistent final plan' on apply
Fix Terraform's 'Provider produced inconsistent final plan' error: identify provider bugs, computed-attribute drift, version mismatches, and unstable expressions.
Read guide - · 8 min read
Terraform Error Guide: 'Reference to undeclared resource' on plan
Fix Terraform's 'Reference to undeclared resource' error: trace typo'd labels, missing modules, wrong resource types, count/for_each indexing, and removed blocks.
Read guide - · 9 min read
Terraform Error Guide: 'Error refreshing state' authentication / 403 expired credentials
Fix Terraform's 'Error refreshing state' auth failures: renew expired STS/SSO tokens, fix assume-role chains, region/profile mismatches, and backend 403s.
Read guide - · 9 min read
Terraform Error Guide: 'A resource with the ID ... already exists' on apply
Fix Terraform's 'already exists' / 'already managed' errors: import existing cloud resources, remove duplicate state entries, and reconcile out-of-band creation.
Read guide - · 8 min read
Terraform Error Guide: 'Saved plan is stale' on apply
Fix Terraform's 'Saved plan is stale' error: understand why a tfplan no longer matches state after drift, out-of-band changes, or concurrent applies, and regenerate it.
Read guide - · 11 min read
Writing Sentinel Mock Data for Terraform Policy Tests
An untested Sentinel policy is a liability that sits in your apply path. Here's how to generate mock data from real plans and write pass and fail fixtures that prove a policy actually works.
Read guide - · 11 min read
Analyzing Terraform Plan Blast Radius With AI Before You Apply
A plan that destroys and recreates a database reads almost the same as one that tweaks a tag. AI can surface the blast radius hiding in your plan JSON.
Read guide - · 12 min read
Building an AI Terraform PR Review Bot That Can't Touch Your Infra
Wire an AI reviewer into Terraform pull requests so it comments on every plan automatically — with an architecture that gives it zero ability to apply anything.
Read guide - · 11 min read
Converting CloudFormation to Terraform With AI Without Trusting It Blindly
AI can translate CloudFormation YAML into HCL faster than any human, but the output lies in subtle ways. Here's a workflow that catches the lies before they ship.
Read guide - · 10 min read
Generating Terraform Documentation With AI and terraform-docs
terraform-docs gives you the tables; AI writes the prose nobody wants to. Pair them to ship module docs that explain the why, not just the variable names.
Read guide - · 11 min read
Modernizing Legacy Terraform HCL Syntax With AI as Your Co-Pilot
Old Terraform is full of count hacks, interpolation syntax, and deprecated arguments. AI can modernize HCL fast, but only a clean plan proves it was right.
Read guide - · 10 min read
Reviewing Terraform Network and Security Group Changes With AI
A single 0.0.0.0/0 in a Terraform security group can expose a database to the internet. AI is a sharp second pair of eyes on network diffs, used carefully.
Read guide - · 11 min read
Right-Sizing Terraform-Managed Resources With AI From Real Metrics
Over-provisioned instances and bloated disks hide in plain sight in Terraform. AI can turn utilization metrics into right-sizing suggestions you review and apply.
Read guide - · 10 min read
Scaffolding Multi-Environment Terraform tfvars With AI Safely
Dev, staging, and prod tfvars drift apart one copy-paste at a time. AI can generate consistent per-environment variable files — if you keep it away from secrets.
Read guide - · 10 min read
Writing Terraform Data Source Queries With AI Instead of Hardcoding IDs
Hardcoded AMI IDs and subnet ARNs rot the moment infrastructure shifts. AI is great at turning them into data source lookups — verified against a real plan.
Read guide - · 18 min read
The Best Way to Learn Terraform for Real Infrastructure
The best way to learn Terraform is to build real infrastructure in a throwaway cloud account, in a deliberate order, with state, modules, and CI from day one.
Read guide - · 9 min read
Enforcing Terraform Standards With TFLint and AI-Authored Rules
Use TFLint to enforce Terraform conventions and catch provider-specific errors, with AI drafting config and lint rules that a human reviews before they land.
Read guide - · 11 min read
Generating CDKTF Infrastructure With AI: TypeScript Over HCL
How to use AI to scaffold and review CDKTF infrastructure in TypeScript: synth-to-plan workflow, when code beats HCL, and keeping a human on every plan.
Read guide - · 15 min read
How AI Helps DevOps Engineers Write Better Terraform Code
AI helps DevOps engineers write better Terraform code by reviewing plans for security and cost risk, generating modules you verify, and refactoring safely.
Read guide - · 10 min read
Mocking Providers in Terraform Tests for Fast, Offline Runs
Use mock_provider and override_resource/override_data/override_module in terraform test to write fast offline unit tests, with AI scaffolds reviewed by humans.
Read guide - · 11 min read
Parsing Terraform Plan JSON for AI-Assisted Review
Export terraform plan JSON, then use jq plus AI to summarize and risk-score changes in CI, with humans on every apply and never handing over state or creds.
Read guide - · 9 min read
Retiring Resources Safely With the Terraform removed Block
Use the Terraform removed block (1.7+) to declaratively drop resources from state without destroying real infrastructure. The modern replacement for state rm.
Read guide - · 10 min read
Scanning Terraform With Checkov and tfsec, Then Fixing With AI
Scan Terraform with Checkov and tfsec, emit SARIF in CI, manage skip comments, and let AI triage the findings to draft remediations a human always reviews.
Read guide - · 10 min read
Surgical Terraform Operations: target, replace, and refresh-only
Use terraform -target, -replace, and -refresh-only as careful escape hatches, not workflow. Let AI propose the minimal safe op while a human reviews every plan.
Read guide - · 9 min read
Taming Sensitive Values and Outputs in Terraform
How Terraform sensitive variables and outputs work, the way sensitivity propagates through expressions, the nonsensitive() footgun, and AI-assisted leak audits.
Read guide - · 9 min read
Writing Bulletproof Terraform Variable Validation With AI
Use AI to draft strong Terraform variable validation blocks that fail fast at plan time, then have a human review every condition before you ever apply.
Read guide - · 9 min read
Debugging Cryptic Terraform Errors With AI
Terraform error messages range from clear to baffling. AI is a fast translator for the baffling ones, if you give it the config and the full error, not a screenshot.
Read guide - · 11 min read
Designing Terraform Modules With AI as a Junior Engineer
AI can scaffold a Terraform module in seconds, but a good module is about interface design, not typing speed. Here is how to use AI without inheriting its bad defaults.
Read guide - · 10 min read
Onboarding to a Huge Terraform Codebase With AI
Inheriting 200 modules and a sprawling state is intimidating. AI is a fast guide through unfamiliar Terraform, as long as you verify its map against the real plan.
Read guide - · 11 min read
Reviewing Terraform IAM Changes With AI Before They Ship
IAM policy diffs are where Terraform plans quietly grant too much. AI is a sharp reviewer for privilege creep, if you feed it the right structured input.
Read guide - · 11 min read
Triaging Terraform Drift Alerts With AI Without Blind Reapplies
Drift detection fires alerts; deciding which ones matter is the hard part. AI triages drift between benign and dangerous, but a human still approves every reconcile.
Read guide - · 12 min read
Using AI to Plan a Safe Terraform State Migration
State surgery is the scariest part of Terraform. AI can map out a state migration plan step by step, but it must never run a single state command itself.
Read guide - · 11 min read
Using AI to Survive a Terraform Provider Major Version Bump
A major provider upgrade can rewrite half your plan. AI reads the changelog and your code together to find the breaking changes before they break you.
Read guide - · 12 min read
Writing Terraform Policy-as-Code Rules With AI
Rego and Sentinel are easy to get subtly wrong. AI can draft policy-as-code for Terraform fast, but every rule needs a failing test before you trust it as a gate.
Read guide - · 10 min read
Writing Terraform Tests With AI Without Faking the Coverage
AI can churn out Terraform native test files fast, but most of what it writes tests nothing. Here is how to get assertions that would actually catch a regression.
Read guide - · 9 min read
Building Continuous Terraform Drift Detection Into Your Pipeline
Catching drift once it's caused an outage is too late. Here's how to run scheduled drift detection that surfaces out-of-band changes before they bite you.
Read guide - · 8 min read
Catching Bad Infrastructure Early With Terraform Check Blocks and Assertions
Validation, preconditions, postconditions, and check blocks each catch failures at a different moment. Knowing which to use where prevents a lot of 2am surprises.
Read guide - · 8 min read
Encrypting Terraform State at the Source With OpenTofu State Encryption
Backend encryption protects state at rest, but OpenTofu encrypts state before it ever leaves your machine. Here's how client-side state encryption actually works.
Read guide - · 8 min read
Provider-Defined Functions: The Terraform Feature That Kills Your Locals Sprawl
Terraform's built-in functions can't do everything, so people build grotesque locals to parse ARNs and encode JWTs. Provider-defined functions fix that. Here's how.
Read guide - · 8 min read
Sharing Data Between Terraform Configurations Without Creating a Mess
Remote state data sources are the obvious way to share outputs between configs, and the easiest way to build a brittle dependency web. Here are the safer patterns.
Read guide - · 8 min read
Spacelift vs env0: Choosing a Terraform Automation Platform
Both promise managed Terraform runs, policy gates, and drift detection. The differences only matter once you know what your team actually needs. Here's how to decide.
Read guide - · 8 min read
Stop Leaking Secrets With Terraform Ephemeral Resources and Write-Only Arguments
Terraform has always written your secrets to state in plaintext. Ephemeral resources and write-only arguments finally close that hole. Here's how to use both.
Read guide - · 8 min read
Taming the Terraform Lock File and Version Constraints for Real
The .terraform.lock.hcl file and version constraints quietly decide whether your applies are reproducible. Most teams treat them as noise. Here's how to use them right.
Read guide - · 8 min read
Terraform Stacks Explained for Teams Drowning in Workspaces
Workspaces and copy-pasted root modules don't scale to dozens of environments. Terraform Stacks rethink the unit of deployment. Here's how they actually work.
Read guide - · 8 min read
Cutting Cloud Bills With Infracost in Your Terraform Pipeline
Most cloud overspend is committed in a Terraform PR nobody priced. Here's how to put a dollar figure on every plan with Infracost and catch the expensive change before merge.
Read guide - · 9 min read
GitOps for Terraform With Atlantis and Spacelift
Running terraform apply from laptops doesn't scale or stay safe. Here's how Atlantis and Spacelift turn pull requests into the apply workflow — and how to pick between them.
Read guide - · 9 min read
Importing Existing Infrastructure Into Terraform at Scale
Bringing a pile of click-ops resources under Terraform without an outage is a real project. Here's a staged approach using import blocks, generated config, and zero-change plans.
Read guide - · 9 min read
Keeping Terraform DRY With Terragrunt Without the Magic
Terragrunt promises DRY Terraform across dozens of environments, but it's easy to bury your config in indirection. Here's how to adopt it deliberately and keep it debuggable.
Read guide - · 9 min read
Policy as Code for Terraform With OPA and Sentinel
Stop relying on PR reviewers to catch the public S3 bucket. Here's how to enforce Terraform guardrails automatically with OPA/Conftest and Sentinel — and which checks are worth writing.
Read guide - · 8 min read
Taming Terraform Dynamic Blocks Without Making Config Unreadable
Dynamic blocks kill repetition in Terraform, but they're also where readable config goes to die. Here's how to use them deliberately — and when a plain static block is the better call.
Read guide - · 8 min read
Terraform Provider Configuration and Aliases Done Right
Multi-region and multi-account Terraform lives and dies on provider aliases. Here's how to configure providers, pass them into modules, and avoid the errors that block every apply.
Read guide - · 8 min read
Terraform Workspaces vs Directories: When Each One Makes Sense
Workspaces look like the obvious way to manage dev, staging, and prod — until they aren't. Here's how to choose between workspaces and directory-per-environment without painting yourself into a corner.
Read guide - · 8 min read
Fixing Terraform State Drift Before It Bites You
Drift is what happens between your code and reality when humans touch the console. Here's how I detect it, reconcile it, and stop it from causing failed applies.
Read guide - · 9 min read
Large Terraform Refactors With Moved and Import Blocks
Renaming resources or absorbing existing infra used to mean scary state surgery. Moved and import blocks make large refactors reviewable and safe. Here's my playbook.
Read guide - · 8 min read
Managing Secrets in Terraform Without Leaking Them
Terraform writes every secret it touches into state in plaintext. Here's how I keep credentials out of code and state, and reference them safely instead.
Read guide - · 8 min read
Migrating From Terraform to OpenTofu: A Practical Guide
Evaluating the OpenTofu fork? Here's how I assess the switch, run the migration safely on a large estate, and decide whether it's worth it for your team.
Read guide - · 9 min read
Running Terraform Safely in CI/CD Pipelines
Letting CI run terraform apply unattended is powerful and terrifying. Here's the pipeline structure, gates, and credential handling I use to do it without blowing up prod.
Read guide - · 8 min read
Structuring Terraform State and Remote Backends That Scale
State is the single most dangerous file in your Terraform estate. Here's how I structure backends, split state, and lock things down so a large org doesn't corrupt itself.
Read guide - · 8 min read
Surviving Terraform Provider Version Upgrades
Major provider upgrades break plans in subtle ways across a large estate. Here's how I roll them out incrementally with lock files, pins, and read-only validation.
Read guide - · 8 min read
Terraform for_each vs count: Choosing the Right One
Pick the wrong iteration construct and a single list change destroys and recreates half your resources. Here's when to use for_each, when count is fine, and why.
Read guide - · 9 min read
Testing Terraform: From Validate to Native Tests
Infrastructure code deserves tests too. Here's the layered approach I use — fmt, validate, policy checks, and native terraform test — to catch failures before apply.
Read guide - · 7 min read
The Right Way to Pair AI With Terraform Plans
Reviewing a 400-line Terraform plan output is tedious and error-prone. AI helps — but only if you give it the right format and ask the right question.
Read guide
Recommended tools
-
GitHub Copilot
by GitHub / Microsoft
4.5The lowest-friction AI completion in your existing editor.
- Best for
- Inline completion while writing YAML, Bash, Python, Terraform — plus agent mode for scoped multi-file changes
- Pricing
- Free tier (limited); Pro $10/mo; Business $19/seat/mo; Enterprise $39/seat/mo
Read review -
Amazon Q Developer
by Amazon Web Services
4.3AWS's AI assistant for building and operating on AWS — IaC, CLI, and resource Q&A grounded in your account.
- Best for
- Building & operating on AWS — CloudFormation/CDK/Terraform, CLI, and AWS resource troubleshooting
- Pricing
- Free tier (generous); Pro $19/user/mo
Read review