Master Terraform state management including remote backends, locking, workspaces, and state operations
View on GitHubpluginagentmarketplace/custom-plugin-terraform
terraform-assistant
January 20, 2026
Select agents to install to:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-terraform/blob/main/skills/terraform-state/SKILL.md -a claude-code --skill terraform-stateInstallation paths:
.claude/skills/terraform-state/# Terraform State Skill
Comprehensive guide to state management, remote backends, and state manipulation operations.
## Backend Configuration
### AWS S3 Backend
```hcl
terraform {
backend "s3" {
bucket = "company-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "terraform-locks"
# Cross-account access
role_arn = "arn:aws:iam::ACCOUNT:role/TerraformAccess"
}
}
```
### Azure Storage Backend
```hcl
terraform {
backend "azurerm" {
resource_group_name = "terraform-state-rg"
storage_account_name = "tfstatecompany"
container_name = "tfstate"
key = "prod.terraform.tfstate"
use_azuread_auth = true
}
}
```
### GCP Cloud Storage Backend
```hcl
terraform {
backend "gcs" {
bucket = "company-terraform-state"
prefix = "terraform/state"
}
}
```
### Terraform Cloud
```hcl
terraform {
cloud {
organization = "my-org"
workspaces {
tags = ["app:my-app", "env:prod"]
}
}
}
```
## State Locking
### DynamoDB Lock Table
```hcl
resource "aws_dynamodb_table" "terraform_locks" {
name = "terraform-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
tags = {
Purpose = "Terraform state locking"
}
}
```
## Workspace Strategies
### Directory-Based (Recommended)
```
infrastructure/
├── environments/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── backend.tf
│ │ └── terraform.tfvars
│ ├── staging/
│ └── prod/
└── modules/
```
### CLI Workspaces
```bash
# Create and switch
terraform workspace new prod
terraform workspace select prod
terraform workspace list
# Use in config
locals {
env_config = {
dev = { instance_type = "t3.micro" }
prod = { instance_type = "t3.large" }
}
config = local.env_config[terraform.workspace]
}
```
## State Operations
### Import Resources
```bash
# Basic