-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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]: Wrong output when Elastic IP was reassigned #37584
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
Hey @EugenKon 👋 Thank you for taking the time to raise this! In this case, this is how I would expect this to behave, and is more related to Terraform Core than the AWS Provider itself. Looking at your example configuration and notes, the output is using an attribute from the Unfortunately, in this case you can't just add an expliict |
We have two instances: zzz and zzz-public. The ElasticIP could be assigned to either host. I do not think we can use Below I want to provide more details how we change the IP between hosts (Please look at it as separate example, which does not belongs to the cluster in the first post): resource "aws_instance" "zzz1" {
}
resource "aws_instance" "zzz2" {
...
}
resource "aws_eip" "manage-cluster" {
instance = aws_instance.zzz2.id # This was chanaged from zzz1 to zzz2
}
output "zzz1" {
value = "zzz1: ${aws_instance.zzz1.public_ip}"
}
output "zzz2" {
value = "zzz2: ${aws_instance.zzz2.public_ip}"
}
# aws_eip.manage-cluster will be updated in-place
~ resource "aws_eip" "manage-cluster" {
id = "eipalloc-*"
~ instance = "i-*1" -> "i-*2"
# (15 unchanged attributes hidden)
} From the plan above it even does not show that IP will be changed for
I understand, that there is some dependencies. But, I suppose, you could agree that users could do not know that dependency and the internals of Terraform. And in this case it leads to unexpected results, because the actual host IP is different in compare to TF state. In this case, I believe, you should update Terraform internals. |
Interesting. If I comment out both:
I see in my plan that zzz1 and output will be removed.
If outputs for zzz1 depends on zzz1 host, why it was not removed? I suppose, this issue with |
If I do vice-versa: adding the host and output back, then I get expected results: The IP address for output is updated.
Thus updates to output do not work only when instance is destroyed. |
Hey @EugenKon 👋 Thanks for the additional context, and for that standalone example -- that's really helpful.
This is a very important callout, and is the root of why you're seeing a need to do a double apply with how you have things configured. This is oversimplified, but the steps of the plan/apply after changing First
Because the Second
Ultimately, I agree with you that I wouldn't expect the average Terraform user to inherently recognize this. In reviewing the documentation to see how we could address this, however, I noticed that we mention something about this already:
So the documentation would typically recommend what I'd mentioned before -- using the As far as applies with |
@justinretzolk Do I understand correct that I should add |
@EugenKon for the data sources, correct. |
I can check this in a few weeks later. |
Hey @EugenKon, just checking in here to see if you were able to test this any further, or whether we should close this one out. |
Sorry. No, I have not worked on this task. Probably next month. |
It looks like it does not belongs to Elastic IP. We have issues when IP address was changed for some reason. To fix this we need to run plan/apply twice. For the next change:
The plan is:
It was applied successfully:
If I run plan again I get this output:
The parts of configuration files:
|
Shouldn't the .tfstate file be updated after an EIP is assigned to an instance, so that in .tfstate the public_ip of an EC2 instance is shown as that assigned EIP? So in .tfstate file I think I should be able to see the EIP I assigned as below, and not as the old public IP:
so actually it should be like this:
I have been recently working on Terraform and encountered this situation or "bug" and my researches lead me to this bug report. So, I wanted to point this out as well. |
Terraform Core Version
v1.8.2
AWS Provider Version
v4.67.0
Affected Resource(s)
Expected Behavior
Actual Behavior
If I rerun the plan/apply, then I can see the correct values:
Though it should be done only by one run of plan/apply.
Output does not corresponds to the actual value:
Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
Steps to Reproduce
Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
No response
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: