Challenge - Configure Resources Using Variables and Expressions
Write a parameterized Terraform configuration using variables, complex types, for_each, and expressions to deploy a multi-subnet VPC on AWS.

Lab overview
Terraform configurations tend to start life hardcoded. A CIDR block is typed directly into a resource, a subnet block gets copy-pasted twice, and the result works fine for exactly one environment. The moment you need a second one, every literal has to be found and changed by hand, and the copies drift apart. Parameterization is what separates a script that deployed something once from a configuration a team can reuse.
Terraform's answer is a small set of language features that work together. Input variables lift values out of resource blocks and give them explicit type constraints. Complex types such as map(object({...})) let a single variable describe a whole collection of similar resources. The for_each meta-argument turns that collection into one resource instance per entry, replacing repeated blocks with a single one. Built-in functions like cidrsubnet() compute values that would otherwise be hand-calculated and error-prone. Output values and for expressions then project what was created into a shape other configurations and operators can consume.
Objectives
By completing this Intermediate challenge, you will be able to:
- Replace hardcoded values with typed input variables
- Model a set of similar resources with a single collection variable and iterate to create them
- Compute subnet CIDRs with a built-in function instead of writing them by hand
- Expose a resource ID and a name-to-ID map as outputs using a
forexpression
Prerequisites
Before attempting this challenge, you should be comfortable with:
- Writing and editing Terraform configuration files (HCL syntax)
- Terraform input variables and basic types
- The core Terraform workflow (init, plan, apply)
- Basic AWS networking concepts (VPCs and subnets)
Recommended Lab: Introduction to AWS Terraform
Verified against your live environment
An automated validation engine inspects your actual resources and configurations as you work. Completion means the task was performed — not multiple choice, real-world proficiency.
More labs like this
Introduction to Infrastructure as Code with Terraform on AWS
Write your first HCL configuration and deploy a DynamoDB table to AWS using Terraform's init, plan, and apply workflow.
Terraform Complex Types and Dynamic Expressions on AWS
Define complex variable types, use for_each and count for resource iteration, apply splat expressions and dynamic blocks on AWS with Terraform.
Terraform Input Variables, Outputs, and Variable Precedence on AWS
Declare Terraform input variables with defaults, override values using tfvars and CLI flags, and expose outputs from a deployed DynamoDB table.
Related reading
Environment
Every lab includes
- Real environment, pre-credentialed
- Automated checks on every step
- Isolated sandbox, auto cleanup
- AI-recommended next steps
Lab curriculum
- 01
Deploy a Parameterized VPC with Terraform Variables and Expressions
4 automated checks
Skills validated
Not the lab you were looking for?
Browse 150+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.