TE

Terraform Testing Defaults

Testing conventions for Terraform using native test framework and Terratest

Details

Language / Topic
terraformTerraform
Category
Testing

Rules

balanced
- Write native Terraform tests in `.tftest.hcl` files using `run` blocks with `command = plan` for fast unit checks and `command = apply` for integration tests.
- Use `assert` blocks inside `run` blocks to validate output values: `assert { condition = output.bucket_name != "" error_message = "bucket name must not be empty" }`.
- Always run `terraform test` against a dedicated test account or project — never run destructive integration tests against shared environments.
- Use `mock_provider` blocks in unit tests to avoid real cloud API calls and keep plan-only tests offline and fast.