Actualiser vpc.tf
Some checks failed
Terraform Apply / Terraform Apply (push) Failing after 22s

This commit is contained in:
2025-08-07 13:39:50 +02:00
parent 90ffdff761
commit a0dce87015

39
vpc.tf
View File

@@ -1,12 +1,13 @@
locals { 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 # VPC
resource "aws_vpc" "vpc" { resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true enable_dns_hostnames = true
enable_dns_support = true enable_dns_support = true
instance_tenancy = "default"
tags = { tags = {
Name = "${var.environment}-vpc" Name = "${var.environment}-vpc"
@@ -16,7 +17,8 @@ resource "aws_vpc" "vpc" {
# Public subnet # Public subnet
resource "aws_subnet" "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) count = length(var.public_subnets_cidr)
cidr_block = element(var.public_subnets_cidr, count.index) cidr_block = element(var.public_subnets_cidr, count.index)
availability_zone = element(local.availability_zones, count.index) availability_zone = element(local.availability_zones, count.index)
@@ -30,7 +32,8 @@ resource "aws_subnet" "public_subnet" {
# Private Subnet # Private Subnet
resource "aws_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) count = length(var.private_subnets_cidr)
cidr_block = element(var.private_subnets_cidr, count.index) cidr_block = element(var.private_subnets_cidr, count.index)
availability_zone = element(local.availability_zones, count.index) availability_zone = element(local.availability_zones, count.index)
@@ -43,8 +46,9 @@ resource "aws_subnet" "private_subnet" {
} }
#Internet gateway #Internet gateway
resource "aws_internet_gateway" "ig" { resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc.id vpc_id = aws_vpc.default.id
tags = { tags = {
"Name" = "${var.environment}-igw" "Name" = "${var.environment}-igw"
"Environment" = var.environment "Environment" = var.environment
@@ -58,18 +62,19 @@ resource "aws_internet_gateway" "ig" {
#} #}
# NAT Gateway # NAT Gateway
resource "aws_nat_gateway" "nat" { #resource "aws_nat_gateway" "nat" {
# allocation_id = aws_eip.nat_eip.id # allocation_id = aws_eip.nat_eip.id
subnet_id = element(aws_subnet.public_subnet.*.id, 0) # subnet_id = element(aws_subnet.public_subnet.*.id, 0)
tags = { # tags = {
Name = "nat-gateway-${var.environment}" # Name = "nat-gateway-${var.environment}"
Environment = "${var.environment}" # Environment = "${var.environment}"
} # }
} #}
# Routing tables to route traffic for Private Subnet # Routing tables to route traffic for Private Subnet
resource "aws_route_table" "private" { resource "aws_route_table" "private" {
vpc_id = aws_vpc.vpc.id vpc_id = aws_vpc.default.id
tags = { tags = {
Name = "${var.environment}-private-route-table" Name = "${var.environment}-private-route-table"
Environment = "${var.environment}" Environment = "${var.environment}"
@@ -78,7 +83,7 @@ resource "aws_route_table" "private" {
# Routing tables to route traffic for Public Subnet # Routing tables to route traffic for Public Subnet
resource "aws_route_table" "public" { resource "aws_route_table" "public" {
vpc_id = aws_vpc.vpc.id vpc_id = aws_vpc.default.id
tags = { tags = {
Name = "${var.environment}-public-route-table" Name = "${var.environment}-public-route-table"
@@ -89,13 +94,15 @@ resource "aws_route_table" "public" {
# Route for Internet Gateway # Route for Internet Gateway
resource "aws_route" "public_internet_gateway" { resource "aws_route" "public_internet_gateway" {
route_table_id = aws_route_table.public.id route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0" 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 # Route for NAT Gateway
resource "aws_route" "private_internet_gateway" { resource "aws_route" "private_internet_gateway" {
route_table_id = aws_route_table.private.id route_table_id = aws_route_table.private.id
destination_cidr_block = "0.0.0.0/0" destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_nat_gateway.nat.id gateway_id = aws_nat_gateway.nat.id
} }