Skip to content
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

Show diff for computed nested labels fields when creating resources #2147

Conversation

modular-magician
Copy link
Collaborator

fixes hashicorp/terraform-provider-google#17756

Error

Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for module.cloud_run.google_cloud_run_service.main
│ to include new values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/google-beta" produced an invalid new value
│ for .metadata[0].labels: was null, but now

Resource google_cloud_run_service and google_cloud_run_domain_mapping have nested labels fields metadata.0.labels and metadata.0.annotations.

In the CustomizeDiff function SetMetadataLabelsDiff, SetNew is applied on "metadata" field with the object including terraform_labels and effective_labels. It introduced two bugs.

  1. when creating resource, computed metadata.0.labels and metadata.0.annotations fields don't appear in terraform plan
  2. After creating the resource with the normal labels value, and then updating the labels fields with the computed value will fail, similar to root labels field Error: Provider produced inconsistent final plan - "registry.terraform.io/hashicorp/google" produced an invalid new value for .terraform_labels: new element "date_modified" has appeared. hashicorp/terraform-provider-google#16217.
    This bug cannot be fixed with the similar way in Fix the bug for computed labels and annotations magic-modules#10182.
    The reason is that metadata.0.terraform_labels and metadat.0.effective_labels fields cannot be set to computed due to a bug that SetNew doesn't work on nested fields
    in terraform sdk SetNew does not work on nested fields hashicorp/terraform-plugin-sdk#459

The solution to fix these two bugs in my mind is to move terraform_labels and effective_labels to root level in provider release 6.0.
Before the release 6.0, the first bug can be fixed in this PR and I don't find an easy way to fix the second bug.

Release Note Template for Downstream PRs (will be copied)

cloudrun: fixed the bug that computed `metadata.0.labels` and `metadata.0.annotations` fields don't appear in terraform plan when creating resource `google_cloud_run_service` and `google_cloud_run_domain_mapping`

Derived from GoogleCloudPlatform/magic-modules#10401

…#10401)

[upstream:c1e30ed89595203b0b2bf597b7f1cd597eed17e5]

Signed-off-by: Modular Magician <[email protected]>
@modular-magician modular-magician requested a review from a team as a code owner April 10, 2024 19:04
@modular-magician modular-magician requested review from iyabchen and removed request for a team April 10, 2024 19:04
@modular-magician modular-magician merged commit 08b148d into GoogleCloudPlatform:main Apr 10, 2024
3 checks passed
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provider produced inconsistent final plan. Adding labels to Cloud Run
1 participant