Back to Skills

terraform-testing

verified

Testing Terraform configurations with native tests, Terratest, and validation frameworks

View on GitHub

Marketplace

pluginagentmarketplace-terraform

pluginagentmarketplace/custom-plugin-terraform

Plugin

terraform-assistant

Repository

pluginagentmarketplace/custom-plugin-terraform
1stars

skills/terraform-testing/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-testing/SKILL.md -a claude-code --skill terraform-testing

Installation paths:

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

Instructions

# Terraform Testing Skill

Comprehensive testing patterns for Terraform modules and configurations.

## Native Terraform Test (1.6+)

### Basic Test
```hcl
# tests/vpc_test.tftest.hcl
run "vpc_creation" {
  command = plan

  variables {
    vpc_cidr    = "10.0.0.0/16"
    environment = "test"
  }

  assert {
    condition     = aws_vpc.main.cidr_block == "10.0.0.0/16"
    error_message = "VPC CIDR mismatch"
  }

  assert {
    condition     = aws_vpc.main.enable_dns_hostnames == true
    error_message = "DNS hostnames should be enabled"
  }
}
```

### Apply Test
```hcl
run "full_deployment" {
  command = apply

  variables {
    vpc_cidr    = "10.0.0.0/16"
    environment = "test"
  }

  assert {
    condition     = length(aws_subnet.private) == 3
    error_message = "Expected 3 private subnets"
  }
}

run "cleanup" {
  command = apply
  destroy = true
}
```

### Mock Providers
```hcl
mock_provider "aws" {
  mock_resource "aws_instance" {
    defaults = {
      id = "i-mock12345"
    }
  }
}

run "with_mocks" {
  providers = {
    aws = aws
  }

  assert {
    condition     = aws_instance.web.id != ""
    error_message = "Instance ID should be set"
  }
}
```

## Terratest (Go)

### Basic Module Test
```go
package test

import (
    "testing"
    "github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"
)

func TestVPCModule(t *testing.T) {
    t.Parallel()

    opts := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
        TerraformDir: "../modules/vpc",
        Vars: map[string]interface{}{
            "vpc_cidr":    "10.0.0.0/16",
            "environment": "test",
        },
    })

    defer terraform.Destroy(t, opts)
    terraform.InitAndApply(t, opts)

    vpcId := terraform.Output(t, opts, "vpc_id")
    assert.NotEmpty(t, vpcId)

    subnets := terraform.OutputList(t, opts, "private_subnet_ids")
    assert.Equal(t, 3, len(subnets))
}
```

### Validation Test
```go
func TestInvalidInput(t *testing.T) {
    t.Pa

Validation Details

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