Skip to content

Commit c69ee8b

Browse files
committed
Fix auto-drive networking
1 parent 07a4ed4 commit c69ee8b

File tree

7 files changed

+37
-57
lines changed

7 files changed

+37
-57
lines changed

auto-drive/main.tf

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ locals {
2929
module "vpc" {
3030
source = "../templates/terraform/aws/vpc"
3131

32-
name = "${local.name}-vpc"
33-
cidr = var.vpc_cidr
34-
azs = local.azs
35-
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
36-
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
32+
name = "${local.name}-vpc"
33+
cidr = var.vpc_cidr
34+
azs = local.azs
35+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
3736

38-
enable_nat_gateway = true
39-
single_nat_gateway = true
37+
# Configure NAT gateways and private subnets settings
38+
enable_nat_gateway = false # Set to true to use NAT gateways and private subnets without public IPs
39+
single_nat_gateway = false # Set to true to use a single NAT gateway
4040

4141
tags = local.tags
4242
}
@@ -125,11 +125,19 @@ module "ec2_auto_drive" {
125125
count = var.auto_drive_instance_count
126126
ami = data.aws_ami.ubuntu_amd64.id
127127
instance_type = var.auto_drive_instance_type
128-
availability_zone = element(local.azs, count.index % length(local.azs))
129-
subnet_id = element(module.vpc.private_subnets, count.index % length(module.vpc.private_subnets))
128+
availability_zone = element(module.vpc.azs, 0)
129+
subnet_id = element(module.vpc.public_subnets, 0)
130130
vpc_security_group_ids = [aws_security_group.auto_drive_sg.id]
131-
associate_public_ip_address = false # Auto-drive instances use EIPs
131+
associate_public_ip_address = false # Gateway instances use EIPs
132+
create_eip = true
133+
disable_api_stop = false
134+
135+
create_iam_instance_profile = true
132136
ignore_ami_changes = true
137+
iam_role_description = "IAM role for EC2 instance"
138+
iam_role_policies = {
139+
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess"
140+
}
133141
root_block_device = [
134142
{
135143
device_name = "/dev/sdf"
@@ -156,11 +164,20 @@ module "ec2_gateway" {
156164
count = var.gateway_instance_count
157165
ami = data.aws_ami.ubuntu_amd64.id
158166
instance_type = var.gateway_instance_type
159-
availability_zone = element(local.azs, count.index % length(local.azs))
160-
subnet_id = element(module.vpc.private_subnets, count.index % length(module.vpc.private_subnets))
167+
availability_zone = element(module.vpc.azs, 0)
168+
subnet_id = element(module.vpc.public_subnets, 0)
161169
vpc_security_group_ids = [aws_security_group.auto_drive_sg.id]
162170
associate_public_ip_address = false # Gateway instances use EIPs
171+
create_eip = true
172+
disable_api_stop = false
173+
174+
create_iam_instance_profile = true
163175
ignore_ami_changes = true
176+
iam_role_description = "IAM role for EC2 instance"
177+
iam_role_policies = {
178+
AdministratorAccess = "arn:aws:iam::aws:policy/AdministratorAccess"
179+
}
180+
164181
root_block_device = [
165182
{
166183
device_name = "/dev/sdf"
@@ -176,29 +193,3 @@ module "ec2_gateway" {
176193
)
177194
tags = merge(local.tags, { Role = "gateway" })
178195
}
179-
180-
################################################################################
181-
# Elastic IPs for Auto-Drive Instances
182-
################################################################################
183-
184-
resource "aws_eip" "auto_drive_eip" {
185-
count = var.auto_drive_instance_count
186-
187-
instance = module.ec2_auto_drive[count.index].id
188-
tags = {
189-
Name = "${local.name}-backend-eip-${count.index}"
190-
}
191-
}
192-
193-
################################################################################
194-
# Elastic IPs for Gateway Instances
195-
################################################################################
196-
197-
resource "aws_eip" "gateway_eip" {
198-
count = var.gateway_instance_count
199-
200-
instance = module.ec2_gateway[count.index].id
201-
tags = {
202-
Name = "${local.name}-gateway-eip-${count.index}"
203-
}
204-
}

auto-drive/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ output "ec2_gateway_availability_zones" {
6868

6969
output "auto_drive_eip" {
7070
description = "Elastic IPs for Auto-Drive instances"
71-
value = aws_eip.auto_drive_eip[*].public_ip
71+
value = module.ec2_auto_drive[*].public_ip
7272
}
7373

7474
output "gateway_eip" {
7575
description = "Elastic IPs for Gateway instances"
76-
value = aws_eip.gateway_eip[*].public_ip
76+
value = module.ec2_gateway[*].public_ip
7777
}
7878

7979

auto-drive/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ variable "kms_key_id" {
7070
variable "auto_drive_instance_count" {
7171
description = "Number of auto-drive instances to create."
7272
type = number
73-
default = 2
73+
default = 1
7474
}
7575

7676
variable "gateway_instance_count" {
7777
description = "Number of gateway instances to create."
7878
type = number
79-
default = 2
79+
default = 1
8080
}
8181

8282
variable "ingress_cidr_blocks" {

templates/terraform/aws/ec2/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
data "aws_partition" "current" {}
22

33
locals {
4-
create = var.create && var.putin_khuylo
4+
create = var.create
55

66
is_t_instance_type = replace(var.instance_type, "/^t(2|3|3a|4g){1}\\..*$/", "1") == "1" ? true : false
77

templates/terraform/aws/ec2/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,6 @@ variable "disable_api_stop" {
351351
default = null
352352

353353
}
354-
variable "putin_khuylo" {
355-
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
356-
type = bool
357-
default = true
358-
}
359354

360355
################################################################################
361356
# IAM Role / Instance Profile

templates/terraform/aws/rds/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
2-
create_db_subnet_group = var.create_db_subnet_group && var.putin_khuylo
3-
create_db_parameter_group = var.create_db_parameter_group && var.putin_khuylo
4-
create_db_instance = var.create_db_instance && var.putin_khuylo
2+
create_db_subnet_group = var.create_db_subnet_group
3+
create_db_parameter_group = var.create_db_parameter_group
4+
create_db_instance = var.create_db_instance
55

66
db_subnet_group_name = var.create_db_subnet_group ? module.db_subnet_group.db_subnet_group_id : var.db_subnet_group_name
77
parameter_group_name_id = var.create_db_parameter_group ? module.db_parameter_group.db_parameter_group_id : var.parameter_group_name

templates/terraform/aws/rds/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,6 @@ variable "cloudwatch_log_group_tags" {
611611
default = {}
612612
}
613613

614-
variable "putin_khuylo" {
615-
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
616-
type = bool
617-
default = true
618-
}
619-
620614
################################################################################
621615
# DB Instance Role Association
622616
################################################################################

0 commit comments

Comments
 (0)