0
0
Terraformcloud~10 mins

Arguments and expressions 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 assign the region argument in the provider block.

Terraform
provider "aws" {
  region = "[1]"
}
Drag options to blanks, or click blank then click option'
Aus-west-2
Btrue
C123
Dmy-region
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean or numeric values instead of a region string.
Using an invalid region name.
2fill in blank
medium

Complete the code to set the instance type argument for the AWS EC2 resource.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "[1]"
}
Drag options to blanks, or click blank then click option'
A123
Bt2.micro
Ctrue
Dmy-instance
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean or numeric values instead of a valid instance type string.
Using an invalid instance type.
3fill in blank
hard

Fix the error in the expression to correctly reference the variable 'environment'.

Terraform
variable "environment" {
  type = string
}

resource "aws_s3_bucket" "bucket" {
  bucket = "my-app-[1]"
  acl    = "private"
}
Drag options to blanks, or click blank then click option'
Aenvironment
Bvar.environment
C${environment}
D${var.environment}
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without interpolation syntax.
Using interpolation without the 'var.' prefix.
4fill in blank
hard

Fill both blanks to create a map variable with keys 'dev' and 'prod' and their respective CIDR blocks.

Terraform
variable "cidr_blocks" {
  type = map(string)
  default = {
    dev  = "[1]"
    prod = "[2]"
  }
}
Drag options to blanks, or click blank then click option'
A"10.0.1.0/24"
B"10.0.0.0/16"
C"10.0.2.0/24"
D"10.0.3.0/24"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same CIDR block for both environments.
Not using quotes around CIDR strings.
5fill in blank
hard

Fill all three blanks to create a resource with a tag key 'Name' and value from a variable, and enable versioning.

Terraform
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"

  tags = {
    Name = [1]
  }

  versioning {
    enabled = [2]
  }

  lifecycle_rule {
    id      = "log"
    enabled = [3]
  }
}
Drag options to blanks, or click blank then click option'
A"var.bucket_name"
Btrue
Cfalse
Dvar.bucket_name
Attempts:
3 left
💡 Hint
Common Mistakes
Putting variable references inside quotes, making them literal strings.
Using string 'true' instead of boolean true.