File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -87,13 +87,43 @@ resource "aws_instance" "nat_instance" {
8787 # https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html#EIP_Disable_SrcDestCheck
8888 source_dest_check = false
8989
90- associate_public_ip_address = true
90+ associate_public_ip_address = false
9191
9292 lifecycle {
9393 create_before_destroy = true
9494 }
9595}
9696
97+ resource "aws_eip" "nat_instance" {
98+ count = local. nat_instance_count
99+ vpc = true
100+ tags = merge (
101+ module. nat_instance_label . tags ,
102+ {
103+ " Name" = format (
104+ " %s%s%s" ,
105+ module. nat_label . id ,
106+ var. delimiter ,
107+ replace (
108+ element (var. availability_zones , count. index ),
109+ " -" ,
110+ var. delimiter
111+ )
112+ )
113+ }
114+ )
115+
116+ lifecycle {
117+ create_before_destroy = true
118+ }
119+ }
120+
121+ resource "aws_eip_association" "nat_instance" {
122+ count = local. nat_instance_count
123+ instance_id = element (aws_instance. nat_instance . * . id , count. index )
124+ allocation_id = element (aws_eip. nat_instance . * . id , count. index )
125+ }
126+
97127resource "aws_route" "nat_instance" {
98128 count = local. nat_instance_count
99129 route_table_id = element (aws_route_table. private . * . id , count. index )
You can’t perform that action at this time.
0 commit comments