0
0
Terraformcloud~10 mins

Module inputs (variables) 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 declare a variable named 'region' with a default value.

Terraform
variable "region" {
  type    = string
  default = "[1]"
}
Drag options to blanks, or click blank then click option'
Aus-west-2
B123
Ctrue
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean or number instead of a string for the default value.
Leaving the default value empty.
2fill in blank
medium

Complete the code to pass the variable 'region' to the module input.

Terraform
module "network" {
  source = "./modules/network"
  region = [1]
}
Drag options to blanks, or click blank then click option'
A"us-east-1"
Bmodule.region
Cregion
Dvar.region
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the variable name without 'var.' prefix.
Passing a string literal instead of the variable.
3fill in blank
hard

Fix the error in the variable declaration by completing the type definition.

Terraform
variable "instance_count" {
  type = [1]
  default = 3
}
Drag options to blanks, or click blank then click option'
Anumber
Bbool
Clist
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' type for a numeric default value.
Using 'bool' or 'list' which do not match the default.
4fill in blank
hard

Fill both blanks to declare a variable 'tags' as a map of strings with a default.

Terraform
variable "tags" {
  type    = map[1]string[2]
  default = {
    Environment = "dev"
  }
}
Drag options to blanks, or click blank then click option'
A(
B[
C)
D]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of parentheses.
Omitting one of the brackets.
5fill in blank
hard

Fill all three blanks to pass variables 'region', 'instance_count', and 'tags' to the module.

Terraform
module "app" {
  source         = "./modules/app"
  region         = [1]
  instance_count = [2]
  tags           = [3]
}
Drag options to blanks, or click blank then click option'
Avar.region
Bvar.instance_count
Cvar.tags
Dmodule.region
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'module.' prefix instead of 'var.'.
Passing variable names without 'var.' prefix.