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 #17815

Conversation

modular-magician
Copy link
Collaborator

fixes #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. #16217.
    This bug cannot be fixed with the similar way in Fix the bug for computed labels and annotations GoogleCloudPlatform/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 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

…ashicorp#10401)

[upstream:c1e30ed89595203b0b2bf597b7f1cd597eed17e5]

Signed-off-by: Modular Magician <magic-modules@google.com>
@modular-magician modular-magician merged commit 450b311 into hashicorp:main Apr 10, 2024
4 checks passed
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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