0
0
Terraformcloud~20 mins

Block syntax and structure in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Block Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Configuration
intermediate
2:00remaining
Identify the output of this Terraform resource block
Given the following Terraform resource block, what will be the value of the instance_type attribute after deployment?
Terraform
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"
  tags = {
    Name = "ExampleInstance"
  }
}
A"t2.micro"
B"ami-12345678"
C"ExampleInstance"
D"aws_instance.example"
Attempts:
2 left
💡 Hint
Look at the attribute assigned to instance_type inside the resource block.
Architecture
intermediate
2:00remaining
Determine the number of blocks in this Terraform configuration
How many top-level blocks are defined in the following Terraform configuration snippet?
Terraform
provider "aws" {
  region = "us-west-2"
}

resource "aws_s3_bucket" "bucket" {
  bucket = "my-bucket"
  acl    = "private"
}

variable "bucket_name" {
  type = string
}
A2
B3
C4
D1
Attempts:
2 left
💡 Hint
Count each block that starts at the left margin with a block type keyword.
security
advanced
2:00remaining
Identify the security risk in this Terraform block structure
Which option correctly identifies the security risk in the following Terraform block?
Terraform
resource "aws_security_group" "example" {
  name        = "example-sg"
  description = "Allow SSH"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
AThe security group name is not unique, causing deployment failure.
BMissing egress block will block all outbound traffic, causing connectivity issues.
CThe protocol value "tcp" is invalid and will cause a syntax error.
DIngress rule allows SSH from any IP address, which is a security risk.
Attempts:
2 left
💡 Hint
Consider what allowing SSH from everywhere means for security.
Best Practice
advanced
2:00remaining
Choose the correct block structure to define multiple tags in Terraform
Which option correctly defines multiple tags inside a resource block in Terraform?
A
tags = {
  Environment = "Production"
  Owner       = "TeamA"
}
B
tags = [
  "Environment=Production",
  "Owner=TeamA"
]
C
tags = {
  "Environment": "Production",
  "Owner": "TeamA"
}
Dtags = ("Environment" = "Production", "Owner" = "TeamA")
Attempts:
2 left
💡 Hint
Terraform uses maps for tags, not lists or tuples.
service_behavior
expert
2:00remaining
Predict the behavior of nested blocks in this Terraform configuration
What will be the effect of the nested lifecycle block inside this resource block?
Terraform
resource "aws_s3_bucket" "example" {
  bucket = "my-example-bucket"

  lifecycle {
    prevent_destroy = true
  }
}
ATerraform will throw a syntax error due to incorrect lifecycle block placement.
BTerraform will ignore the lifecycle block and destroy the bucket normally.
CTerraform will prevent the bucket from being destroyed unless the lifecycle block is removed.
DTerraform will automatically recreate the bucket if destroyed outside Terraform.
Attempts:
2 left
💡 Hint
Consider what the prevent_destroy setting does in Terraform lifecycle blocks.