terraform-provider-googleworkspace
terraform-provider-googleworkspace copied to clipboard
`flattenCustomSchemas` does not sort a `googleworkspace_user`'s custom schemas, resulting in permadiff
Terraform Version
terraform: 1.0.2
provider: 0.4.0
Affected Resource(s)
- googleworkspace_user
Terraform Configuration Files
resource "googleworkspace_user" "foo" {
custom_schemas {
schema_name = "bar"
schema_values = jsonencode("Bar")
}
custom_schemas {
schema_name = "baz"
schema_values = jsonencode("Baz")
}
}
Debug Output
N/A
Panic Output
N/A
Expected Behavior
Stable terraform plan after terraform apply, showing no changes.
Actual Behavior
Sometimes (not always) I get a terraform plan that looks like this:
(roughly paraphrased from terraform plan output)
~ custom_schemas {
~ schema_name = "bar" -> "baz"
~ schema_values = jsonencode("Bar") -> jsonencode("Baz")
}
~ custom_schemas {
~ schema_name = "baz" -> "bar"
~ schema_values = jsonencode("Baz") -> jsonencode("Bar")
}
Steps to Reproduce
Create a user with multiple custom_schemas blocks. See note below
Important Factoids
The bug is at https://github.com/hashicorp/terraform-provider-googleworkspace/blob/14966537974769f23e597f44a212c0bc964d679e/internal/provider/resource_user.go#L1737 which calls range on the raw schemaAttrObj.(map[string]googleapi.RawMessage), which then results https://github.com/hashicorp/terraform-provider-googleworkspace/blob/14966537974769f23e597f44a212c0bc964d679e/internal/provider/resource_user.go#L1792 in simply being appended to the list, without regard to order.
The underlying Google API only guarantees that customSchemas is a map, and does not guarantee any order. The terraform-provider-googleworkspace needs to sort the responses in order to prevent this sort of terraform plan output.
Updated issue to clarify that this issue is still relevant in 0.4.0
Hi @megan07 @appilon ,
While reviewing @megan07 's fix in https://github.com/hashicorp/terraform-provider-googleworkspace/pull/139 , I notice that, while the permadiff no longer shows up in terrafomr plan or terraform apply, the permadiff does still show up in Note: Objects have changed outside of Terraform and attempting to run terraform apply -refresh-only does not eliminate that false drift detection.
Should this be re-opened?