Back to Skills

terraform-state

verified

Master Terraform state management including remote backends, locking, workspaces, and state operations

View on GitHub

Marketplace

pluginagentmarketplace-terraform

pluginagentmarketplace/custom-plugin-terraform

Plugin

terraform-assistant

Repository

pluginagentmarketplace/custom-plugin-terraform
1stars

skills/terraform-state/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-terraform/blob/main/skills/terraform-state/SKILL.md -a claude-code --skill terraform-state

Installation paths:

Claude
.claude/skills/terraform-state/
Powered by add-skill CLI

Instructions

# 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

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
4269 chars