-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Sensitive variable with null default causes unnecessary plan to update in-place #32864
Comments
Thanks for this - we will look into it. The weird plan output is a case of #31887, but it looks like there might be something happening here with the sensitive value - perhaps a "sensitive null" vs a "non-sensitive null". |
I'm not 100% sure what's going on here either but I think it's worth noting that because this seems to be a map from the provider's perspective this is not a situation where setting it to null would be the same as omitting it entirely, because the provider will be able to observe the presence of the element in the map even though its value is a null. Therefore I would expect the UI to describe the map value like this when the value is null: variables = {
FOO = "bar"
TEST_ENV = null
} (I've illustrated what it would look like when creating the object for the first time above; of course if the whole value hasn't changed for an in-place update or a replace then as usual Terraform should hide the unchanged elements behind an "unchanged elements hidden" comment.) I don't think this answer can fully explain what happened here but I wonder if the diff renderer is incorrectly using the normal rules for object types like the resource config as a whole -- where an attribute being set to There seems to also be a quirk in the logic which decides whether the planned state differs from the prior state, making this appear as an "update in-place" even though nothing seems to be changing. That decision gets made in Terraform Core by comparing the prior state with the planned state, and my top-of-head theory (without looking at the code) is that something is incorrectly using |
Yes, the difference in the config is is that If there is a |
Ok, I have all the behavior traced out here. As I mentioned in the previous comment, the value returned by The reason there is no change shown with a literal When you add null value marked as sensitive by inserting the variable directly, the provider creates the same plan, but because core recorded the configuration as having a change in sensitivity, it must still be marked as a change in order to notify the user (the provider has no say in config sensitivity). The additional field however is now missing because the provider dropped it, so the plan ends displaying no changes being made. In this particular case the provider's behavior is technically allowed, as the prior state can be returned in lieu of the proposed state when there are no functional changes. The provider does not handle this correctly in any other case however, and will return the wrong value even when changes will be recorded, but Terraform will only warn about this in the logs due to the compatibility guarantees for legacy providers. I think we can actually catch this by filtering out the recorded marks for paths not present in the planned value, because there is a valid case where a provider is allowed to return a plan which does not exactly match the config. |
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. |
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/tatnat/60f079e4868b08beb61824afc7575ede
Expected Behavior
terraform plan
orterraform apply
should not detect any changes.Actual Behavior
terraform plan
orterraform apply
detects changes with the variable that hasdefault = null
as well assensitive = true
when the default is used. Whensensitive = false
then this behavior does not occur.Example:
Steps to Reproduce
terraform init
terraform plan
terraform plan
Additional Context
Under the
environment
andvariables
section, if conditional logic is used to set the variable such as:Then the expected behavior is actually produced (no changes detected).
Example:
References
No response
The text was updated successfully, but these errors were encountered: