Streamlining AWS Infrastructure with Terraform: A Modular Approach
Reza Chegini
Certified GCP & AWS DevOps Engineer| Seeking Entry-Level Cloud Developer, DevOps, SRE Roles, Software Engineer or Developer | Aspiring DevOps & SRE
In today's cloud-native world, managing infrastructure efficiently and securely is paramount. I recently worked on creating a modular AWS Virtual Private Cloud (VPC) using Terraform to simplify resource provisioning and ensure scalability. This configuration is designed to create and manage a VPC with associated subnets, routing tables, NAT gateways, and other features, all while adhering to best practices.
In this post, I’ll walk through the highlights of the configuration, explaining each component and showcasing how Terraform's modular approach enhances the efficiency and manageability of AWS infrastructure. Let’s dive in! ??
1. Terraform Block
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.69.0"
}
}
}
2. Provider Block
provider "aws" {
region = var.aws_region
}
3. Variable Declaration
variable "aws_region" {
description = "Region in which AWS Resources to be created"
type = string
default = "us-east-1"
}
4. Module for VPC
领英推荐
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.13.0"
name = "vpc-dev"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
#database subnet
create_database_subnet_group = true
create_database_subnet_route_table = true
database_subnets = ["10.0.151.0/24", "10.0.152.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
enable_dns_support = true
public_subnet_tags = {
Type: "public_subnets",
}
private_subnet_tags = {
Type: "private_subnets",
}
database_subnet_tags = {
Type: "database_subnets",
}
tags = {
owner: "Reza"
Environment: "dev"
}
vpc_tags = {
Name: "vpc-dev"
}
}
. Source and Version
b. VPC Configuration
c. Subnets
d. NAT Gateway
e. DNS Settings
f. Tags
This Terraform configuration demonstrates the power of modular infrastructure management by:
By leveraging Terraform's capabilities, this setup ensures a scalable, efficient, and well-organized AWS infrastructure.
Senior Infrastructure And Network Expert
2 个月Interesting