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

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

zli82016
Copy link
Member

@zli82016 zli82016 commented Apr 9, 2024

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

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 90 insertions(+))
google-beta provider: Diff ( 3 files changed, 90 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2829
Passed tests: 2472
Skipped tests: 356
Affected tests: 1

Click here to see the affected service packages
all service packages are affected

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccSqlUser_postgresIAM

Get to know how VCR tests work

mmv1/third_party/terraform/tpgresource/annotations.go Outdated Show resolved Hide resolved
mmv1/third_party/terraform/tpgresource/annotations.go Outdated Show resolved Hide resolved
mmv1/third_party/terraform/tpgresource/labels.go Outdated Show resolved Hide resolved
mmv1/third_party/terraform/tpgresource/labels.go Outdated Show resolved Hide resolved
@modular-magician
Copy link
Collaborator

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccSqlUser_postgresIAM[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$
View the build log or the debug log for each test

@zli82016
Copy link
Member Author

zli82016 commented Apr 9, 2024

The failed test is unrelated

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 90 insertions(+))
google-beta provider: Diff ( 3 files changed, 90 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 2749
Passed tests: 2392
Skipped tests: 356
Affected tests: 1

Click here to see the affected service packages
all service packages are affected

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccSqlUser_postgresIAM

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccSqlUser_postgresIAM[Error message] [Debug log]

$\textcolor{red}{\textsf{Please fix these to complete your PR.}}$
View the build log or the debug log for each test

@zli82016 zli82016 merged commit c1e30ed into GoogleCloudPlatform:main Apr 10, 2024
11 of 12 checks passed
@zli82016 zli82016 deleted the computed-nested-labels-3 branch April 10, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provider produced inconsistent final plan. Adding labels to Cloud Run
4 participants