-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
v0.15.4 replaces resources on "Optional+Computed" attributes #29028
Comments
Hi @yanndegat, The terraform changes you've mentioned in the linked issue are not related to any plan changes, and only serve to provide more information for the user to see how resource change outside of terraform. They cause no difference in the plan and apply operations of terraform. The behavior here would be explained by the resource returning If the resource is ensuring that a computed value is set and remains unchanged, then you may have an issue with the plugin SDK. Since you are not setting an initial value (which appears to be the case as the output is |
hi @jbardin I'm not sure i get your point as it's quite complex to express.
so something must have been introduced into the core that changes that behavior? do you see something wrong on the ovh provider's side ? which could have worked up to 0.15.3 but not after ? thanks a lot |
btw:
on terraform v0.15.3, the resource doesn"t return null on the first apply. it only does since terraform v0.15.4. this is what annoys me. |
Thanks @yanndegat, I'll look through that set of commits and see if there is anything which looks related. Unusual behavior like this is often accompanied by warnings in the core logs. Can you see if there is any info there about the values returned by this resource? |
Ok, so my bad: it doesn't work in terraform v0.15.3 either. but in terraform v0.13.6
BTW, i don't get why it tells "the provider uses the legacy sdk", while it uses the sdk/v2 ? |
From Terraform's perspective, the plugin sdk/v2 is still the same legacy SDK, it just contains some backwards incmpatible changes from the original v1 SDK. It cannot make use of the full type system used in Terraform, and will produce certain inconsistencies that cannot be avoided, which is why we must allow these results and can only log them as warnings. This is likely a result of the more precise planning that is available in 0.14, which is being tripped up by the unexpected change, but I'm not sure how exactly that is happening. We can see that although terraform does not expect the |
ok. so what's the new non legacy sdk ?
ok. I'm not sure to get it properly. Said another way, how can we make an attribute optional, and if unset, let the api return the default value ? but if the user later change the attribute, then the resource is recreated ? To me, the tuple : Optional: true, Computed: True, ForcesNew: true: should do the the trick ? |
The latest SDK is being developed here: https://github.com/hashicorp/terraform-plugin-go, in conjunction with the existing SDK project here https://github.com/hashicorp/terraform-plugin-sdk.
This is more a question for the SDK, since the handling of these is outside of Terraform. I think this combination should work as you have described in many cases, though one major problem here is that it will not let a user revert to a default with replacement. Because the value is also "computed", when the user removes the value from the configuration terraform is going to treat that as computed by the provider and not cause any changes. The new plugin protocol does now include the information for providers to manually detect this, but the existing SDK cannot access it. Due to the complications around detecting if the user set or unset the value it's often easier to separate the configuration attributes ("inputs") from computed values ("outputs"). This way you have better control over the lifecycle of the desired version and the default. Aside from the noted complications above however, I don't think that is the root of your problem, and this looks like it should still be working in the simple case shown as long as the provider is consistently setting the |
ok. i'll try to upgrade to provider to the new sdk then. still it may require some time to integrate it properly. Meanwhile, i don't see what i have to do to "consistently" set the version attribute. IMHO, the https://github.com/ovh/terraform-provider-ovh/blob/master/ovh/resource_cloud_project_kube.go#L143 there's only one create method, which always returns the "read" method. i'll try to run it in debug to see if the api is always returning the value. |
This does seem like a rather baffling behavior, indeed. Unfortunately it seems to be sitting right at the integration point between Terraform Core and the SDK, so it's kinda hard to think through what's going on here, but after some thought experiment I think this behavior must be something odd happening inside the SDK rather than in Terraform Core. To try to illustrate why I'll summarize my understanding of what Terraform Core would be doing for this second
Your particular resource type doesn't implement Unfortunately this is where things get pretty murky, because the main logic in the SDK is One thing that could be interesting to try to gather some more information is to temporarily add a CustomizeDiff: func (ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
old, new := d.GetChange("version")
log.Printf("[DEBUG] version in diff is %q -> %q", old, new)
return nil
} Given what you initially reported, I would expect this to log the following:
If you see something different, that could indicate that I've been wrong in my assumptions so far and the problem may lurk somewhere other than where I think it does. Otherwise though, I think we'll probably end up referring this to the SDK team, who can hopefully offer a more complete explanation of the SDK side of the behavior here, from which we may be able to identify an alternative approach that avoids the problem. |
hi @apparentlymart / @jbardin i finally found the root cause of my issue. explaining why i've been misleaded several times. it has been released 2 times: once without the patch fixing the version, once with it. But the second release failed to update the registry and overwrite the first one. thank you very much for the time you spent trying to help us. regards |
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
Expected Behavior
The First apply should have output the "version" attribute in the outputs.
The Second apply shouldn't detect any change
Actual Behavior
First apply:
Second plan:
Steps to Reproduce
terraform init
terraform apply
terraform plan
Additional Context
This behavior is introduced by terraform 0.15.4. The same plan has been tested with terraform 0.15.3 and works as expected.
This has been reproduced up to terraform 1.0.0 version.
The version attribute is defined as :
https://github.com/ovh/terraform-provider-ovh/blob/master/ovh/resource_cloud_project_kube.go#L38
References
ovh/terraform-provider-ovh#204
The text was updated successfully, but these errors were encountered: