-
Notifications
You must be signed in to change notification settings - Fork 95
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
Dynamic type attribute does not work with sets #1008
Comments
Hey there @mawasile 👋🏻, thanks for reporting the issue with an example and sorry you're running into trouble here. I wasn't able to recreate this behavior with the dynamic attribute isolated in a sandbox, but the CLI output you shared seems to indicate that Terraform core is detecting a difference, but the plan renderer cannot find where the difference is. With dynamic schemas it can be a little difficult to pinpoint where that difference is being introduced. Looking through your provider code, I do see some code that could be a good place to start investigating. So This code is attempting to refresh a configuration value, so if the value being refreshed is not an exact match, Terraform will detect drift continuously, until the practitioner updates their configuration to match the new refreshed value. I would expect, since this value is not Regardless, I'd be interested to know if there is a difference being generated by the I'd start by looking at that piece of code, but I'd think that removing that refresh of the Let me know what you find! |
Hi @austinvalle, sorry for late response on that bug. Some time had passed since I've opened this issue and definitely something change so now my workaround with using The issue is in the following piece:
I've changed the attribute to be optional and computed since you are right it should be as it needs to be refreshed every time.
That also means, I can't remove refresh logic for my current versions: |
Now that I'm looking at the code again, I think I see what the issue could be. So first a little background on types in Terraform. Since you're using a dynamic configuration attribute, Terraform will decide what the type of the value is. With literals, the following would be determined as a # The literal for [ ] will always be a tuple if you're using a dynamic attribute
contact_customer_accounts = [
{
table_logical_name = "contact",
data_record_id = powerplatform_data_record.contact.id
}
] And with the contact_customer_accounts = toset([
{
table_logical_name = "contact",
data_record_id = powerplatform_data_record.contact.id
}
]) The reason this is important, is not only can differing values cause drift, but also differing types. My guess is that this piece of code is causing the "invisible" diff by refreshing the type from My guess is that the Terraform renderer UI doesn't have support for displaying when the values are equivalent, but the types are different (possible feature request?). If what I said above is what's happening, it could look like this: Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# powerplatform_data_record.account will be updated in-place
~ resource "powerplatform_data_record" "account" {
id = "830dc891-9b28-ef11-840a-000d3ab60f37"
- columns = (old type) -> (new type)
# (2 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy. The fix for that would be to ensure when you refresh values, that you preserve the original type, which might require a little more complicated logic here. (Some of the pains of working with dynamic data unfortunately) Let me know if that helps! |
thanks @austinvalle that did the trick! |
Module version
Relevant provider source code
resource implementation:
https://github.com/microsoft/terraform-provider-power-platform/blob/main/internal/powerplatform/services/data_record/resource_data_record.go
Terraform Configuration Files
Debug Output
apply.log and plan.log can be found here: https://gist.github.com/mawasile/f61ce8807e1011983b9089f97dba542b
Expected Behavior
We use dynamic type for "columns" attribute and inside that we also allow to create collection of values. if that collection is a list everything is working fine but when we use
toset()
then in terraform plan we get in-place update which is incorrect as nothing had changed. Just by removingtoset
incontact_customer_accounts
from the above example, fixes that issue.Actual Behavior
toset should not generate dirty state when used in dynamic attribute
Steps to Reproduce
terraform apply
terraform plan
=> plan is not emptyThe text was updated successfully, but these errors were encountered: