0
0
Terraformcloud~20 mins

Querying existing resources in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Data Source Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Terraform data source output
You use a Terraform data source to query an existing AWS VPC by its ID. What will be the value of data.aws_vpc.selected_vpc.cidr_block after applying this configuration?
Terraform
data "aws_vpc" "selected_vpc" {
  id = "vpc-0abc123def456ghij"
}

output "vpc_cidr" {
  value = data.aws_vpc.selected_vpc.cidr_block
}
A"vpc-0abc123def456ghij"
B"10.0.0.0/16"
Cnull
DSyntaxError
Attempts:
2 left
💡 Hint
The data source fetches existing resource attributes, including the CIDR block.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Terraform data sources
What is the main purpose of using a Terraform data source when working with existing cloud resources?
ATo query and reference existing cloud resources without creating them
BTo create new cloud resources with predefined settings
CTo delete existing cloud resources safely
DTo automatically update resource configurations
Attempts:
2 left
💡 Hint
Think about how Terraform can use information about resources it did not create.
Configuration
advanced
2:30remaining
Correctly querying an existing AWS subnet by tag
Which Terraform configuration correctly queries an existing AWS subnet with the tag Environment=Production and outputs its subnet ID?
A
data "aws_subnet_ids" "prod_subnets" {
  filter {
    name   = "tag:Environment"
    values = ["Production"]
  }
}

output "subnet_id" {
  value = data.aws_subnet_ids.prod_subnets.ids[0]
}
B
data "aws_subnet_ids" "prod_subnets" {
  tags = {
    Environment = "Production"
  }
}

output "subnet_id" {
  value = data.aws_subnet_ids.prod_subnets.ids[0]
}
C
data "aws_subnet" "prod_subnet" {
  tags = {
    Environment = "Production"
  }
}

output "subnet_id" {
  value = data.aws_subnet.prod_subnet.id
}
D
data "aws_subnet" "prod_subnet" {
  filter {
    name   = "tag:Environment"
    values = ["Production"]
  }
}

output "subnet_id" {
  value = data.aws_subnet.prod_subnet.id
}
Attempts:
2 left
💡 Hint
Use the correct data source type and filter syntax for multiple subnets.
security
advanced
2:00remaining
Security implications of querying existing resources
When using Terraform data sources to query existing cloud resources, what is a key security consideration?
AData sources automatically grant Terraform full access to modify the queried resources
BData sources expose sensitive resource credentials in the Terraform state by default
CTerraform must have appropriate read permissions to access the existing resources' metadata
DUsing data sources disables encryption for the queried resources
Attempts:
2 left
💡 Hint
Think about what permissions Terraform needs to read existing resource information.
Architecture
expert
3:00remaining
Designing Terraform to query multi-cloud existing resources
You need to write a Terraform configuration that queries existing virtual networks from both AWS and Azure in the same deployment. Which approach correctly supports querying both cloud providers' existing networks?
AUse the <code>terraform_remote_state</code> data source to import network IDs from AWS and Azure
BUse a single <code>aws_vpc</code> data source with filters for both AWS and Azure network IDs
CUse the <code>null_resource</code> to run scripts that query networks from both clouds
DUse separate provider blocks for AWS and Azure, then use respective data sources <code>aws_vpc</code> and <code>azurerm_virtual_network</code> to query existing networks
Attempts:
2 left
💡 Hint
Terraform supports multiple providers in one configuration.