DEV Community

Cover image for Automating Infrastructure Creation With IAC (Terraform)
Oluwaseun Olaleye
Oluwaseun Olaleye

Posted on

1

Automating Infrastructure Creation With IAC (Terraform)

INTRODUCTION
This guide walks you through creating a fully functional custom VPC (Virtual Private Cloud) on AWS using Terraform. The configuration includes a VPC, internet gateway, public route table, and dynamically created public subnets distributed across availability zones.

βœ… Prerequisites
Before you begin, ensure you have the following tools and configurations in place:

πŸ› οΈ Tools Installed

  1. Terraform (v1.0 or above recommended)

  2. AWS CLI (configured with appropriate credentials)

  3. Code Editor (e.g., VS Code, Sublime Text)

  4. AWS account

πŸ”§ Provider Configuration

Image description

Initializes the AWS provider for Terraform, setting the region dynamically via a variable.

🌍 Fetching Availability Zones

Image description

Fetches the list of currently available Availability Zones in the region for resilient subnet placement.

πŸ› οΈ VPC Creation

Image description

🌐 Internet Gateway

Image description

Attaches an internet gateway to your VPC, enabling external internet access.

πŸ—ΊοΈ Public Route Table

Image description

Creates a route table with an internet route (0.0.0.0/0) pointing to the IGW.

🧱 Dynamic Public Subnets
Dynamically provisions public subnets across multiple Availability Zones using CIDR subnetting.

Image description

πŸ” Route Table Associations

Associates each public subnet with the public route table to ensure internet connectivity.

Image description

πŸ“¦ Variables to Define
Add the following to your variables.tf file:

Image description

You can find and copy this code from my repository: https://github.com/heritageolaleye/terraform_demo

πŸŽ‰ Conclusion
You now have a dynamic, production-ready AWS VPC setup that includes public subnets distributed across availability zones with internet access configured. This is a great foundation for hosting web applications, microservices, or any cloud-native infrastructure.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)