debug:terraform
Debug Terraform infrastructure-as-code issues systematically. This skill helps diagnose and resolve Terraform-specific problems including state lock conflicts, provider authentication failures, resource dependency cycles, state drift detection, import failures, module version conflicts, and plan/apply errors. Provides TF_LOG debugging, terraform console usage, state manipulation commands, and CI/CD best practices for infrastructure automation.
What this skill does
# Terraform Debugging Guide
Debug Terraform configurations and state issues using a systematic four-phase approach with provider-specific considerations.
## Error Classification
Terraform errors fall into four categories:
1. **Language Errors** - Syntax and configuration issues
2. **State Errors** - State file corruption, drift, or lock issues
3. **Core Errors** - Terraform engine problems
4. **Provider Errors** - Cloud provider authentication or API issues
## Phase 1: Reproduce and Isolate
### Gather Initial Information
```bash
# Check Terraform and provider versions
terraform version
# Validate configuration syntax
terraform validate
# Review current state
terraform state list
terraform state show <resource_address>
# Check for state drift
terraform plan -refresh-only
```
### Enable Debug Logging
```bash
# Set log level (TRACE, DEBUG, INFO, WARN, ERROR)
export TF_LOG=DEBUG
# Write logs to file (recommended for large outputs)
export TF_LOG_PATH="./terraform-debug.log"
# For provider-specific debugging
export TF_LOG_PROVIDER=DEBUG
# Run command with logging
terraform plan
```
**Log Levels:**
- `TRACE` - Maximum verbosity, every action logged
- `DEBUG` - Detailed debugging for complex issues
- `INFO` - General informative messages
- `WARN` - Non-critical warnings
- `ERROR` - Critical errors only
### Isolate the Problem
```bash
# Target specific resource
terraform plan -target=aws_instance.example
# Check specific module
terraform plan -target=module.networking
# Validate single file
terraform validate -json
```
## Phase 2: Analyze Root Cause
### Common Error Patterns and Solutions
#### State Lock Errors
```
Error: Error acquiring the state lock
```
**Diagnosis:**
```bash
# Check if another process is running
ps aux | grep terraform
# View lock info (for S3 backend)
aws dynamodb get-item --table-name terraform-locks --key '{"LockID":{"S":"your-state-path"}}'
```
**Solution:**
```bash
# Force unlock (use with caution!)
terraform force-unlock <LOCK_ID>
# For S3/DynamoDB backend
aws dynamodb delete-item --table-name terraform-locks --key '{"LockID":{"S":"your-state-path"}}'
```
#### Provider Authentication Failures
```
Error: error configuring Terraform AWS Provider: no valid credential sources found
```
**Diagnosis:**
```bash
# Check AWS credentials
aws sts get-caller-identity
# Verify environment variables
env | grep AWS
# Check credential file
cat ~/.aws/credentials
```
**Solution:**
```hcl
# Explicit provider configuration
provider "aws" {
region = "us-east-1"
profile = "my-profile"
# Or use assume_role
assume_role {
role_arn = "arn:aws:iam::123456789012:role/TerraformRole"
}
}
```
#### Resource Dependency Cycles
```
Error: Cycle: aws_security_group.a, aws_security_group.b
```
**Diagnosis:**
```bash
# Generate dependency graph
terraform graph | dot -Tpng > graph.png
# Or view in text format
terraform graph
```
**Solution:**
```hcl
# Break cycle with explicit dependencies
resource "aws_security_group" "a" {
name = "sg-a"
# Remove circular reference
}
resource "aws_security_group_rule" "a_to_b" {
security_group_id = aws_security_group.a.id
source_security_group_id = aws_security_group.b.id
# ...
}
```
#### State Drift
```
Note: Objects have changed outside of Terraform
```
**Diagnosis:**
```bash
# Detect drift
terraform plan -refresh-only
# Show current state
terraform show
# Pull remote state for inspection
terraform state pull > state.json
```
**Solution:**
```bash
# Accept external changes into state
terraform apply -refresh-only
# Or reimport drifted resource
terraform import aws_instance.example i-1234567890abcdef0
# Or replace resource to match config
terraform apply -replace=aws_instance.example
```
#### Import Failures
```
Error: Cannot import non-existent remote object
```
**Diagnosis:**
```bash
# Verify resource exists
aws ec2 describe-instances --instance-ids i-1234567890abcdef0
# Check import syntax for resource type
terraform providers schema -json | jq '.provider_schemas["registry.terraform.io/hashicorp/aws"].resource_schemas["aws_instance"]'
```
**Solution:**
```bash
# Correct import command
terraform import aws_instance.example i-1234567890abcdef0
# For modules
terraform import module.ec2.aws_instance.example i-1234567890abcdef0
# Generate import blocks (Terraform 1.5+)
terraform plan -generate-config-out=generated.tf
```
#### Module Version Conflicts
```
Error: Module version requirements have changed
```
**Diagnosis:**
```bash
# Check current module versions
terraform providers lock -platform=linux_amd64
# View dependency tree
cat .terraform.lock.hcl
```
**Solution:**
```bash
# Upgrade modules
terraform init -upgrade
# Clear cache and reinitialize
rm -rf .terraform
terraform init
# Pin specific version
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
}
```
#### Resource Already Exists
```
Error: Error creating S3 bucket: BucketAlreadyExists
```
**Solution:**
```bash
# Import existing resource
terraform import aws_s3_bucket.example my-bucket-name
# Or use data source to reference
data "aws_s3_bucket" "existing" {
bucket = "my-bucket-name"
}
```
## Phase 3: Fix and Verify
### Interactive Debugging
```bash
# Open Terraform console for expression testing
terraform console
# Test expressions
> var.instance_type
> aws_instance.example.id
> length(var.subnets)
> jsonencode(local.tags)
```
### State Manipulation (Use with Caution)
```bash
# Remove resource from state (doesn't destroy)
terraform state rm aws_instance.orphaned
# Move resource in state
terraform state mv aws_instance.old aws_instance.new
# Move to different state file
terraform state mv -state-out=other.tfstate aws_instance.example aws_instance.example
# Replace provider in state
terraform state replace-provider hashicorp/aws registry.terraform.io/hashicorp/aws
```
### Safe Apply Strategies
```bash
# Preview changes
terraform plan -out=tfplan
# Apply with plan file (recommended)
terraform apply tfplan
# Apply specific resource only
terraform apply -target=aws_instance.example
# Destroy and recreate
terraform apply -replace=aws_instance.problematic
```
## Phase 4: Document and Prevent
### Pre-Commit Validation
```bash
# Validate syntax
terraform validate
# Format check
terraform fmt -check -recursive
# Use tflint for best practices
tflint --init
tflint
# Security scanning with checkov
checkov -d .
# Cost estimation
infracost breakdown --path=.
```
### CI/CD Best Practices
```bash
# CI-friendly commands
terraform init -input=false
terraform plan -input=false -no-color -out=tfplan
terraform apply -input=false -no-color tfplan
# Lock provider versions
terraform providers lock -platform=linux_amd64 -platform=darwin_amd64
```
### Configuration Best Practices
```hcl
# Pin Terraform version
terraform {
required_version = ">= 1.5.0, < 2.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
# Use variables with validation
variable "environment" {
type = string
validation {
condition = contains(["dev", "staging", "prod"], var.environment)
error_message = "Environment must be dev, staging, or prod."
}
}
# Add lifecycle rules for critical resources
resource "aws_instance" "critical" {
# ...
lifecycle {
prevent_destroy = true
create_before_destroy = true
}
}
```
## Quick Reference Commands
| Command | Purpose |
|---------|---------|
| `terraform validate` | Check syntax and configuration |
| `terraform plan` | Preview changes |
| `terraform plan -refresh-only` | Detect state drift |
| `terraform state list` | List all resources in state |
| `terraform state show <addr>` | Show resource details |
| `terraform state pull` | Download remote state |
| `terraform state rm <addr>` | Remove from state |
| `terraform import <addr> <id>` | Import existing resource |
| `terraform force-unlock <id>` | Release state lock |
| `terraform console` | InteractRelated in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.