Using templatefile directly in a part's content can cause unnecessary plan changes #254
Open
1 task done
Labels
bug
Something isn't working
Terraform CLI and Provider Versions
Terraform v1.9.1
on linux_amd64
Terraform Configuration
Expected Behavior
Adding a new element to
test_map
should not causedata.cloudinit_config.config["itemA"]
to get read on plan and outputconfig_id
should not show as "known after apply", as the template output has not changed.Actual Behavior
Adding a new element to
test_map
causesdata.cloudinit_config.config["itemA"]
to get read on plan and outputconfig_id
shows as "known after apply".The code above is a contrived example but in real world usage a
data.cloudinit_config
is likely referenced in theuser_data
field of a cloud instance and so such a change, when the output has not actually changed, leads to unnecessary resource replacement and possibly destructive behaviour.Steps to Reproduce
terraform apply
. Noteconfig_id
outputterraform plan
. Noteconfig_id
is now "(known after apply)" despite not changingterraform apply
. Note thatconfig_id
output is the same as before, indicating nothing actually changedHow much impact is this issue causing?
Medium
Logs
https://gist.github.com/euanhunteratom/e81bc7cba42696779a1fea85a77faa42
Additional Information
Gist log is from the step 3 in the reproduction.
This issue seems to have something to do with the interaction between
content
,templatefile
, and a resource with multiple instances usingfor_each
. The workaround (see below) involves moving thetemplatefile
to a local; and using a resource with only a single instance or static values in the template does not trigger this issue. So, there is something abouttemplatefile
being directly used ascontent
where the template references a resource which is planned to have a new instance added that triggers this issue.Workaround
I found a workaround for this issue while trying to fix where this came up in our TF code. Moving
templatefile
to a local and referencing that instead seems to fix this issue. E.g.replace the
data "cloudinit_config" "config"
in the reproduction code withWith this change, step (3) of the reproduction only shows the expected since resource add and not a change to
config_id
.Code of Conduct
The text was updated successfully, but these errors were encountered: