SetNew in CustomizeDiff does not trigger diff on computed field when map value is set to empty string #371
Labels
bug
Something isn't working
subsystem/types
Issues and feature requests related to the type system of Terraform and our shims around it.
SDK version
Relevant provider source code
Terraform Configuration Files
Debug Output
https://gist.github.com/invidian/4f1d9d0b6f74f352aad892dab857a8fa
Expected Behavior
When using
SetNew
fromschema.ResourceDiff
on fields which areTypeMap
andComputed
, Terraform should properly write them and show them in diff, not ignore them.Actual Behavior
Field
input
, containing user input properly shows diff and gets updated in the state, but fieldresult
gets ignored and it's never corrected. This might be problematic, when one needs a Map, where the value can actually be an empty string.Related upstream issue flexkube/libflexkube#48 (comment).
Steps to Reproduce
main.go
file.go build -o terraform-provider-diffmap
.main.tf
file with following content:terraform init
.terraform apply -auto-approve
.cat terraform.tfstate
. Example output:Context
With terraform-provider-flexkube, I take user configuration, including TLS certificates and then transpile it to more complex structure, which is written to Terraform state to provide user friendly diff. Unfortunately, currently re-generating the certificates triggers inconsistent state, as certificate content is not known while planning. I would expect computed fields which has value set to empty string (
""
) to be seen in diff as "Known after apply", instead of just being ignored. UsingSetNewComputed
on sub-field produces error too.With "real world example", running Terraform twice or with proper
-target
serves as a workaround. To trigger inconsistent plan issue, one needs to runterraform taint tls_private_key.example
and thenterraform apply
.If this is like this by design, how can I avoid getting inconsistent plan in such case?
References
The text was updated successfully, but these errors were encountered: