Skip to content

Commit 1debbbf

Browse files
committed
vpc: ignore new AMIs, remove associate_public_ip_address from NAT instances
New Amazon NAT AMIs are now ignored - this previously caused NAT instances to be recreated. NAT instances no longer use associate_public_ip_address, as this caused instances which were not using an Elastic IP Address to be recreated if Terraform was run while NAT instances were stopped.
1 parent df23366 commit 1debbbf

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

vpc/main.tf

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,24 @@ resource "aws_instance" "nat_instance" {
151151
Environment = "${var.environment}"
152152
}
153153

154-
key_name = "${var.nat_instance_ssh_key_name}"
155-
ami = "${data.aws_ami.nat_ami.id}"
156-
instance_type = "${var.nat_instance_type}"
157-
source_dest_check = false
158-
associate_public_ip_address = true
159-
subnet_id = "${element(aws_subnet.external.*.id, count.index)}"
160-
vpc_security_group_ids = ["${aws_security_group.nat_instances.id}"]
154+
key_name = "${var.nat_instance_ssh_key_name}"
155+
ami = "${data.aws_ami.nat_ami.id}"
156+
instance_type = "${var.nat_instance_type}"
157+
source_dest_check = false
158+
159+
# associate_public_ip_address is not used,,
160+
# as public subnets have map_public_ip_on_launch set to true.
161+
# Also, using associate_public_ip_address causes issues with
162+
# stopped NAT instances which do not use an Elastic IP.
163+
# - For more details: https://github.com/terraform-providers/terraform-provider-aws/issues/343
164+
subnet_id = "${element(aws_subnet.external.*.id, count.index)}"
165+
166+
vpc_security_group_ids = ["${aws_security_group.nat_instances.id}"]
167+
168+
lifecycle {
169+
# Ignore changes to the NAT AMI data source.
170+
ignore_changes = ["ami"]
171+
}
161172
}
162173

163174
resource "aws_eip_association" "nat_instance_eip" {

0 commit comments

Comments
 (0)