From 9c427567a043617e434261a32223c8d1f19e7a88 Mon Sep 17 00:00:00 2001 From: Sourav Kundu Date: Tue, 20 Aug 2024 17:06:26 -0500 Subject: [PATCH] #4 network stack --- data.tf | 3 +++ network.tf | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 data.tf create mode 100644 network.tf diff --git a/data.tf b/data.tf new file mode 100644 index 0000000..fe2f6cb --- /dev/null +++ b/data.tf @@ -0,0 +1,3 @@ +data "aws_caller_identity" "current" {} + +data "aws_availability_zones" "available" {} \ No newline at end of file diff --git a/network.tf b/network.tf new file mode 100644 index 0000000..c77884a --- /dev/null +++ b/network.tf @@ -0,0 +1,31 @@ + +resource "aws_vpc" "this" { + #checkov:skip=CKV2_AWS_11: This is non prod and hence disabled. + cidr_block = var.vpc_cidr + enable_dns_hostnames = true + enable_dns_support = true + tags = { + "Name" = "${var.name}" + } +} +resource "aws_subnet" "db" { + count = length(var.subnet_cidr) + vpc_id = aws_vpc.this.id + cidr_block = var.subnet_cidr[count.index] + availability_zone = data.aws_availability_zones.available.names[count.index] + tags = { + "Name" = "${var.name}subnet-${count.index + 1}" + } +} +resource "aws_route_table" "this_rt" { + vpc_id = aws_vpc.this.id + tags = { + "Name" = "${var.name}-route-table" + } +} +resource "aws_route_table_association" "db" { + count = length(var.subnet_cidr) + subnet_id = element(aws_subnet.db.*.id, count.index) + route_table_id = aws_route_table.this_rt.id +} +