Skip to content

Commit 49430ce

Browse files
committed
Replace complex VPC module with simple Terraform configuration for testing
1 parent f63e1bc commit 49430ce

File tree

4 files changed

+235
-147
lines changed

4 files changed

+235
-147
lines changed
Lines changed: 153 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,173 @@
1-
# Security Group for VPC Endpoints
2-
resource "aws_security_group" "vpc_endpoints" {
3-
name_prefix = "hpc-${var.environment}-vpc-endpoints-"
4-
vpc_id = module.vpc.vpc_id
5-
description = "Security group for VPC endpoints"
6-
7-
ingress {
8-
from_port = 443
9-
to_port = 443
10-
protocol = "tcp"
11-
cidr_blocks = [var.vpc_cidr]
12-
description = "HTTPS from VPC"
13-
}
14-
15-
egress {
16-
from_port = 0
17-
to_port = 0
18-
protocol = "-1"
19-
cidr_blocks = ["0.0.0.0/0"]
20-
description = "All outbound traffic"
21-
}
22-
23-
tags = merge(var.common_tags, {
24-
Name = "hpc-${var.environment}-vpc-endpoints-sg"
25-
Type = "VPC-Endpoints-SecurityGroup"
1+
# Simple VPC Configuration for Testing
2+
resource "aws_vpc" "main" {
3+
cidr_block = var.cidr
4+
enable_dns_hostnames = true
5+
enable_dns_support = true
6+
7+
tags = merge(var.tags, {
8+
Name = var.name
269
})
27-
28-
lifecycle {
29-
create_before_destroy = true
30-
}
3110
}
3211

33-
# VPC Endpoints for AWS services
34-
resource "aws_vpc_endpoint" "ec2" {
35-
vpc_id = module.vpc.vpc_id
36-
service_name = "com.amazonaws.${var.region}.ec2"
37-
vpc_endpoint_type = "Interface"
38-
subnet_ids = module.vpc.private_subnets
39-
security_group_ids = [aws_security_group.vpc_endpoints.id]
40-
private_dns_enabled = true
41-
42-
tags = merge(var.common_tags, {
43-
Name = "hpc-${var.environment}-ec2-endpoint"
44-
Type = "VPC-Endpoint"
12+
# Internet Gateway
13+
resource "aws_internet_gateway" "main" {
14+
vpc_id = aws_vpc.main.id
15+
16+
tags = merge(var.tags, {
17+
Name = "${var.name}-igw"
4518
})
4619
}
4720

48-
resource "aws_vpc_endpoint" "ec2messages" {
49-
vpc_id = module.vpc.vpc_id
50-
service_name = "com.amazonaws.${var.region}.ec2messages"
51-
vpc_endpoint_type = "Interface"
52-
subnet_ids = module.vpc.private_subnets
53-
security_group_ids = [aws_security_group.vpc_endpoints.id]
54-
private_dns_enabled = true
55-
56-
tags = merge(var.common_tags, {
57-
Name = "hpc-${var.environment}-ec2messages-endpoint"
58-
Type = "VPC-Endpoint"
21+
# Public Subnets
22+
resource "aws_subnet" "public" {
23+
count = length(var.public_subnets)
24+
25+
vpc_id = aws_vpc.main.id
26+
cidr_block = var.public_subnets[count.index]
27+
availability_zone = var.azs[count.index]
28+
map_public_ip_on_launch = true
29+
30+
tags = merge(var.public_subnet_tags, {
31+
Name = "${var.name}-public-${count.index + 1}"
32+
})
33+
}
34+
35+
# Private Subnets
36+
resource "aws_subnet" "private" {
37+
count = length(var.private_subnets)
38+
39+
vpc_id = aws_vpc.main.id
40+
cidr_block = var.private_subnets[count.index]
41+
availability_zone = var.azs[count.index]
42+
43+
tags = merge(var.private_subnet_tags, {
44+
Name = "${var.name}-private-${count.index + 1}"
5945
})
6046
}
6147

62-
resource "aws_vpc_endpoint" "ssm" {
63-
vpc_id = module.vpc.vpc_id
64-
service_name = "com.amazonaws.${var.region}.ssm"
65-
vpc_endpoint_type = "Interface"
66-
subnet_ids = module.vpc.private_subnets
67-
security_group_ids = [aws_security_group.vpc_endpoints.id]
68-
private_dns_enabled = true
69-
70-
tags = merge(var.common_tags, {
71-
Name = "hpc-${var.environment}-ssm-endpoint"
72-
Type = "VPC-Endpoint"
48+
# Database Subnets
49+
resource "aws_subnet" "database" {
50+
count = length(var.database_subnets)
51+
52+
vpc_id = aws_vpc.main.id
53+
cidr_block = var.database_subnets[count.index]
54+
availability_zone = var.azs[count.index]
55+
56+
tags = merge(var.database_subnet_tags, {
57+
Name = "${var.name}-database-${count.index + 1}"
7358
})
7459
}
7560

76-
resource "aws_vpc_endpoint" "ssmmessages" {
77-
vpc_id = module.vpc.vpc_id
78-
service_name = "com.amazonaws.${var.region}.ssmmessages"
79-
vpc_endpoint_type = "Interface"
80-
subnet_ids = module.vpc.private_subnets
81-
security_group_ids = [aws_security_group.vpc_endpoints.id]
82-
private_dns_enabled = true
83-
84-
tags = merge(var.common_tags, {
85-
Name = "hpc-${var.environment}-ssmmessages-endpoint"
86-
Type = "VPC-Endpoint"
61+
# Compute Subnets
62+
resource "aws_subnet" "compute" {
63+
count = length(var.compute_subnets)
64+
65+
vpc_id = aws_vpc.main.id
66+
cidr_block = var.compute_subnets[count.index]
67+
availability_zone = var.azs[count.index]
68+
69+
tags = merge(var.compute_subnet_tags, {
70+
Name = "${var.name}-compute-${count.index + 1}"
8771
})
8872
}
8973

90-
resource "aws_vpc_endpoint" "cloudwatch" {
91-
vpc_id = module.vpc.vpc_id
92-
service_name = "com.amazonaws.${var.region}.monitoring"
93-
vpc_endpoint_type = "Interface"
94-
subnet_ids = module.vpc.private_subnets
95-
security_group_ids = [aws_security_group.vpc_endpoints.id]
96-
private_dns_enabled = true
97-
98-
tags = merge(var.common_tags, {
99-
Name = "hpc-${var.environment}-cloudwatch-endpoint"
100-
Type = "VPC-Endpoint"
74+
# Route Table for Public Subnets
75+
resource "aws_route_table" "public" {
76+
vpc_id = aws_vpc.main.id
77+
78+
route {
79+
cidr_block = "0.0.0.0/0"
80+
gateway_id = aws_internet_gateway.main.id
81+
}
82+
83+
tags = merge(var.tags, {
84+
Name = "${var.name}-public-rt"
10185
})
10286
}
10387

104-
resource "aws_vpc_endpoint" "cloudwatchlogs" {
105-
vpc_id = module.vpc.vpc_id
106-
service_name = "com.amazonaws.${var.region}.logs"
107-
vpc_endpoint_type = "Interface"
108-
subnet_ids = module.vpc.private_subnets
109-
security_group_ids = [aws_security_group.vpc_endpoints.id]
110-
private_dns_enabled = true
111-
112-
tags = merge(var.common_tags, {
113-
Name = "hpc-${var.environment}-cloudwatchlogs-endpoint"
114-
Type = "VPC-Endpoint"
88+
# Route Table Associations for Public Subnets
89+
resource "aws_route_table_association" "public" {
90+
count = length(aws_subnet.public)
91+
92+
subnet_id = aws_subnet.public[count.index].id
93+
route_table_id = aws_route_table.public.id
94+
}
95+
96+
# NAT Gateway (single for dev)
97+
resource "aws_eip" "nat" {
98+
count = var.enable_nat_gateway ? 1 : 0
99+
100+
domain = "vpc"
101+
102+
tags = merge(var.tags, {
103+
Name = "${var.name}-nat-eip"
115104
})
116105
}
106+
107+
resource "aws_nat_gateway" "main" {
108+
count = var.enable_nat_gateway ? 1 : 0
109+
110+
allocation_id = aws_eip.nat[0].id
111+
subnet_id = aws_subnet.public[0].id
112+
113+
tags = merge(var.tags, {
114+
Name = "${var.name}-nat-gateway"
115+
})
116+
117+
depends_on = [aws_internet_gateway.main]
118+
}
119+
120+
# Route Table for Private Subnets
121+
resource "aws_route_table" "private" {
122+
count = var.enable_nat_gateway ? 1 : 0
123+
124+
vpc_id = aws_vpc.main.id
125+
126+
route {
127+
cidr_block = "0.0.0.0/0"
128+
nat_gateway_id = aws_nat_gateway.main[0].id
129+
}
130+
131+
tags = merge(var.tags, {
132+
Name = "${var.name}-private-rt"
133+
})
134+
}
135+
136+
# Route Table Associations for Private Subnets
137+
resource "aws_route_table_association" "private" {
138+
count = var.enable_nat_gateway ? length(aws_subnet.private) : 0
139+
140+
subnet_id = aws_subnet.private[count.index].id
141+
route_table_id = aws_route_table.private[0].id
142+
}
143+
144+
# Security Group for VPC Endpoints
145+
resource "aws_security_group" "vpc_endpoints" {
146+
name_prefix = "${var.name}-vpc-endpoints-"
147+
vpc_id = aws_vpc.main.id
148+
description = "Security group for VPC endpoints"
149+
150+
ingress {
151+
from_port = 443
152+
to_port = 443
153+
protocol = "tcp"
154+
cidr_blocks = [var.cidr]
155+
description = "HTTPS from VPC"
156+
}
157+
158+
egress {
159+
from_port = 0
160+
to_port = 0
161+
protocol = "-1"
162+
cidr_blocks = ["0.0.0.0/0"]
163+
description = "All outbound traffic"
164+
}
165+
166+
tags = merge(var.tags, {
167+
Name = "${var.name}-vpc-endpoints-sg"
168+
})
169+
170+
lifecycle {
171+
create_before_destroy = true
172+
}
173+
}
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
# VPC outputs
21
output "vpc_id" {
32
description = "ID of the VPC"
4-
value = module.vpc.vpc_id
3+
value = aws_vpc.main.id
54
}
65

76
output "vpc_cidr_block" {
87
description = "CIDR block of the VPC"
9-
value = module.vpc.vpc_cidr_block
8+
value = aws_vpc.main.cidr_block
109
}
1110

12-
output "private_subnets" {
13-
description = "List of IDs of private subnets"
14-
value = module.vpc.private_subnets
11+
output "public_subnets" {
12+
description = "IDs of the public subnets"
13+
value = aws_subnet.public[*].id
1514
}
1615

17-
output "public_subnets" {
18-
description = "List of IDs of public subnets"
19-
value = module.vpc.public_subnets
16+
output "private_subnets" {
17+
description = "IDs of the private subnets"
18+
value = aws_subnet.private[*].id
2019
}
2120

2221
output "database_subnets" {
23-
description = "List of IDs of database subnets"
24-
value = module.vpc.database_subnets
22+
description = "IDs of the database subnets"
23+
value = aws_subnet.database[*].id
2524
}
2625

2726
output "compute_subnets" {
28-
description = "List of IDs of compute subnets"
29-
value = module.vpc.compute_subnets
27+
description = "IDs of the compute subnets"
28+
value = aws_subnet.compute[*].id
29+
}
30+
31+
output "internet_gateway_id" {
32+
description = "ID of the Internet Gateway"
33+
value = aws_internet_gateway.main.id
3034
}
3135

3236
output "nat_gateway_ids" {
33-
description = "List of IDs of the NAT Gateways"
34-
value = module.vpc.natgw_ids
37+
description = "IDs of the NAT Gateways"
38+
value = aws_nat_gateway.main[*].id
3539
}
3640

3741
output "vpc_endpoints_security_group_id" {
38-
description = "ID of the VPC endpoints security group"
42+
description = "ID of the security group for VPC endpoints"
3943
value = aws_security_group.vpc_endpoints.id
40-
}
44+
}

infrastructure/dev/us-east-2/networking/vpc/terragrunt.hcl

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ include "region" {
99
}
1010

1111
terraform {
12-
source = "git::https://github.com/terraform-aws-modules/terraform-aws-vpc.git?ref=v5.1.2"
12+
source = "."
1313
}
1414

1515
inputs = {
16-
# VPC Module inputs
16+
# VPC Configuration
1717
name = "hpc-dev-vpc"
1818
cidr = "10.0.0.0/16"
1919

@@ -25,19 +25,8 @@ inputs = {
2525
database_subnets = ["10.0.200.0/24", "10.0.201.0/24", "10.0.202.0/24"]
2626
compute_subnets = ["10.0.100.0/22", "10.0.104.0/22", "10.0.108.0/22"]
2727

28-
# Enable DNS
29-
enable_dns_hostnames = true
30-
enable_dns_support = true
31-
3228
# Enable NAT Gateway (single for dev)
3329
enable_nat_gateway = true
34-
single_nat_gateway = true # Cost optimization for dev
35-
36-
# Disable VPC Flow Logs for now to simplify configuration
37-
enable_flow_log = false
38-
39-
# VPC Endpoints for AWS services
40-
enable_s3_endpoint = true
4130

4231
# Tags
4332
tags = {
@@ -90,17 +79,5 @@ inputs = {
9079
Type = "Compute-Subnet"
9180
Tier = "HPC-Compute"
9281
}
93-
94-
# Additional variables for local Terraform resources
95-
environment = "dev"
96-
region = "us-east-2"
97-
vpc_cidr = "10.0.0.0/16"
98-
common_tags = {
99-
Environment = "dev"
100-
Region = "us-east-2"
101-
Project = "HPC-Networking"
102-
ManagedBy = "Terragrunt"
103-
Owner = "DevOps-Team"
104-
}
10582
}
10683

0 commit comments

Comments
 (0)