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

[Bug]: EC2 public_ip isn't re-read on modifyInstanceAttributeWithStopStart #40586

Closed
nijave opened this issue Dec 16, 2024 · 6 comments · Fixed by #40710
Closed

[Bug]: EC2 public_ip isn't re-read on modifyInstanceAttributeWithStopStart #40586

nijave opened this issue Dec 16, 2024 · 6 comments · Fixed by #40710
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@nijave
Copy link
Contributor

nijave commented Dec 16, 2024

Terraform Core Version

1.7.5

AWS Provider Version

5.81.0

Affected Resource(s)

aws_instance

Expected Behavior

modifyInstanceAttributeWithStopStart should refresh instance attributes that can change after a stop/start cycle. This mainly effects public_ip

Actual Behavior

Instance attributes that change aren't updated

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_instance" "bastion" {
  ami                         = var.bastion_ami
  instance_type               = var.bastion_instance_type
  associate_public_ip_address = true
  ebs_optimized               = true
  key_name                    = "${var.vpc_name}-${var.bastion_key_name}"
  vpc_security_group_ids      = [var.aws_security_group_bastion_id]
  iam_instance_profile        = aws_iam_instance_profile.ec2.name
  subnet_id                   = var.aws_subnet_public1_id
  disable_api_termination     = var.bastion_termination

  user_data = templatefile(
    "./templates/user-data.yaml.tpl",
    {
      deploy_pubkey = data.aws_key_pair.deploy.public_key
      host_keys     = data.aws_secretsmanager_secret_version.bastion_hostkeys.secret_string
    }
  )

  root_block_device {
    encrypted   = var.bastion_volume_encrypted
    volume_size = var.bastion_volume_size
    volume_type = var.bastion_volume_type
  }
}

resource "cloudflare_record" "bastion" {
  zone_id = data.cloudflare_zone.zone.id
  name    = "bastion"
  content = aws_instance.bastion.public_ip
  type    = "A"
  proxied = false
}

Steps to Reproduce

Change user-data, notice route53 record (or cloudflare, whatever) does not update

Changing instance type also causes the same problem

Debug Output

No response

Panic Output

No response

Important Factoids

public_ip is a computed attribute. Terraform performs an action that triggers a value change but does not re-read the new attribute value and update the state. This prevents dependent resources from being updated correctly

References

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/how-ec2-instance-stop-start-works.html

Would you like to implement a fix?

None

@nijave nijave added the bug Addresses a defect in current functionality. label Dec 16, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/ec2 Issues and PRs that pertain to the ec2 service. needs-triage Waiting for first response or review from a maintainer. labels Dec 16, 2024
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Dec 17, 2024
@MS99-9
Copy link
Contributor

MS99-9 commented Dec 30, 2024

Is anyone working on this issue? I want to try fixing it cc @justinretzolk

@nijave
Copy link
Contributor Author

nijave commented Dec 30, 2024

Is anyone working on this issue? I want to try fixing it cc @justinretzolk

Not me

@MS99-9
Copy link
Contributor

MS99-9 commented Jan 12, 2025

This issue is already fixed by this commit @ewbankkit

@nijave nijave closed this as completed Jan 12, 2025
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.

Copy link

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 12, 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.
Projects
None yet
3 participants