Open invidian opened 4 years ago
I'm also doing some testing now with NewValueKnown
and it seems, that this function incorrectly returns true
for input
field in the example I provided:
func resourceTestDiff(d *schema.ResourceDiff, m interface{}) error {
if d.NewValueKnown("input") {
log.Printf("new value known")
}
And if I run terraform plan
, I get the message logged every time. That doesn't seem like the right behavior either.
@invidian I'm not entirely sure but I was seeing something similar and this is my hackaround https://github.com/mingfang/terraform-provider-k8s/blob/master/k8s/k8s.go#L99
@invidian I'm not entirely sure but I was seeing something similar and this is my hackaround https://github.com/mingfang/terraform-provider-k8s/blob/master/k8s/k8s.go#L99
Thanks for the hint @mingfang. Unfortunately, from my testing, it seems that what you're doing is to remove the extra parameters from diff, and what I need is to trigger additional diff on map field. I've tried injecting some attributes, rather than removing them, but I don't know Terraform internals very well, so I still didn't figure out how to do that.
I think for the workaround I'll just set top field as NewComputed
, to at least avoid Terraform giving the error to the user. The downside is not so accurate diff provided to the user.
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 https://github.com/flexkube/libflexkube/issues/48#issuecomment-605352824.
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