From a0dce87015e26e71f6dc85a17d5b04b45973fa66 Mon Sep 17 00:00:00 2001 From: Hubert Cornet Date: Thu, 7 Aug 2025 13:39:50 +0200 Subject: [PATCH] Actualiser vpc.tf --- vpc.tf | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/vpc.tf b/vpc.tf index d7ac9cd..e8e16b8 100644 --- a/vpc.tf +++ b/vpc.tf @@ -1,12 +1,13 @@ locals { - availability_zones = ["${var.aws_region}a", "${var.aws_region}b"] + availability_zones = ["${var.aws_region}a", "${var.aws_region}b", "${var.aws_region}c"] } # VPC -resource "aws_vpc" "vpc" { +resource "aws_vpc" "default" { cidr_block = "10.0.0.0/16" enable_dns_hostnames = true enable_dns_support = true + instance_tenancy = "default" tags = { Name = "${var.environment}-vpc" @@ -16,7 +17,8 @@ resource "aws_vpc" "vpc" { # Public subnet resource "aws_subnet" "public_subnet" { - vpc_id = aws_vpc.vpc.id + vpc_id = aws_vpc.default.id + count = length(var.public_subnets_cidr) cidr_block = element(var.public_subnets_cidr, count.index) availability_zone = element(local.availability_zones, count.index) @@ -30,7 +32,8 @@ resource "aws_subnet" "public_subnet" { # Private Subnet resource "aws_subnet" "private_subnet" { - vpc_id = aws_vpc.vpc.id + vpc_id = aws_vpc.default.id + count = length(var.private_subnets_cidr) cidr_block = element(var.private_subnets_cidr, count.index) availability_zone = element(local.availability_zones, count.index) @@ -43,8 +46,9 @@ resource "aws_subnet" "private_subnet" { } #Internet gateway -resource "aws_internet_gateway" "ig" { - vpc_id = aws_vpc.vpc.id +resource "aws_internet_gateway" "igw" { + vpc_id = aws_vpc.default.id + tags = { "Name" = "${var.environment}-igw" "Environment" = var.environment @@ -58,18 +62,19 @@ resource "aws_internet_gateway" "ig" { #} # NAT Gateway -resource "aws_nat_gateway" "nat" { +#resource "aws_nat_gateway" "nat" { # allocation_id = aws_eip.nat_eip.id - subnet_id = element(aws_subnet.public_subnet.*.id, 0) - tags = { - Name = "nat-gateway-${var.environment}" - Environment = "${var.environment}" - } -} +# subnet_id = element(aws_subnet.public_subnet.*.id, 0) +# tags = { +# Name = "nat-gateway-${var.environment}" +# Environment = "${var.environment}" +# } +#} # Routing tables to route traffic for Private Subnet resource "aws_route_table" "private" { - vpc_id = aws_vpc.vpc.id + vpc_id = aws_vpc.default.id + tags = { Name = "${var.environment}-private-route-table" Environment = "${var.environment}" @@ -78,7 +83,7 @@ resource "aws_route_table" "private" { # Routing tables to route traffic for Public Subnet resource "aws_route_table" "public" { - vpc_id = aws_vpc.vpc.id + vpc_id = aws_vpc.default.id tags = { Name = "${var.environment}-public-route-table" @@ -89,13 +94,15 @@ resource "aws_route_table" "public" { # Route for Internet Gateway resource "aws_route" "public_internet_gateway" { route_table_id = aws_route_table.public.id + destination_cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.ig.id + gateway_id = aws_internet_gateway.igw.id } # Route for NAT Gateway resource "aws_route" "private_internet_gateway" { route_table_id = aws_route_table.private.id + destination_cidr_block = "0.0.0.0/0" gateway_id = aws_nat_gateway.nat.id }