0
0
Terraformcloud~10 mins

Integration testing strategies in Terraform - Interactive Code Practice

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

Complete the code to initialize Terraform before running tests.

Terraform
terraform [1]
Drag options to blanks, or click blank then click option'
Aapply
Binit
Cplan
Ddestroy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'terraform apply' before initialization causes errors.
Confusing 'plan' with 'init' command.
2fill in blank
medium

Complete the code to create a Terraform plan file for integration testing.

Terraform
terraform [1] -out=tfplan
Drag options to blanks, or click blank then click option'
Aplan
Bapply
Cdestroy
Dvalidate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'apply' instead of 'plan' when creating a plan file.
Forgetting to specify the output file with '-out'.
3fill in blank
hard

Fix the error in the command to apply a saved Terraform plan during integration testing.

Terraform
terraform [1] tfplan
Drag options to blanks, or click blank then click option'
Aplan
Bvalidate
Capply
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'terraform plan tfplan' instead of 'apply'.
Trying to initialize with 'init' when applying.
4fill in blank
hard

Fill both blanks to write a Terraform test block that checks if a resource attribute equals a value.

Terraform
test "resource_attribute" {
  check "state_check" {
    assert {
      condition = [1] == [2]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aresource.aws_instance.example.id
B"running"
C"stopped"
Dresource.aws_instance.example.state
Attempts:
3 left
💡 Hint
Common Mistakes
Using the instance ID instead of state for comparison.
Comparing to the wrong string value.
5fill in blank
hard

Fill all three blanks to create a Terraform output that shows the public IP of an instance after integration testing.

Terraform
output "instance_ip" {
  value = [1].[2].[3]
}
Drag options to blanks, or click blank then click option'
Aaws_instance
Bexample
Cpublic_ip
Dprivate_ip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'private_ip' instead of 'public_ip'.
Mixing resource names or types.