From ClickOps to Code: Automating Your First AWS Architecture with Infrastructure as Code
Manual console clicks don’t scale. In this guide, I move a first AWS architecture from “ClickOps” to Infrastructure as Code with Terraform. You’ll build a VPC with public and private subnets, an Internet Gateway and a web server, learn how state files work, and avoid common pitfalls like dependency errors, state drift and surprise bills.
Clicking through the AWS Management Console is the best way to learn what an EC2 instance or an S3 bucket actually is. It is also the first habit you need to outgrow. This is "ClickOps": provisioning infrastructure by hand, one console screen at a time.
ClickOps works for a lab on a Sunday afternoon. It breaks down the moment you need to do the same thing twice. Settings live in your memory and in browser tabs, not in any file. Two environments that were meant to match slowly diverge. A teammate tweaks a security group to "just test something" and never reverts it. This is configuration drift, and it turns every deployment into a guess.
Human error compounds the problem. Miss one checkbox while rebuilding your project for a demo and you get a server that is quietly different from the one you tested. Nobody can review a sequence of clicks, and nobody can roll one back.
Infrastructure as Code (IaC) fixes this by describing your cloud resources in files, then letting a tool build them for you. Your infrastructure becomes text you can read, review, version, and rerun. In this article, we move a first AWS architecture from the console into Terraform and treat the cloud the way we already treat application code.
1. Why Infrastructure as Code Is a Game-Changer for Students
IaC is not an advanced topic reserved for senior engineers. For a student, it solves three practical problems on day one.
Version control for your infrastructure. Terraform files are plain text, so they live in Git next to your application code. Every change gets a commit, a diff, and a message explaining why. If an edit breaks your environment, you can see exactly which line did it and revert it. Your portfolio repo can show not only what you built, but how it evolved.
Disaster recovery and clean-up. A multi-tier architecture that took an afternoon of clicking can be rebuilt with a single. The reverse is just as valuable:
terraform destroy tears the whole thing down in one command. For anyone learning on a tight budget, that is the difference between a controlled experiment and a surprise bill at the end of the month.An industry standard worth listing on your resume. Cloud and DevOps job descriptions routinely ask for experience with Terraform or CloudFormation. Showing a repository where you provisioned a network and a server from code tells a recruiter far more than a line saying "familiar with AWS." It proves you can work the way production teams actually work.
2. Choosing Your Tool: Terraform vs. AWS CloudFormation
Two tools dominate beginner conversations about IaC on AWS. Both are good, and learning either one makes the other easier.
AWS CloudFormation is Amazon's native service. It is tightly integrated with AWS, needs no extra installation, and keeps its state inside AWS itself. If your world is AWS-only, it is a solid and well-supported choice.
Terraform, from HashiCorp, is cloud-agnostic. The same workflow and the same language (HCL) work for AWS, Azure, Google Cloud, and hundreds of other providers. It has a huge community, a public registry of reusable modules, and wide adoption in modern engineering teams.
| CloudFormation | Terraform |
|---|---|---|
Provider scope | AWS only | Multi-cloud and many SaaS providers |
Language | YAML or JSON | HCL (HashiCorp Configuration Language) |
State handling | Managed by AWS | State file you manage (local or remote) |
Reuse | Nested stacks | Modules and a public registry |
This guide uses Terraform. Its skills transfer across clouds, and its plan-then-apply workflow makes it easy to see what will change before anything is touched.
3. A Practical Walkthrough: Building a Simple 2-Tier Architecture
The blueprint
We will build a small but realistic network. A Virtual Private Cloud (VPC) holds two subnets. The public subnet routes to the internet through an Internet Gateway and hosts a web server. The private subnet has no route to the internet and is reserved for a future database tier. A security group allows only HTTP traffic into the web server.
[embed: node/a4e1c8f4-4610]
Only the public subnet is routed to the Internet Gateway, so the web server is reachable from outside, and anything placed in the private subnet is not.
You need Terraform installed and AWS credentials configured locally (for example, with). The examples use the
ap-south-1 region, which you can change in one place.Modular design: keep the files separate.
Even a small project reads better when it is split by purpose. Terraform loads every file in a folder, so this layout costs you nothing:
terraform-aws-demo/├── main.tf # provider and resources├── variables.tf # inputs you can change├── outputs.tf # values printed after apply└── .gitignore # keeps state and secrets out of GitStart with. Anything you might want to change, such as the region or instance size, becomes a variable instead of a hard-coded value:
variable "aws_region" { description = "AWS region to deploy into" type = string default = "ap-south-1"}
variable "project_name" { description = "Prefix used to name and tag resources" type = string default = "iac-demo"}
variable "vpc_cidr" { description = "CIDR block for the VPC" type = string default = "10.0.0.0/16"}
variable "instance_type" { description = "EC2 instance type for the web server" type = string default = "t3.micro"}Next,
main.tf declares the network and the server. Notice that resources refer to each other (for example) instead of using copied IDs:terraform { required_version = ">= 1.5"
required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } }}
provider "aws" { region = var.aws_region}
data "aws_availability_zones" "available" { state = "available"}
data "aws_ami" "amazon_linux" { most_recent = true owners = ["amazon"]
filter { name = "name" values = ["al2023-ami-2023.*-x86_64"] }}
resource "aws_vpc" "main" { cidr_block = var.vpc_cidr enable_dns_hostnames = true
tags = { Name = "${var.project_name}-vpc" }}
resource "aws_internet_gateway" "igw" { vpc_id = aws_vpc.main.id
tags = { Name = "${var.project_name}-igw" }}
resource "aws_subnet" "public" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" availability_zone = data.aws_availability_zones.available. names[0] map_public_ip_on_launch = true
tags = { Name = "${var.project_name}-public" }}
resource "aws_subnet" "private" { vpc_id = aws_vpc.main.id cidr_block = "10.0.2.0/24" availability_zone = data.aws_availability_zones.available. names[0]
tags = { Name = "${var.project_name}-private" }}
resource "aws_route_table" "public" { vpc_id = aws_vpc.main.id
route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.igw.id }
tags = { Name = "${var.project_name}-public-rt" }}
resource "aws_route_table_association" "public" { subnet_id = aws_subnet.public.id route_table_id = aws_route_table.public.id}
resource "aws_security_group" "web" { name = "${var.project_name}-web-sg" description = "Allow inbound HTTP" vpc_id = aws_vpc.main.id
ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] }
egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] }
tags = { Name = "${var.project_name}-web-sg" }}
resource "aws_instance" "web" { ami = data.aws_ami.amazon_linux.id instance_type = var.instance_type subnet_id = aws_subnet.public.id vpc_security_group_ids = [aws_security_group.web.id]
user_data = <<-EOF #!/bin/bashdnf install -y nginx systemctl enable --now nginxecho "Hello from Terraform</h1>" > /usr/share/nginx/html/index.html EOF
tags = { Name = "${var.project_name}-web" }}Finally,
outputs.tf prints the values you care about once the build finishes:output "vpc_id" { description = "ID of the VPC" value = aws_vpc.main.id}
output "web_url" { description = "Public URL of the web server" value = "http://${aws_instance.web.public_ip}"}Three commands take you from an empty folder to a running server:
terraform init # download the AWS providerterraform plan # preview what will be createdterraform apply # build it (type 'yes' to confirm)Wait a minute or two for the instance to finish booting, then open the
web_url output in your browser.State management: what terraform.tfstate is
After, Terraform writes a file called. It is Terraform's record of which real AWS resources correspond to which blocks in your code. Every future
plan compares three things: your code, this state file, and the live infrastructure.Treat it carefully. If you delete it, Terraform forgets what it built and will try to create everything again. It can also contain sensitive values, so add and the folder to and never commit them. A local state file is fine while you are learning alone. Once you work in a team, move it to a remote backend such as an S3 bucket with locking so everyone shares one source of truth.
4. Lessons Learned Along the Way: The "Break and Fix" Loop
The first time you run Terraform, something will go wrong. That is normal, and each failure teaches a concept the console hides from you.
Dependency hell
Some resources cannot exist until others do. A subnet needs a VPC. A route needs an Internet Gateway. In the console you create them in the right order without thinking. In code, you describe what you want, and Terraform works out the order.
It does this by reading references. When the subnet says, "Terraform learns that the VPC must come first." Errors appear when a dependency is hidden, for example when something relies on a resource but never references it. In that case, add an explicit
argument. Running terraform graph shows the dependency tree Terraform has built.State drift
Suppose a teammate opens the console and changes the security group while Terraform is not looking. Now reality no longer matches your code or your state file. This is drift.
Run
terraform plan . Terraform refreshes its view of the real infrastructure and shows the differences. To only update the state file with what exists in AWS, use terraform apply -refresh-only . To push everything back to what your code says, run terraform apply . The older terraform refresh command does the refresh-only step but is now deprecated, so prefer the -refresh-only form. The lasting fix is a team rule: change infrastructure only through code.Cost implications
Terraform makes creating resources so easy that forgetting them is the real danger. An instance left running costs money every hour. Get in the habit of running
terraform destroy when you finish a session, and read the plan it prints before confirming.Two more habits help. Set a billing alert in AWS Budgets so a mistake never goes unnoticed for a month. And be aware that some resources, such as NAT Gateways, charge by the hour even when idle, which is why this walkthrough leaves the private subnet without internet access.
Conclusion
Moving to Infrastructure as Code changes how you think about cloud engineering. A network, a firewall rule and a server stop being things you click into existence and become software: written, reviewed, versioned, tested and rebuilt on demand. Once you have watched a whole VPC appear from
terraform apply and vanish with terraform destroy , going back to ClickOps feels like editing a document with no undo button.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article