0
0
Terraformcloud~10 mins

Terraform test framework (1.6+) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a basic Terraform test block.

Terraform
test "example" {
  [1] = "."
}
Drag options to blanks, or click blank then click option'
Asource
Bframework
Cprovider
Dmodule
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'framework' instead of 'source' causes an error.
Confusing 'provider' with 'source' attribute.
2fill in blank
medium

Complete 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'
Aactions
Bsteps
Csetup
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setup' instead of 'steps' will not run commands.
Using 'actions' or 'execute' are not valid block names.
3fill in blank
hard

Fix 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'
Aassertion
Basserts
Ccheck
Dassert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'assertion' or 'asserts' causes syntax errors.
Using 'check' is not recognized by Terraform test framework.
4fill in blank
hard

Fill 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'
Asetup
Bsteps
Cteardown
Dcleanup
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'steps' instead of 'setup' for initialization.
Using 'cleanup' instead of 'teardown' is invalid.
5fill in blank
hard

Fill 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'
Aname
Bid
Cexpected_value
Dmy_output
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'id' instead of the actual output name.
Not matching the message with the expected value.