Featured image of post Managing AWS with Terraform

Managing AWS with Terraform

Provision a basic cloud environment from code.

Overview

Terraform treats infrastructure as code. This article demonstrates building an AWS environment consisting of public and private subnets across two availability zones in ap-northeast-1.

Architecture

  • Region: ap-northeast-1
  • AZs: ap-northeast-1a, ap-northeast-1c
  • Public subnets: 10.0.0.0/24, 10.0.128.0/24
  • Private subnets: 10.0.16.0/24, 10.0.144.0/24

Each subnet hosts an EC2 instance with proper routing and security groups.

architecture

Prerequisites

Install Terraform and configure AWS credentials. Ensure Docker is available if you plan to run Terraform inside a container.

Terraform Configuration

Example main.tf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
provider "aws" {
  region = "ap-northeast-1"
}

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_subnet" "public_a" {
  vpc_id            = aws_vpc.main.id
  cidr_block        = "10.0.0.0/24"
  availability_zone = "ap-northeast-1a"
  map_public_ip_on_launch = true
}

Continue declaring private subnets, route tables and EC2 instances.

Initialize and apply:

1
2
terraform init
terraform apply

Cleanup

Destroy resources when finished:

1
terraform destroy

Conclusion

Terraform allows reproducible infrastructure setups and version control for cloud configurations.

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy