diff --git a/terraform/aws-infrastructure/modules/vpc/main.tf b/terraform/aws-infrastructure/modules/vpc/main.tf new file mode 100644 index 0000000..a5243f2 --- /dev/null +++ b/terraform/aws-infrastructure/modules/vpc/main.tf @@ -0,0 +1,70 @@ +# VPC Module Example +# Full implementation available in repository + +resource "aws_vpc" "main" { + cidr_block = var.vpc_cidr + enable_dns_hostnames = true + enable_dns_support = true + + tags = merge(var.tags, { + Name = var.vpc_name + }) +} + +resource "aws_internet_gateway" "main" { + vpc_id = aws_vpc.main.id + tags = merge(var.tags, { Name = "${var.vpc_name}-igw" }) +} + +resource "aws_subnet" "public" { + count = length(var.public_subnet_cidrs) + vpc_id = aws_vpc.main.id + cidr_block = var.public_subnet_cidrs[count.index] + availability_zone = var.azs[count.index] + map_public_ip_on_launch = true + + tags = merge(var.tags, { + Name = "${var.vpc_name}-public-${var.azs[count.index]}" + Tier = "Public" + }) +} + +resource "aws_subnet" "private" { + count = length(var.private_subnet_cidrs) + vpc_id = aws_vpc.main.id + cidr_block = var.private_subnet_cidrs[count.index] + availability_zone = var.azs[count.index] + + tags = merge(var.tags, { + Name = "${var.vpc_name}-private-${var.azs[count.index]}" + Tier = "Private" + }) +} + +resource "aws_eip" "nat" { + count = var.enable_nat_gateway ? (var.single_nat_gateway ? 1 : length(var.azs)) : 0 + domain = "vpc" + tags = merge(var.tags, { Name = "${var.vpc_name}-nat-eip" }) +} + +resource "aws_nat_gateway" "main" { + count = var.enable_nat_gateway ? (var.single_nat_gateway ? 1 : length(var.azs)) : 0 + allocation_id = aws_eip.nat[count.index].id + subnet_id = aws_subnet.public[count.index].id + tags = merge(var.tags, { Name = "${var.vpc_name}-nat" }) +} + +# Route tables, associations, and other resources... +# See full implementation in repository + +output "vpc_id" { + value = aws_vpc.main.id +} + +output "public_subnet_ids" { + value = aws_subnet.public[*].id +} + +output "private_subnet_ids" { + value = aws_subnet.private[*].id +}