📖 Scenario: You are setting up cloud infrastructure using Terraform. To simplify your work, you want to use a module from the Terraform Registry that creates a virtual private cloud (VPC) network.This project will guide you step-by-step to configure Terraform to use a Registry module, set variables, and apply the module to create a VPC.
🎯 Goal: Build a Terraform configuration that uses the official Terraform Registry module terraform-aws-modules/vpc/aws to create a VPC with a specific CIDR block and enable DNS support.
📋 What You'll Learn
Use the Terraform Registry module terraform-aws-modules/vpc/aws
Set the VPC CIDR block to 10.0.0.0/16
Enable DNS support and DNS hostnames
Output the VPC ID after creation
💡 Why This Matters
🌍 Real World
Using Terraform Registry modules helps you quickly build cloud infrastructure by reusing tested and community-approved code.
💼 Career
Cloud engineers and DevOps professionals often use Terraform modules to standardize and speed up infrastructure deployment.
Progress0 / 4 steps
1
Initialize Terraform configuration with provider
Create a Terraform configuration file that declares the aws provider with the region set to us-east-1.
Terraform
Hint
Use the provider "aws" block and set region = "us-east-1".
2
Add the Terraform Registry VPC module
Add a module block named vpc that uses the source terraform-aws-modules/vpc/aws with version ~> 3.0.
Terraform
Hint
Use a module "vpc" block with source and version attributes.
3
Configure the VPC module with CIDR and DNS settings
Inside the module "vpc" block, set cidr to "10.0.0.0/16", enable_dns_support to true, and enable_dns_hostnames to true.
Terraform
Hint
Add the three variables inside the module block exactly as shown.
4
Output the VPC ID
Create an output block named vpc_id that outputs the value of module.vpc.vpc_id.
Terraform
Hint
Use an output block with the name vpc_id and set value = module.vpc.vpc_id.
Practice
(1/5)
1. What is the main purpose of using Terraform Registry modules in your infrastructure code?
easy
A. To reuse tested infrastructure code easily
B. To write all infrastructure code from scratch
C. To avoid using any external code
D. To manually configure cloud resources without code
Solution
Step 1: Understand Terraform Registry modules
Terraform Registry modules are pre-built, reusable pieces of infrastructure code shared publicly or privately.
Step 2: Identify the main benefit
Using these modules helps you avoid rewriting code and ensures you use tested, reliable configurations.
Final Answer:
To reuse tested infrastructure code easily -> Option A