0
0
Terraformcloud~10 mins

Why variables make configurations reusable 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 declare a variable for the AWS region.

Terraform
variable "region" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Anumber
Bstring
Cbool
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using number or bool as the variable type for region.
2fill in blank
medium

Complete the code to assign a default value to the variable.

Terraform
variable "instance_type" {
  type    = string
  default = [1]
}
Drag options to blanks, or click blank then click option'
A"t2.micro"
Bt2.micro
Ct2_micro
Dmicro
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the default string value.
3fill in blank
hard

Fix the error in referencing the variable in the resource block.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = [1]
}
Drag options to blanks, or click blank then click option'
Avariable.instance_type
Binstance_type
Cvar.instance_type
Dvar[instance_type]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without var. prefix.
Using incorrect syntax like variable.instance_type.
4fill in blank
hard

Fill both blanks to define a variable with a description and a default value.

Terraform
variable "environment" {
  description = [1]
  default     = [2]
}
Drag options to blanks, or click blank then click option'
A"The deployment environment"
Bproduction
C"production"
D"Deployment environment"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes for description or default value.
Using unquoted default values.
5fill in blank
hard

Fill all three blanks to use variables for region, instance type, and count in the resource.

Terraform
resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = [1]
  count         = [2]
  availability_zone = [3]
}
Drag options to blanks, or click blank then click option'
Avar.instance_type
Bvar.count
Cvar.region
Dvar.availability_zone
Attempts:
3 left
💡 Hint
Common Mistakes
Using var.region for availability zone.
Not using var. prefix.