A module computes resource names from several input variables. The maintainer wants a test in a .tftest.hcl file that checks the computed names without creating any real infrastructure. How should the run block be configured?
Select an answer to reveal the explanation.
Short Explanation
Think of command = plan as a dress rehearsal: Terraform works out every name your module would use, you check them with assert, and nothing real gets built. The default apply would actually create resources, so don't skip that one line.
Full Explanation
In the Terraform test framework, each run block executes a command against the module under test. The default is apply, which creates real infrastructure that the framework destroys at the end of the test file. Setting command to plan tells Terraform to create a plan only, so assertions run against planned values, which suits unit-style tests of naming logic, conditionals and custom conditions. Because name values derived from input variables are known at plan time, assertions can compare them directly with the expected strings. Relying on the default apply creates and then destroys real resources, which costs time and money and contradicts the requirement even though cleanup follows. The expect_failures argument declares checkable objects such as variable validations or custom conditions that are expected to fail; it is for negative tests and does not check successful name computation. Terraform validate checks syntax and internal consistency but evaluates no variable values and prints no planned names, so there is nothing to assert. Exam caveat: a plan still contacts the provider for configuration and data sources unless the provider is mocked, so pair plan-mode runs with mock providers when tests must run without credentials. Operational check: run terraform test and confirm the run passes with no resources recorded as created in the output.