0
0
Terraformcloud~20 mins

Resource block syntax in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Resource Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Configuration
intermediate
2:00remaining
Identify the correct resource block syntax for creating an AWS S3 bucket
Which resource block correctly defines an AWS S3 bucket named "my_bucket" with versioning enabled?
A
resource "aws_s3_bucket" "my_bucket" {
  bucket = "my_bucket"
  versioning = true
}
B
resource aws_s3_bucket my_bucket {
  bucket = "my_bucket"
  versioning = true
}
C
resource "aws_s3_bucket" "my_bucket" {
  name = "my_bucket"
  versioning = {
    enabled = true
  }
}
D
resource "aws_s3_bucket" "my_bucket" {
  bucket = "my_bucket"
  versioning {
    enabled = true
  }
}
Attempts:
2 left
💡 Hint
Remember that nested blocks like versioning require a block syntax, not just an attribute assignment.
service_behavior
intermediate
2:00remaining
Effect of missing required attribute in resource block
What happens if you define an AWS EC2 instance resource block without specifying the required attribute "ami"?
Terraform
resource "aws_instance" "example" {
  instance_type = "t2.micro"
}
ATerraform will ignore the missing attribute and create the instance with instance_type only.
BTerraform will create the instance with a default AMI automatically.
CTerraform plan will fail with an error about missing required attribute "ami".
DTerraform will create the instance but it will be stopped by default.
Attempts:
2 left
💡 Hint
Think about how Terraform validates resource blocks before applying.
Architecture
advanced
2:00remaining
Correct resource block to create a VPC with CIDR block and enable DNS support
Which resource block correctly creates an AWS VPC with CIDR block "10.0.0.0/16" and enables DNS support?
A
resource "aws_vpc" "main" {
  cidr = "10.0.0.0/16"
  enable_dns = true
}
B
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
  enable_dns_support = true
}
C
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
  dns_support = true
}
D
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
  enable_dns_hostnames = true
}
Attempts:
2 left
💡 Hint
Check the exact attribute names required by the AWS VPC resource.
security
advanced
2:00remaining
Resource block to create a security group allowing inbound HTTP traffic
Which resource block correctly creates an AWS security group allowing inbound HTTP (port 80) traffic from anywhere?
A
resource "aws_security_group" "web_sg" {
  name = "web_sg"
  ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
B
resource "aws_security_group" "web_sg" {
  name = "web_sg"
  ingress = [{
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }]
}
C
resource "aws_security_group" "web_sg" {
  name = "web_sg"
  ingress {
    port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
D
resource "aws_security_group" "web_sg" {
  name = "web_sg"
  ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_block = "0.0.0.0/0"
  }
}
Attempts:
2 left
💡 Hint
Remember the correct attribute names and types for ingress rules.
Best Practice
expert
2:00remaining
Correct way to reference another resource's attribute in a resource block
Given a resource "aws_vpc" "main" with attribute "id", which resource block correctly references this VPC ID when creating a subnet?
Terraform
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "subnet1" {
  vpc_id = ???
  cidr_block = "10.0.1.0/24"
}
Avpc_id = aws_vpc.main.id
Bvpc_id = "aws_vpc.main.id"
Cvpc_id = ${aws_vpc.main.id}
Dvpc_id = $aws_vpc.main.id
Attempts:
2 left
💡 Hint
Terraform 0.12+ allows direct references without interpolation syntax.