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

fix: ignore changes to associate_public_ip_address #203

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aslafy-z
Copy link

@aslafy-z aslafy-z commented Aug 7, 2024

what

Add lifecycle ignore changes to aws_instance.associate_public_ip_address

why

  • prevent replacement on external aws eip association

more

Alternative:

  • Implement usage of custom EIP

@aslafy-z aslafy-z requested review from a team as code owners August 7, 2024 12:14
@mergify mergify bot added the triage Needs triage label Aug 7, 2024
@andreineculau
Copy link

@Gowiem @jamengual
Any chance of approving and merging this in 🙇 ? In our case, the EIP association happens outside of this terraform module thus we have a race condition on our hands.

andreineculau added a commit to andreineculau/terraform-aws-ec2-instance that referenced this pull request Aug 14, 2024
@Gowiem
Copy link
Member

Gowiem commented Aug 14, 2024

@aslafy-z @andreineculau -- I believe you can associate an EIP to the EC2 instance through an ENI and the external_network_interfaces variable. I know that is a bit indirect, but does that solve your need here? I believe that would be the proper solution to your issues.

@andreineculau
Copy link

@Gowiem thanks for the reply. I didn't understand your point, but the confusion lead me to investigate the code closer. It turns out that the magic incantation for our situation is

associate_public_ip_address = true
assign_eip_address = false

The former, because we will assign an EIP out of band to the EC2 instance, and the latter because we don't want the module to do that automatically.

Possibly the README or even variables.tf could benefit from clarification upon the matter.
Thank you!

Copy link

mergify bot commented Aug 17, 2024

💥 This pull request now has conflicts. Could you fix it @aslafy-z? 🙏

@mergify mergify bot added the conflict This PR has conflicts label Aug 17, 2024
@Gowiem
Copy link
Member

Gowiem commented Aug 19, 2024

@andreineculau if that worked for you, awesome.

@aslafy-z can you check if that works for your use-case as well and then update this PR (or open another) to mention those instructions in the README under Usage?

@Gowiem
Copy link
Member

Gowiem commented Aug 21, 2024

@aslafy-z friendly ping on the above. Thanks!

@aslafy-z
Copy link
Author

aslafy-z commented Sep 2, 2024

The goal is to assign a static public ip address to the instance. If I get it well, what @andreineculau proposes may change the IP on instance replacement (userdata update for eg.). Can you confirm?

@mergify mergify bot removed the conflict This PR has conflicts label Sep 2, 2024
@andreineculau
Copy link

may change the IP on instance replacement (userdata update for eg.)

Not sure what you mean. We consistently bring down the instance (AMI updates) with no apparent issues. An EIP is assigned just like this module would do internally, except that it is assigned externally. It's the equivalent of "implement usage of custom EIP", just that it's not obvious

@andreineculau
Copy link

@aslafy-z I confirm now. We started seeing IP-related diffs

@andreineculau
Copy link

@Gowiem if you are reluctant, could it be that we make this lifecycle ignore-change conditional to var.associate_public_ip_address being false?

It would read like "you told me NOT to associate an IP, so you do it separately".

But the reverse would still try to correct the drift "you told me to associate an IP, somehow the association broke, I will fix it back"

andreineculau added a commit to andreineculau/terraform-aws-ec2-instance that referenced this pull request Sep 8, 2024
@nitrocode
Copy link
Member

if you are reluctant, could it be that we make this lifecycle ignore-change conditional to var.associate_public_ip_address being false?

@andreineculau please see a similar PR that tries to add a conditional #209 (comment)

This is not possible currently in terraform/opentofu.

Instead, could you set external_network_interface_enabled to true ? That should null the argument

associate_public_ip_address = var.external_network_interface_enabled ? null : var.associate_public_ip_address

@andreineculau
Copy link

Unfortunately i tried that and that opens up to a whole bunch if other issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants