Challenge LabIntermediate

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.

40 minEstimated time
1Guided step
AutoVerification
IsolatedSandbox
Challenge - Configure Resources Using Variables and Expressions

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 for expression

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.

[CHECK] validation_activelive
Inspecting deployed resources...
Verifying configuration state...
✓ Step requirements satisfied

More labs like this

Related reading

PremiumIncluded in Premium
Duration
40 min
Steps
1

Environment

Browser Code IDELive Cloud Environment

Every lab includes

  • Real environment, pre-credentialed
  • Automated checks on every step
  • Isolated sandbox, auto cleanup
  • AI-recommended next steps

Lab curriculum

  1. 01

    Deploy a Parameterized VPC with Terraform Variables and Expressions

    4 automated checks

Skills validated

TerraformInfrastructure as Code

Not the lab you were looking for?

Browse 200+ hands-on labs across AWS, Azure, Kubernetes, Docker, and cloud security.

Explore the catalog