Module 6 · Project 06 · Build AWS Infrastructure with Terraform · Lesson 21 of 48
Infrastructure as code and your first network
Why you describe cloud infrastructure in code, how an AWS VPC is laid out, and how Terraform providers and resources describe it.
In this lesson · about 30 minutes
- Explain infrastructure as code and declarative tools
- Describe a VPC with public and private subnets, an internet gateway, route tables and security groups
- Read and write Terraform resources and references
Stop clicking
You can build a network, servers and a database by clicking through the AWS console. But clicks can't be reviewed, repeated or undone. Nobody remembers exactly which boxes were ticked, and building a second copy for staging takes a day and comes out slightly different.
Infrastructure as code (IaC) describes infrastructure in text files that live in Git. You review changes in pull requests, recreate whole environments with one command, and see the history of every change. Terraform is the most widely used IaC tool. Like Ansible, it's declarative: you describe the end result, and Terraform works out what to create, change or delete to get there.
The network: a VPC
A VPC (virtual private cloud) is your own private network inside AWS, with an address range such as 10.0.0.0/16. Inside it:
- Subnets split the range up, each in one availability zone (a separate data center).
- A public subnet has a route to an internet gateway; load balancers and bastion hosts go here.
- A private subnet has no direct route from the internet; app servers and databases go here.
- Route tables decide where traffic from each subnet goes.
- Security groups are firewalls around each resource: "allow 443 from anywhere to the load balancer; allow 3000 only from the load balancer to the app".
Who is allowed to change all this is controlled by IAM (users, roles and policies). If that's new, the Cloud Security (AWS) course covers IAM and least privilege step by step.
Terraform files
# providers.tf
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
}
provider "aws" {
region = var.region
}
# main.tf
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = { Name = "notes-vpc" }
}
resource "aws_subnet" "public_a" {
vpc_id = aws_vpc.main.id # a reference
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.main.id
}
Every resource has a type (aws_subnet) and a name you choose (public_a). aws_vpc.main.id is a reference: it means "the ID of that VPC, once it exists". References are how Terraform knows the order: the VPC must exist before its subnet. A provider is the plugin that talks to a particular platform: AWS, Azure, Google Cloud, Cloudflare, GitHub and hundreds more.
Whiteboard · watch and try
Sketch the network
Press Play. The tutor draws the VPC you'll build.
Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.
Check your understanding0 of 3 correct
Key terms
Say the meaning to yourself, then tap a card to check.
Quiz score: 0 of 3
Written by Noviq Academy in its own words. The labs are simulations: no real servers are touched. When you build the projects yourself, use a practice virtual machine or a free-tier cloud account you control, watch your cloud spending, and never run cleanup or delete commands on a machine you care about. Tool names belong to their owners; versions and output are shown for learning and may differ slightly from yours. Read-aloud and the whiteboard voice use your device's built-in voices.