0
0
Terraformcloud~10 mins

Data source dependencies 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 reference the AWS VPC data source.

Terraform
data "aws_vpc" "main" {
  id = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_vpc.main.id
Bvar.vpc_id
Cvpc-123456
Dlocal.vpc_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using the data source name instead of a variable.
Hardcoding the VPC ID directly in the code.
2fill in blank
medium

Complete the code to create a subnet using the VPC ID from the data source.

Terraform
resource "aws_subnet" "example" {
  vpc_id = [1]
  cidr_block = "10.0.1.0/24"
}
Drag options to blanks, or click blank then click option'
Alocal.vpc_id
Bvar.vpc_id
Caws_vpc.main.id
Ddata.aws_vpc.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable instead of the data source.
Referencing the resource instead of the data source.
3fill in blank
hard

Fix the error in the data source dependency to correctly get the subnet IDs.

Terraform
data "aws_subnet_ids" "selected" {
  vpc_id = [1]
}
Drag options to blanks, or click blank then click option'
Adata.aws_vpc.main.id
Bvar.vpc_id
Clocal.vpc_id
Daws_vpc.main.id
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the data. prefix.
Using a variable instead of the data source.
4fill in blank
hard

Fill both blanks to create a security group that depends on the VPC data source.

Terraform
resource "aws_security_group" "example" {
  name        = "example-sg"
  description = "Example security group"
  vpc_id      = [1]

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = [[2]]
  }
}
Drag options to blanks, or click blank then click option'
Adata.aws_vpc.main.id
B"0.0.0.0/0"
Cvar.vpc_id
D"10.0.0.0/16"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable instead of the data source for VPC ID.
Not quoting the CIDR block string.
5fill in blank
hard

Fill all three blanks to output the subnet IDs from the data source with a condition.

Terraform
output "public_subnet_ids" {
  value = [for id in [1] : id if [2](id, [3])]
}
Drag options to blanks, or click blank then click option'
Adata.aws_subnet_ids.selected.ids
Bstarts_with
C"subnet-"
Dvar.subnet_ids
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable instead of the data source for subnet IDs.
Incorrect syntax for the filter condition.