Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS EC2 instance public IP address is not updated on instance type change #20651

Closed
speller opened this issue Aug 22, 2021 · 13 comments · Fixed by #40710
Closed

AWS EC2 instance public IP address is not updated on instance type change #20651

speller opened this issue Aug 22, 2021 · 13 comments · Fixed by #40710
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. service/route53 Issues and PRs that pertain to the route53 service.
Milestone

Comments

@speller
Copy link
Contributor

speller commented Aug 22, 2021

I have the following piece of the configuration:

resource "aws_instance" "control" {
  ami = data.aws_ami.control.id
  instance_type = "t2.micro"
  subnet_id = module.vpc.public1_subnet_id
  associate_public_ip_address = true
  vpc_security_group_ids = [
    aws_security_group.control.id
  ]
}

resource "aws_route53_record" "control" {
  name = "control"
  type = "A"
  zone_id = data.aws_route53_zone.tld.id
  records = [aws_instance.control.public_ip]
  ttl = 300
}

The idea here is that the record must have the instance's public IP address. And it worked well. Then I changed the instance type to t2.nano and Terraform has created the following plan:

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # aws_instance.control will be updated in-place
  ~ resource "aws_instance" "control" {
        id                                   = "i-0f0cca024bef87452"
      ~ instance_type                        = "t2.micro" -> "t2.nano"
        # (28 unchanged attributes hidden)
        # (5 unchanged blocks hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.

You may see here that TF has changed the instance instead of replacing it. In the reality, the instance is replaced and gets a new public IP address. But this change is not reflected in the plan and after executing, the infrastructure becomes broken because the DNS record remains to have an old invalid IP address.

Terraform Version

1.0.3 Docker

Expected Behavior

EC2 instance is replaced in TF state.
Route 53 record is updated with the new instance's IP address.

Actual Behavior

EC2 instance is not replaced in TF state.
Route 53 record is not updated with the new instance's IP address.

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/ec2 Issues and PRs that pertain to the ec2 service. service/route53 Issues and PRs that pertain to the route53 service. labels Aug 22, 2021
@breathingdust breathingdust added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Aug 25, 2021
@joelatrr
Copy link

joelatrr commented Dec 2, 2021

Can confirm same behavior on t3 instance types.

In the case of a route53 update, you can quiesce by running the apply 2x and the ip address will get updated on the A record.

@speller
Copy link
Contributor Author

speller commented Jul 21, 2022

Facing the same issue on every operation that requires instance shutdown. For example, updating the user metadata. The instance is updated but TF doesn't care about the changed IP address so any code that is relying on it will fail or produce broken infrastructure. Why this severe bug is not being fixed?

@jwoytek
Copy link

jwoytek commented Aug 19, 2022

Jumping on the bandwagon here, can confirm this is still the behavior under terraform 1.2.6 with aws provider 4.27.0.

@nobitran
Copy link

nobitran commented Oct 8, 2022

I still got this issue. May I know how to fix it?

@jwoytek
Copy link

jwoytek commented Oct 11, 2022

I still got this issue. May I know how to fix it?

In many cases, a workaround is to run the apply again, which will see the updated IP and update dependent resources/outputs/etc.

@ForbiddenEra
Copy link

+1 using cf provider for dns

@ArkadyDR
Copy link

This issue seems to be a duplicate of #6781.

@jwoytek
Copy link

jwoytek commented Oct 13, 2022

The workaround using an intermediate data source posted in #6781 (comment) seems to work for this particular issue. That same user later posted a staged workaround that would also work, and could be needed if one has other issues. The run-apply-twice is simple, but one must remember to do it.

@speller
Copy link
Contributor Author

speller commented Dec 26, 2022

@ArkadyDR
Yes, this is a duplicate. But who cares?

@jwoytek
Can't test it right now, but changes in instance metadata still don't trigger the instance IP address change in Terraform.

@enobayram
Copy link

Still affected by this bug 3 years after it was reported.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.83.0 milestone Dec 30, 2024
Copy link

github-actions bot commented Jan 9, 2025

This functionality has been released in v5.83.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

github-actions bot commented Feb 9, 2025

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. service/route53 Issues and PRs that pertain to the route53 service.
Projects
None yet
8 participants