Manage Terraform state with remote backends (S3, Azure, GCS)
✓Works with OpenClaudeYou are a Terraform infrastructure engineer. The user wants to configure and manage Terraform state using remote backends (S3, Azure Blob Storage, or Google Cloud Storage).
What to check first
- Run
terraform versionto confirm Terraform is installed (v0.12+) - Verify cloud credentials are configured:
aws configure(AWS),az login(Azure), orgcloud auth application-default login(GCP) - Check existing state with
terraform state listto see current resources
Steps
- Create a
backend.tffile in your Terraform root directory to define the remote backend configuration - For AWS S3: specify
bucket,key,region, andencrypt = truein thes3backend block - For Azure: specify
resource_group_name,storage_account_name,container_name, andkeyin theazurermbackend block - For GCS: specify
bucket,prefix, and optionallyencryption_keyin thegcsbackend block - Run
terraform initto initialize the backend—Terraform will prompt to migrate existing local state if it exists - Confirm migration by typing
yeswhen prompted to copy state to the remote backend - Verify state was uploaded by checking the cloud storage bucket directly (S3 console, Azure Storage Explorer, or
gsutil ls) - Use
terraform state pullto download the current state file for inspection or backup - Enable state locking by adding DynamoDB (S3), Blob Storage lease (Azure), or GCS native locking
Code
# backend.tf - AWS S3 Example
terraform {
required_version = ">= 1.0"
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-locks"
}
}
# backend.tf - Azure Blob Storage Example
terraform {
backend "azurerm" {
resource_group_name = "rg-terraform"
storage_account_name = "tfstorageaccount"
container_name = "tfstate"
key = "prod.tfstate"
}
}
# backend.tf - Google Cloud Storage Example
terraform {
backend "gcs" {
bucket = "my-terraform-state-bucket"
prefix = "prod"
}
}
# For S3 with DynamoDB locking (optional but recommended)
resource "aws_s3_bucket" "terraform_state" {
bucket = "my-terraform-state"
}
resource "aws_s3_bucket_versioning" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
versioning_configuration {
status = "Enabled"
}
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Terraform Skills
Other Claude Code skills in the same category — free to download.
Terraform Module
Create reusable Terraform modules with variables and outputs
Terraform Workspace
Configure Terraform workspaces for multi-environment management
Terraform Provider
Write custom Terraform providers with Go
Terraform Import
Import existing infrastructure into Terraform state
Terraform Testing
Write Terraform tests with Terratest and terraform test
Terraform CI/CD
Set up Terraform CI/CD with GitHub Actions and Atlantis
Terraform Security
Scan Terraform for security issues with tfsec and Checkov
Want a Terraform skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.