AWS Builder Center

Infrastructure as Code on Day One: Your First AWS Architecture with Terraform

When starting out on AWS, most developers create resources by clicking through the AWS Management Console ("ClickOps"). While the console is great for visual exploration, it creates serious challenges as projects grow: you can’t easily replicate environments, you forget which buttons you clicked, and cleaning up test resources requires hunting through multiple service tabs.

Infrastructure as Code (IaC) solves this by defining cloud resources in declarative configuration files that can be version-controlled with Git.
Here is how a junior developer can deploy their first real AWS resource stack using Terraform in under 10 minutes.

Why Terraform Over Console Clicking?

  • Reproducibility: Spin up identical dev, staging, or production environments with a single command.
  • Easy Cleanup: Run terraform destroy when you finish a tutorial, ensuring no stray billable resources stay behind.
  • Portfolio Proof: Committing .tf files to your GitHub profile visibly demonstrates cloud engineering maturity to hiring managers.

Step 1: Install Terraform and Set Up Your Project

Install Terraform via your local package manager:
1
2
3
4
5
6
# macOS (Homebrew)
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

# Windows (Chocolatey)
choco install terraform
Create an isolated directory for your project:
1
mkdir my-first-terraform && cd my-first-terraform

Step 2: Define the Provider and Resources

Create a file named main.tf. In this example, we will define an encrypted Amazon S3 bucket paired with strict public access blocks:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
terraform {
required_version = ">= 1.5.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

provider "aws" {
region = "us-east-1"
}

# Define an S3 bucket with a randomized unique suffix
resource "aws_s3_bucket" "app_storage" {
bucket_prefix = "dev-sandbox-bucket-"

tags = {
Environment = "Dev"
ManagedBy = "Terraform"
}
}

# Enforce encryption at rest
resource "aws_s3_bucket_server_side_encryption_configuration" "app_storage_crypto" {
bucket = aws_s3_bucket.app_storage.id

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

# Block all accidental public exposure
resource "aws_s3_bucket_public_access_block" "app_storage_block" {
bucket = aws_s3_bucket.app_storage.id

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

# Output the generated bucket name
output "bucket_name" {
value = aws_s3_bucket.app_storage.bucket
description = "The globally unique name of the created S3 bucket"
}

Step 3: Initialize, Plan, and Deploy

Run the three standard Terraform commands in your terminal:
1
2
3
4
5
6
7
8
# 1. Download the AWS provider plugin
terraform init

# 2. Preview what AWS resources will be created
terraform plan

# 3. Apply the changes to your AWS account
terraform apply
Type yes when prompted. In seconds, Terraform creates the bucket, sets up AES-256 encryption, and seals off public access.

Step 4: The Clean-Up Superpower

When you are done testing, you do not need to comb through S3 menus to delete the bucket. Tear down everything declared in your configuration file with one command:
1
terraform destroy
Type yes, and all defined resources are cleanly removed from your AWS account, eliminating the risk of accidental recurring costs.

Over to You

Stepping away from ClickOps and writing your first .tf file is often the moment cloud computing clicks from "clicking around a dashboard" to real software engineering.
Builders: What was the first IaC tool you picked up—Terraform, AWS CloudFormation, or the AWS Cloud Development Kit (CDK)? Let’s compare experiences in the comments below!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article