Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a basic Terraform test block.
Terraform
test "example" { [1] = "." }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'framework' instead of 'source' causes an error.
Confusing 'provider' with 'source' attribute.
✗ Incorrect
The source attribute specifies the location of the Terraform module or configuration to test.
2fill in blank
mediumComplete the code to run a Terraform plan in the test block.
Terraform
test "plan_test" { source = "./module" [1] { run = "terraform plan" } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setup' instead of 'steps' will not run commands.
Using 'actions' or 'execute' are not valid block names.
✗ Incorrect
The steps block defines commands to run during the test, like 'terraform plan'.
3fill in blank
hardFix the error in the test assertion syntax.
Terraform
test "assert_test" { source = "./module" steps { run = "terraform apply -auto-approve" } [1] { condition = "length(terraform_output.ids) > 0" } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'assertion' or 'asserts' causes syntax errors.
Using 'check' is not recognized by Terraform test framework.
✗ Incorrect
The correct block name for assertions is assert.
4fill in blank
hardFill both blanks to define a test with setup and teardown steps.
Terraform
test "full_test" { source = "./module" [1] { run = "terraform init" } [2] { run = "terraform destroy -auto-approve" } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'steps' instead of 'setup' for initialization.
Using 'cleanup' instead of 'teardown' is invalid.
✗ Incorrect
The setup block runs before tests, and teardown runs after to clean resources.
5fill in blank
hardFill all three blanks to assert output values correctly.
Terraform
test "output_assert" { source = "./module" steps { run = "terraform apply -auto-approve" } assert { condition = "terraform_output.[1] == '[2]'" message = "Output value should be [3]" } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'id' instead of the actual output name.
Not matching the message with the expected value.
✗ Incorrect
The output name is 'my_output'. The condition compares it to the expected value. The message repeats the expected value.