-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Persistent diff with data sources when referencing 0-count instances in 0.13 #26100
Comments
Thanks for the complete example @lorengordon! The difference here is that 0.12 stored There may be some way to re-introduce the empty resource state, however I have a feeling that the cleanup was done to prevent other side effects of having no resources in the state and it might be more complicated than it appears. In the long run, this is one of the cases that merging of refresh into the plan walk will take care of, which we can look forward to in an upcoming major release. |
Thanks @jbardin, that explanation makes total sense. Of course if a resource with 0 instances is not stored in the state, then the whole thing will need to be read every time and create this persistent diff. I would be very interested in learning which specific edge cases led to this change in behavior. In the meantime, I did find one workaround, using the same condition on the resource and on any reference to its attributes. That way terraform can evaluate the expression properly. Here's an example: locals {
create_this = true
create_empty = false
template = "$${random}"
vars = {
random = local.create_this ? random_pet.this[0].id : ""
empty = local.create_empty ? random_pet.empty[0].id : ""
}
}
resource random_pet this {
count = local.create_this ? 1 : 0
}
resource random_pet empty {
count = local.create_empty ? 1 : 0
}
data template_file this {
template = local.template
vars = local.vars
}
output template_rendered {
value = data.template_file.this.rendered
} |
Hello, This issue will only be fix im TF 0.14 ? Quentin. |
This is fixed in master by the new data lifecycle changes, and will be included in the 0.14 release.
Thanks! |
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. |
Terraform Version
Terraform Configuration Files
Expected Behavior
Following a successful apply,
terraform plan
should result in no changes.Actual Behavior
terraform plan
outputs that data sources will be read during apply, despite there being no other changes.Steps to Reproduce
terraform init
terraform apply
terraform plan
Additional Information
The persistent diff occurs when the data source references a "conditional" resource (e.g.
count = 0
), such that the value is empty. In the repro above, this is theempty
key/value in thevars
map. Remove that value and it works fine.References
There are a handful of similar reported issues, but the ones I found were closed as duplicates or otherwise resolved in terraform 0.13.1.
The text was updated successfully, but these errors were encountered: