magic-modules icon indicating copy to clipboard operation
magic-modules copied to clipboard

fix: added EmptyOrUnsetBlockDiffSuppress to the `scalingMode` field in resource `google_cloud_run_v2_service`

Open tamir-deep opened this issue 1 month ago • 6 comments

Fixes https://github.com/hashicorp/terraform-provider-google/issues/25457

According to the REST API, if not specified, it defaults to "AUTOMATIC". While https://github.com/GoogleCloudPlatform/magic-modules/pull/15808 fixes the case where the entire scaling block is missing and causing permadiff, it doesn't handle a case where the block only contains "min_instance_count = 0".

What happens is, if min_instance_count = 0 is the only field specified, the response from the API has the scaling = [] and so it's saved as in the terraform state file.

Release Note Template for Downstream PRs (will be copied)

See Write release notes for guidance.

cloudrunv2: fix permadiff when default values of the service `scaling` block are used by adding EmptyOrUnsetBlockDiffSuppress

tamir-deep avatar Dec 07 '25 20:12 tamir-deep

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@NickElliot, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

github-actions[bot] avatar Dec 07 '25 20:12 github-actions[bot]

@NickElliot This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

github-actions[bot] avatar Dec 11 '25 09:12 github-actions[bot]

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 ( 2 files changed, 4 insertions(+), 2 deletions(-)) google-beta provider: Diff ( 2 files changed, 4 insertions(+), 2 deletions(-))

Breaking Change(s) Detected

The following breaking change(s) were detected within your pull request.

  • Field scaling.scaling_mode default value changed from <nil> to AUTOMATIC on google_cloud_run_v2_service - reference

If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An override-breaking-change label can be added to allow merging.

modular-magician avatar Dec 11 '25 21:12 modular-magician

Tests analytics

Total tests: 84 Passed tests: 65 Skipped tests: 9 Affected tests: 10

Click here to see the affected service packages
  • cloudrunv2

Action taken

Found 10 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccCloudRunV2ServiceIamBindingGenerated
  • TestAccCloudRunV2ServiceIamMemberGenerated
  • TestAccCloudRunV2ServiceIamPolicyGenerated
  • TestAccCloudRunV2Service_cloudrunv2ServiceBasicExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceFullUpdate
  • TestAccCloudRunV2Service_cloudrunv2ServiceGpuExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceSqlExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceWithDefaultUriDisabled
  • TestAccCloudRunV2Service_cloudrunv2ServiceWithResourcesRequirements
  • TestAccCloudRunV2Service_cloudrunv2ServiceWithServiceMinInstances

Get to know how VCR tests work

modular-magician avatar Dec 11 '25 21:12 modular-magician

🟢 Tests passed during RECORDING mode: TestAccCloudRunV2ServiceIamBindingGenerated [Debug log] TestAccCloudRunV2ServiceIamMemberGenerated [Debug log] TestAccCloudRunV2ServiceIamPolicyGenerated [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceBasicExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceFullUpdate [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceGpuExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceSqlExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceWithDefaultUriDisabled [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceWithServiceMinInstances [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🔴 Tests failed during RECORDING mode: TestAccCloudRunV2Service_cloudrunv2ServiceWithResourcesRequirements [Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

modular-magician avatar Dec 11 '25 22:12 modular-magician

min_instance_count "0" is already the default according to https://docs.cloud.google.com/run/docs/configuring/min-instances#setting-service-level

"By default, container instances have service-level minimum instances turned off, with a setting of 0."

The "AUTOMATIC" is also a default if not specified as stated here: https://docs.cloud.google.com/run/docs/reference/rest/v2/projects.locations.services#scalingmode

When explicitly setting it to "AUTOMATIC" as a default value, the API response contains the service scaling object properly with all of its fields (which in turn, all the default values of this object are saved in the Terraform state file). Hence why it's the "simplest" fix here though I definitely agree it's not clean due to the default value causing a breaking change.

I reverted the default value and set the EmptyOrUnsetBlockDiffSuppress on the scalingMode field. I tested it with no scaling block, using default values from the API itself and it seems to work. While using default values such as min_instance_count = 0 in the scaling now, they don't get written to the state. Terraform doesn't detect it as a diff. Same goes for the rest of the fields in the block.

tamir-deep avatar Dec 12 '25 07:12 tamir-deep

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 ( 1 file changed, 6 insertions(+), 5 deletions(-)) google-beta provider: Diff ( 1 file changed, 6 insertions(+), 5 deletions(-))

modular-magician avatar Dec 12 '25 22:12 modular-magician

Tests analytics

Total tests: 84 Passed tests: 66 Skipped tests: 9 Affected tests: 9

Click here to see the affected service packages
  • cloudrunv2

Action taken

Found 9 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccCloudRunV2ServiceIamBindingGenerated
  • TestAccCloudRunV2ServiceIamMemberGenerated
  • TestAccCloudRunV2ServiceIamPolicyGenerated
  • TestAccCloudRunV2Service_cloudrunv2ServiceBasicExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceFullUpdate
  • TestAccCloudRunV2Service_cloudrunv2ServiceGpuExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceSqlExample
  • TestAccCloudRunV2Service_cloudrunv2ServiceWithDefaultUriDisabled
  • TestAccCloudRunV2Service_cloudrunv2ServiceWithServiceMinInstances

Get to know how VCR tests work

modular-magician avatar Dec 12 '25 22:12 modular-magician

🟢 Tests passed during RECORDING mode: TestAccCloudRunV2ServiceIamBindingGenerated [Debug log] TestAccCloudRunV2ServiceIamMemberGenerated [Debug log] TestAccCloudRunV2ServiceIamPolicyGenerated [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceBasicExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceFullUpdate [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceGpuExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceSqlExample [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceWithDefaultUriDisabled [Debug log] TestAccCloudRunV2Service_cloudrunv2ServiceWithServiceMinInstances [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

modular-magician avatar Dec 12 '25 22:12 modular-magician