
production-style infrastructure: ALB module infra-modules + infra-live separation environment-based deployment
ποΈ FINAL STRUCTURE terraform-production-lab/ β βββ infra-modules/ β βββ vpc/ β βββ security-group/ β βββ ec2/ β βββ alb/ β βββ infra-live/ βββ dev/ βββ prod/ π§ IDEA (VERY IMPORTANT) infra-modules β reusable (write once) infra-live β environment-specific (dev/prod) βοΈ STEP 1 β CREATE STRUCTURE mkdir -p terraform-production-lab/infra-modules/ { vpc,security-group,ec2,alb } mkdir -p terraform-production-lab/infra-live/ { dev,prod } cd terraform-production-lab π· MODULE 1 β VPC infra-modules/vpc/main.tf resource "aws_vpc" "this" { cidr_block = var . cidr_block tags = merge ( var . tags , { Name = var . name }) } resource "aws_subnet" "public" { count = length ( var . public_subnets ) vpc_id = aws_vpc . this . id cidr_block = var . public_subnets [ count . index ] availability_zone = var . azs [ count . index ] tags = merge ( var . tags , { Name = "${var.name}-public-${count.index}" }) } variables.tf variable "cidr_block" { type = string } variable "public_subnets" { type = list ( string ) }
Continue reading on Dev.to
Opens in a new tab



