@@ -29,14 +29,14 @@ locals {
2929module "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- }
0 commit comments