Terraform workspace management for multi-environment deployments
Manages Terraform workspaces for multi-environment deployments. Use when you need to create, switch, or delete workspaces, or configure environment-specific resources using `terraform.workspace` references.
/plugin marketplace add pluginagentmarketplace/custom-plugin-terraform/plugin install terraform-assistant@pluginagentmarketplace-terraformThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonassets/workspace-commands.yamlreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyManage multiple environments with Terraform workspaces.
# List workspaces
terraform workspace list
# Create workspace
terraform workspace new dev
terraform workspace new staging
terraform workspace new prod
# Switch workspace
terraform workspace select prod
# Show current
terraform workspace show
# Delete workspace
terraform workspace delete dev
locals {
env_config = {
dev = {
instance_type = "t3.micro"
min_size = 1
max_size = 2
}
staging = {
instance_type = "t3.small"
min_size = 2
max_size = 4
}
prod = {
instance_type = "t3.medium"
min_size = 3
max_size = 10
}
}
config = local.env_config[terraform.workspace]
}
resource "aws_autoscaling_group" "app" {
min_size = local.config.min_size
max_size = local.config.max_size
# ...
}
locals {
name_prefix = "${var.project}-${terraform.workspace}"
}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
tags = {
Name = "${local.name_prefix}-vpc"
Environment = terraform.workspace
}
}
resource "aws_cloudwatch_alarm" "cpu" {
count = terraform.workspace == "prod" ? 1 : 0
alarm_name = "${local.name_prefix}-cpu-alarm"
# ...
}
resource "aws_db_instance" "main" {
multi_az = terraform.workspace == "prod"
deletion_protection = terraform.workspace == "prod"
# ...
}
terraform {
backend "s3" {
bucket = "company-terraform-state"
key = "app/terraform.tfstate"
region = "us-east-1"
workspace_key_prefix = "workspaces"
dynamodb_table = "terraform-locks"
}
}
# State paths:
# - workspaces/dev/app/terraform.tfstate
# - workspaces/prod/app/terraform.tfstate
infrastructure/
├── modules/
│ └── app/
├── environments/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── backend.tf
│ │ └── terraform.tfvars
│ ├── staging/
│ │ └── ...
│ └── prod/
│ └── ...
# environments/prod/main.tf
module "app" {
source = "../../modules/app"
environment = "prod"
instance_type = "t3.medium"
min_size = 3
}
| Approach | Use Case | Pros | Cons |
|---|---|---|---|
| Workspaces | Simple environments | Single codebase | Same config |
| Directories | Complex differences | Full customization | Code duplication |
| Hybrid | Mixed needs | Flexible | More complexity |
| Error | Cause | Solution |
|---|---|---|
Workspace not found | Not created | terraform workspace new |
State mismatch | Wrong workspace | Check terraform workspace show |
Cannot delete | Has resources | Destroy first or use -force |
Skill("terraform-workspace")
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.