0
0
Terraformcloud~10 mins

Querying existing resources 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 query an existing AWS VPC by its ID.

Terraform
data "aws_vpc" "selected" {
  id = "[1]"
}
Drag options to blanks, or click blank then click option'
Avpc-123abc
Bvpc-xyz789
Csubnet-456def
Dinstance-001
Attempts:
3 left
💡 Hint
Common Mistakes
Using a subnet or instance ID instead of a VPC ID.
Leaving the ID blank or using an incorrect format.
2fill in blank
medium

Complete the code to query the AWS region where Terraform is running.

Terraform
data "aws_region" "current" {
  [1] = true
}
Drag options to blanks, or click blank then click option'
Adefault
Bname
Ccurrent
Denabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'default' instead of 'current'.
Setting the attribute to false or omitting it.
3fill in blank
hard

Fix the error in the code to query an existing AWS subnet by its filter.

Terraform
data "aws_subnet" "selected" {
  filter {
    name   = "[1]"
    values = ["my-subnet"]
  }
}
Drag options to blanks, or click blank then click option'
Asubnet-name
Btag:Name
Csubnet-id
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'subnet-name' which are not valid filter names.
Using 'subnet-id' which filters by ID, not tag.
4fill in blank
hard

Fill both blanks to query an existing AWS security group by its name and VPC ID.

Terraform
data "aws_security_group" "selected" {
  filter {
    name   = "[1]"
    values = ["my-security-group"]
  }
  filter {
    name   = "[2]"
    values = ["vpc-abc123"]
  }
}
Drag options to blanks, or click blank then click option'
Atag:Name
Bgroup-name
Cvpc-id
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tag:Name' or 'name' instead of 'group-name' for the name filter.
Using 'name' instead of 'vpc-id' for the VPC filter.
5fill in blank
hard

Fill all three blanks to query existing AWS EC2 instances filtered by tag, state, and availability zone.

Terraform
data "aws_instances" "selected" {
  filter {
    name   = "[1]"
    values = ["web-server"]
  }
  filter {
    name   = "[2]"
    values = ["running"]
  }
  filter {
    name   = "[3]"
    values = ["us-east-1a"]
  }
}
Drag options to blanks, or click blank then click option'
Atag:Name
Binstance-state-name
Cavailability-zone
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'state' instead of 'instance-state-name'.
Using 'Name' without 'tag:' prefix.
Using 'availability_zone' instead of 'availability-zone'.