Skip to content

terraform-test skill: incorrect examples and CLI guidance (plan-time unknowns, variable precedence, -filter, undefined cross-run output) #93

Description

@jrx

Found while vendoring the skill into a downstream repo and running an automated review over the vendored files. Four issues in terraform/code-generation/skills/terraform-test/:

1. Plan-mode example asserts an apply-time value (SKILL.md)

The basic test file example uses command = plan with:

assert {
  condition     = aws_instance.example.id != ""
  error_message = "Instance should have a valid ID"
}

id is provider-computed and unknown at plan time, so the condition cannot evaluate to a known boolean and the run fails instead of demonstrating a working pattern. The example should assert a plan-known attribute such as instance_type, or switch to command = apply.

2. Contradictory variable precedence comment (SKILL.md)

The test file structure example says:

# Optional: file-level variables (highest precedence, override all other sources)

but the same skill (and Terraform itself) documents run-level variables blocks as overriding file-level ones. File-level values are defaults for runs, not the highest-precedence source.

3. -filter comment is wrong (SKILL.md, Running Tests section)

terraform test -filter=test_vpc_configuration        # by run block name

-filter selects test files (e.g. -filter=tests/defaults.tftest.hcl), not run blocks. There is no flag to run a single run block.

4. Cross-run reference to an undefined output (references/EXAMPLES.md)

run "test_subnet_references_vpc_with_mocks" uses run.setup_vpc_with_mocks.vpc_id, but setup_vpc_with_mocks defines no vpc_id output, so the example cannot execute. Either add output "vpc_id" { value = aws_vpc.main.id } to the module under test and reference it, or drop the cross-run reference.

Happy to send a PR for any or all of these if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions