Terratest provides automated infrastructure testing for GistPin Terraform modules.
infrastructure/terraform/tests/
├── test_helper.go # Shared test utilities and helpers
├── vpc_test.go # VPC module tests
├── eks_test.go # EKS module tests
└── go.mod / go.sum # Go module dependencies
Tests follow Go conventions:
- Each file tests a single Terraform module
- Test functions are named
Test<ModuleName><Scenario> - All tests use
test_helper.gofor Terraform setup/teardown - Assertions use
testify/assert
Prerequisites:
- Go 1.22+
- Terraform 1.7.5+
- AWS credentials configured
# Run all tests
cd infrastructure/terraform/tests
go test -v -timeout 30m ./...
# Run a specific test
go test -v -timeout 30m -run TestVpcCreation ./...
# Run with shorter timeout for fast feedback
go test -v -timeout 10m -short ./...- Create a new
<module_name>_test.gofile in the tests directory - Import
test_helper.govia thetestpackage - Use
DefaultTerraformOptionsto point at your module - Wrap test setup with
ApplyAndDestroyWithCleanupfor automatic cleanup - Assert outputs using
terraform.Outputandtestify/assert
func TestMyModuleCreation(t *testing.T) {
opts := DefaultTerraformOptions(t, "../modules/my-module")
ApplyAndDestroyWithCleanup(t, opts)
output := terraform.Output(t, opts, "my_output")
assert.Equal(t, "expected", output)
}- Keep tests idempotent and independent
- Always use
ApplyAndDestroyWithCleanupfor cleanup - Test both happy path and edge cases (empty inputs, boundary values)
- Use
t.Parallel()for independent tests to speed up runs - Tag slow tests with
t.Skip("slow")for-shortmode - Validate resource attributes (counts, CIDRs, ARNs) not just existence
Tests run automatically via the terratest.yml GitHub Actions workflow on:
- Pull requests modifying
infrastructure/terraform/** - Pushes to
mainthat modifyinfrastructure/terraform/**
Results are posted as PR comments and artifacts are retained for 30 days.