0
0
Terraformcloud~20 mins

Availability zones data source in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Availability Zones Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
What is the output of this Terraform code snippet?

This Terraform code uses the AWS availability zones data source. What will be the value of length(data.aws_availability_zones.available.names) after applying?

Terraform
data "aws_availability_zones" "available" {
  state = "available"
}

output "az_count" {
  value = length(data.aws_availability_zones.available.names)
}
AAn error, because the data source requires a region argument
BAlways 3, because AWS has 3 availability zones per region
CZero, because the data source does not fetch any zones without explicit filters
DThe number of availability zones in the AWS region configured in the provider
Attempts:
2 left
💡 Hint

Think about what the state = "available" filter does and how Terraform queries AWS regions.

Configuration
intermediate
2:00remaining
Which option correctly filters availability zones by name prefix?

You want to get only availability zones starting with us-west-2a using the AWS availability zones data source in Terraform. Which option correctly applies this filter?

A
data "aws_availability_zones" "filtered" {
  filter {
    name   = "zone-name"
    values = ["us-west-2a*"]
  }
}
B
data "aws_availability_zones" "filtered" {
  filter {
    name   = "zone-name"
    values = ["us-west-2a"]
  }
}
C
data "aws_availability_zones" "filtered" {
  names = ["us-west-2a"]
}
D
data "aws_availability_zones" "filtered" {
  state = "available"
  names = ["us-west-2a*"]
}
Attempts:
2 left
💡 Hint

Remember that the filter values must match exact names, wildcards are not supported.

Architecture
advanced
2:00remaining
How does using the availability zones data source improve multi-AZ architecture design?

Why is it beneficial to use the AWS availability zones data source in Terraform when designing a multi-AZ architecture?

AIt dynamically fetches the current available zones, ensuring resources are deployed only in active zones, improving fault tolerance.
BIt hardcodes the zones to avoid accidental deployment in new zones, reducing complexity.
CIt disables zone awareness to simplify networking configurations.
DIt automatically balances traffic across zones without additional configuration.
Attempts:
2 left
💡 Hint

Think about how availability zones can change over time and how Terraform can adapt.

security
advanced
2:00remaining
What security consideration is important when using availability zones data source in Terraform?

When using the AWS availability zones data source in Terraform, which security consideration is most relevant?

AEnsure the IAM role or user running Terraform has permission to call <code>ec2:DescribeAvailabilityZones</code> API.
BEncrypt the availability zones data source output to protect sensitive zone names.
CUse a VPN to connect to AWS before running the data source to secure the data.
DDisable logging of availability zones data source queries to avoid audit trails.
Attempts:
2 left
💡 Hint

Consider what permissions Terraform needs to query AWS data sources.

Best Practice
expert
3:00remaining
What is the best practice for handling availability zones in Terraform modules for multi-region deployments?

You are designing a Terraform module to deploy infrastructure in multiple AWS regions. What is the best practice for handling availability zones in this module?

AUse the <code>aws_availability_zones</code> data source inside the module without passing region as input, relying on provider configuration.
BHardcode availability zones in the module to ensure consistency across regions.
CPass the region as a variable to the module and use a data source with explicit region provider alias to fetch availability zones.
DAvoid using availability zones and deploy all resources in a single zone to simplify the module.
Attempts:
2 left
💡 Hint

Think about how Terraform handles multiple providers and regions in modules.