Skip to main content

Terraform State Management Strategy

Design a Terraform state management strategy with remote backends, state locking, workspace isolation, and state migration procedures.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Design a Terraform state management strategy for mid-size startup with 4 product teams with 4 teams managing 500+ resources across 3 (dev, staging, production) environments on AWS. Plan: 1) Remote backend configuration using S3 with DynamoDB locking — configure encryption at rest, versioning for state history, and DynamoDB/equivalent for state locking. Provide the backend.tf configuration with variable interpolation for environment separation. 2) State isolation strategy: separate state per environment per service — separate state files per service + environment combination (e.g., api-production, api-staging, networking-production) to limit blast radius. Explain the trade-offs of large monolithic state vs many small states. 3) State file organization: directory structure with terragrunt-style with environment/region/service hierarchy, showing how modules reference other states using terraform_remote_state data sources for application state reads VPC outputs from networking state, database state reads subnet IDs. 4) State locking and concurrency: configure GitHub Actions with Atlantis for PR-based workflow to handle concurrent applies with proper locking, queuing, and timeout settings. 5) Sensitive data in state: identify RDS passwords, IAM access keys, TLS certificates that store secrets in state, and implement use AWS Secrets Manager with data sources instead of storing in Terraform, encrypt state at rest to protect them. 6) State migration procedures: document how to move resources between state files using terraform state mv, import existing resources with terraform import, and remove abandoned resources with terraform state rm. Include rollback procedures. 7) Disaster recovery: state backup to versioned S3 bucket with cross-region replication, recovery procedure from corrupted state, and a break-glass process for state lock override.

What this prompt does

This prompt designs a Terraform state management strategy for a [organization_type] with [team_count] teams managing [resource_count] resources across [environment_count] environments on [cloud_provider]. It configures a remote backend ([backend_type]) with encryption at rest, state versioning for history, and locking, and provides a backend.tf with variable interpolation for environment separation.

It then plans state isolation via [isolation_approach], splitting state per [state_boundary] to limit blast radius, and explains the trade-off between one large monolithic state and many small ones. It covers state file organization with [structure_approach] and cross-state references for [cross_state_references] using terraform_remote_state data sources, concurrency handling in [ci_tool] with locking and queuing, protection of [sensitive_resources] using [mitigation_strategy], migration procedures (terraform state mv, import, rm) with rollback, and disaster recovery that backs state up to [backup_destination] with a documented break-glass lock-override process. State is where Terraform setups quietly go wrong, so the plan treats remote backends, isolation, and locking as non-negotiable from day one.

When to use it

  • You're standing up Terraform for multiple teams and want safe state boundaries from day one
  • You need a remote backend with locking before concurrent applies cause corruption
  • You want to limit blast radius by splitting state per service and environment
  • You need cross-state references so app state can read networking outputs
  • You're concerned about secrets landing in state files
  • You need documented migration and disaster-recovery procedures
  • You're moving resources between states and want a tested, reversible procedure first
  • You want a break-glass process defined before an incident, not improvised during one

Example output

The AI returns a backend.tf configuration, a written discussion of monolithic versus split state, a directory structure following [structure_approach], terraform_remote_state data-source examples for [cross_state_references], CI locking config for [ci_tool], a sensitive-data mitigation section for [sensitive_resources], step-by-step migration commands with rollback notes, and a disaster-recovery runbook. Expect prose plus code blocks per numbered concern so the reasoning behind each boundary is explicit.

Pro tips

  • Choose [state_boundary] by service plus environment so a bad apply to one service can't damage another
  • Enable versioning on the backend so you can recover a previous state if an apply goes wrong
  • Prefer reading secrets from a secrets manager via data sources ([mitigation_strategy]) over storing them in state
  • Document the exact terraform state mv/import/rm steps with rollback before you need them under pressure
  • Configure [ci_tool] locking and queuing so two pipelines never apply the same state at once
  • Restrict who can override a lock, since the break-glass path bypasses the protection locking provides
  • Wire cross-state reads for [cross_state_references] through terraform_remote_state so a service consumes networking outputs without duplicating them
  • Replicate the [backup_destination] cross-region so a regional outage doesn't take your state with it

Frequently Asked Questions

What backend does this prompt configure for remote state?
It uses `[backend_type]`, defaulting to S3 with DynamoDB for state locking. The configuration includes encryption at rest and versioning for state history, and the backend.tf uses variable interpolation to separate state per environment.
How does splitting state limit blast radius?
By isolating state per `[state_boundary]`, typically a service-and-environment combination, a mistaken apply or corrupted state affects only that slice. The prompt also explains the trade-off: many small states reduce blast radius but add cross-state reference and coordination overhead versus one monolithic state.
How are secrets kept out of the state file?
Terraform stores resource attributes, including some secrets, in state. The prompt's `[mitigation_strategy]` favors reading values from a secrets manager via data sources instead of storing them directly, alongside encrypting state at rest, so sensitive material in `[sensitive_resources]` is minimized.
Does it cover recovering from corrupted state?
Yes. It includes disaster-recovery procedures: backing up state to `[backup_destination]` with cross-region replication, a recovery procedure from corrupted state, and a break-glass process for overriding a stuck state lock. Practice these before an incident, since lock overrides are risky if applied carelessly.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Terraform & Infrastructure as Code Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support