0
0
Terraformcloud~10 mins

JSON configuration alternative 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 define a JSON variable in Terraform.

Terraform
variable "config" {
  type = [1]
}
Drag options to blanks, or click blank then click option'
Aany
Bstring
Cmap(string)
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'string' type instead of 'map(string)'
Using 'any' which is too broad for this case
2fill in blank
medium

Complete the code to parse a JSON string into a Terraform map.

Terraform
locals {
  config_map = jsondecode([1])
}
Drag options to blanks, or click blank then click option'
Avar.config
Bjson
Cconfig
D"var.config"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the variable name as a string with quotes
Passing an undefined variable
3fill in blank
hard

Fix the error in the JSON configuration by completing the code.

Terraform
resource "aws_s3_bucket" "example" {
  bucket = [1]
  acl    = "private"
}
Drag options to blanks, or click blank then click option'
Abucket_name
Bjsondecode(var.bucket_name)
C"var.bucket_name"
Dvar.bucket_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the variable name
Using jsondecode on a string variable
4fill in blank
hard

Fill both blanks to create a JSON object variable and assign a default value.

Terraform
variable "settings" {
  type    = [1]
  default = [2]
}
Drag options to blanks, or click blank then click option'
Amap(string)
Bobject({region=string, env=string})
C{"region" = "us-east-1", "env" = "dev"}
D{region = "us-east-1", env = "dev"}
Attempts:
3 left
💡 Hint
Common Mistakes
Using JSON string syntax for default value
Using map(string) type without specifying keys
5fill in blank
hard

Complete the code to decode a JSON string and access a nested value.

Terraform
locals {
  config = jsondecode([1])
  region = config["region"]
}
Drag options to blanks, or click blank then click option'
Avar.json_string
B[
C]
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation for map access
Passing JSON string as a literal with quotes