The Terraform Skill for Claude enables testing, module management, CI/CD integration, and production patterns for Terraform and OpenTofu. It benefits operations teams by automating infrastructure-as-code workflows, ensuring best practices, and streamlining deployments. The skill connects to Terraform and OpenTofu tools, enhancing CI/CD pipelines and production environments.
git clone https://github.com/antonbabenko/terraform-skill.githttps://docs.claude.ai/docs/agent-skills
[{"step":"Define your Terraform/OpenTofu context","action":"Specify the task (e.g., 'validate a module', 'set up CI/CD', 'debug a deployment issue') and provide relevant context like module paths, tool versions, or pipeline constraints.","tip":"Include specific file paths, variable names, or error messages you're encountering. The more precise your context, the better the output."},{"step":"Choose the appropriate workflow","action":"Select whether you need local validation, testing, CI/CD integration, or production deployment patterns. Mention any specific tools (e.g., Terratest, GitHub Actions, GitLab CI).","tip":"For CI/CD, specify your platform (GitHub, GitLab, Jenkins) and required stages (plan, test, apply). For testing, mention if you need unit, integration, or end-to-end tests."},{"step":"Execute the suggested commands","action":"Run the commands and code snippets provided in the output. For CI/CD, implement the suggested pipeline configuration in your repository.","tip":"Start with a test environment before applying changes to production. Use `-target` flags sparingly and document why they're necessary."},{"step":"Iterate based on feedback","action":"Review the output of each step (e.g., test failures, plan changes) and adjust your approach. Use the skill again to refine the solution.","tip":"For persistent issues, share the error messages or unexpected behavior with the skill to get targeted troubleshooting advice."},{"step":"Document and automate","action":"Update your documentation (e.g., README files, runbooks) with the validated patterns. Ensure your CI/CD pipeline includes all critical steps from the output.","tip":"Use the skill to generate documentation snippets or pipeline templates that can be reused across projects."}]
Generate a Terraform module with integrated testing for AWS resources.
Create a CI/CD workflow using GitHub Actions for Terraform deployments.
Review existing Terraform configurations to ensure compliance with best practices.
Implement security scanning in your Terraform pipeline using Trivy and Checkov.
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/antonbabenko/terraform-skillCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Act as a Terraform/OpenTofu expert and help me with [TASK]. Use the following context: [CONTEXT]. Provide a step-by-step plan with commands, code snippets, and best practices. If testing is needed, suggest test cases or validation steps. For CI/CD integration, outline the pipeline stages and required configurations. For module management, recommend structure and versioning strategies.
### Terraform Module Validation & CI/CD Integration Plan
**Context**: We need to validate a new `aws-network` module for our production VPC before merging it into the main branch. The module includes subnets, route tables, and security groups. Our CI/CD pipeline uses GitHub Actions and requires OpenTofu 1.7+.
**Step 1: Local Validation**
1. Initialize the module in a test directory:
```bash
mkdir -p /tmp/terraform-test && cd /tmp/terraform-test
tofu init -upgrade
```
2. Validate the module syntax:
```bash
tofu validate -json
```
3. Run a plan with strict mode enabled to catch potential issues:
```bash
tofu plan -out=tfplan -var-file=test.tfvars -var 'environment=staging' -strict
```
**Step 2: Unit Testing with Terratest**
Create a Go test file (`network_test.go`) to validate subnet CIDR ranges and route table associations:
```go
package test
import (
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
)
func TestNetworkModule(t *testing.T) {
t.Parallel()
opts := &terraform.Options{
TerraformDir: "../modules/aws-network",
Vars: map[string]interface{}{
"environment": "test",
},
}
defer terraform.Destroy(t, opts)
terraform.InitAndApply(t, opts)
// Validate subnet CIDRs
subnetCidrs := terraform.OutputList(t, opts, "subnet_cidrs")
assert.Equal(t, []string{"10.0.1.0/24", "10.0.2.0/24"}, subnetCidrs)
}
```
Run tests with:
```bash
go test -v -timeout 30m
```
**Step 3: CI/CD Pipeline Integration**
Add this GitHub Actions workflow (`.github/workflows/terraform.yml`):
```yaml
name: Terraform CI/CD
on:
pull_request:
paths:
- 'modules/aws-network/**'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: opentofu/setup-opentofu@v1
with:
tofu_version: "1.7.0"
- name: Validate
run: |
cd modules/aws-network
tofu init -upgrade
tofu validate
tofu plan -out=tfplan -var-file=test.tfvars -strict
- name: Test
run: |
cd modules/aws-network
go test -v -timeout 30m
deploy:
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: opentofu/setup-opentofu@v1
- name: Apply
run: |
cd modules/aws-network
tofu apply -auto-approve -var-file=prod.tfvars
env:
TF_VAR_aws_region: "us-west-2"
```
**Step 4: Production Deployment Checklist**
1. **Pre-deployment**:
- Verify `terraform.tfstate` backup exists
- Check drift detection with `tofu plan -detailed-exitcode`
- Review change summary from the plan output
2. **Post-deployment**:
- Run smoke tests against the new resources
- Update documentation in `README.md`
- Tag the release in Git with semantic versioning
**Best Practices Applied**:
- Used OpenTofu instead of Terraform for future-proofing
- Implemented strict mode validation to catch potential issues early
- Separated test and production variables
- Added parallel testing for faster feedback
- Included state backup and drift detection in the workflowDesign and sell products in minutes
Infrastructure as code for multi-cloud deployments
AI assistant built for thoughtful, nuanced conversation
IronCalc is a spreadsheet engine and ecosystem
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan