0
0
Terraformcloud~10 mins

Why expressions add logic in Terraform - Test Your Understanding

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

Complete the code to use a conditional expression that sets the instance type to 't2.micro' if the environment is 'dev'.

Terraform
instance_type = var.environment == "dev" ? [1] : "t2.large"
Drag options to blanks, or click blank then click option'
A"t2.large"
B"t2.micro"
C"m5.large"
D"c5.xlarge"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong instance type for the 'dev' environment.
Swapping the true and false parts of the conditional expression.
2fill in blank
medium

Complete the code to set the number of instances to 3 if the region is 'us-east-1', otherwise 1.

Terraform
count = var.region == "us-east-1" ? [1] : 1
Drag options to blanks, or click blank then click option'
A3
B1
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 3 for the 'us-east-1' region.
Confusing the true and false values.
3fill in blank
hard

Fix the error in the expression that sets 'enable_monitoring' to true only if 'environment' is 'prod'.

Terraform
enable_monitoring = var.environment [1] "prod" ? true : false
Drag options to blanks, or click blank then click option'
A!=
B=
C=>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Using '=>' which is not valid in this context.
4fill in blank
hard

Complete the code to create a conditional expression that sets 'storage_type' to 'gp2' if 'use_ssd' is true, otherwise 'standard'.

Terraform
storage_type = var.use_ssd [1] "gp2" : "standard"
Drag options to blanks, or click blank then click option'
A?
B:
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' or '!=' instead of '?' and ':'.
Swapping the positions of '?' and ':'.
5fill in blank
hard

Fill all three blanks to create a conditional expression that sets 'backup_enabled' to true if 'environment' is 'prod' and 'backup_window' is not empty, otherwise false.

Terraform
backup_enabled = var.environment [1] "prod" [2] var.backup_window [3] "" ? true : false
Drag options to blanks, or click blank then click option'
A==
B!=
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' instead of '&&' which changes the logic.
Mixing up '==' and '!=' operators.