Skip to content

Make plugin-framework provider configuration code treat empty values like the SDK#8798

Merged
SarahFrench merged 14 commits into
mainfrom
make-pf-treat-empty-values-null
Sep 14, 2023
Merged

Make plugin-framework provider configuration code treat empty values like the SDK#8798
SarahFrench merged 14 commits into
mainfrom
make-pf-treat-empty-values-null

Conversation

@SarahFrench

@SarahFrench SarahFrench commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

This PR fixes hashicorp/terraform-provider-google#14255

This PR makes the plugin-framework code behave more like the SDK by ignoring empty strings, and is a bug fix to be included in a v4.x.x release. The bug it's fixing is an unintentional behaviour change introduced when the provider was muxed.

Later, I will remove this fix in 5.0.0, as an intentional breaking change as part of : hashicorp/terraform-provider-google#14447

Also, this PR changes some arbitrary strings from "123s" to "45s" as I realised that "123s" is changed to "2m3s" during the provider configuration logic. I thought this change would help avoid confusion if tests are updated in future to inspect where that second, parsed value is used.


If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Generated Terraform providers, and ran make test and make lint in the generated providers to ensure it passes unit and linter tests.
  • Ran relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read Write release notes before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

provider: fixed the provider so it resumes ignoring empty strings set in the `provider` block

@modular-magician

Copy link
Copy Markdown
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.

Terraform GA: Diff ( 8 files changed, 195 insertions(+), 148 deletions(-))
Terraform Beta: Diff ( 8 files changed, 195 insertions(+), 148 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3006
Passed tests 2710
Skipped tests: 296
Affected tests: 0

$\textcolor{green}{\textsf{All tests passed in REPLAYING mode.}}$
View the build log

@SarahFrench SarahFrench force-pushed the make-pf-treat-empty-values-null branch from 69d5653 to 2a7cffa Compare September 11, 2023 11:43
@SarahFrench

Copy link
Copy Markdown
Contributor Author

This PR currently contains all the unit tests I've managed to get approved and merged to main, unit tests I've got in open PRs, and code changes to make the PF config code behave more like the SDK config code w.r.t empty strings

@modular-magician

Copy link
Copy Markdown
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.

Terraform GA: Diff ( 3 files changed, 503 insertions(+), 133 deletions(-))
Terraform Beta: Diff ( 3 files changed, 503 insertions(+), 133 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3025
Passed tests 2728
Skipped tests: 297
Affected tests: 0

$\textcolor{green}{\textsf{All tests passed in REPLAYING mode.}}$
View the build log

@SarahFrench SarahFrench force-pushed the make-pf-treat-empty-values-null branch 2 times, most recently from ea3c199 to 78cee10 Compare September 13, 2023 14:03

@SarahFrench SarahFrench left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments to help with review

Comment thread mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb
Comment thread mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb
@SarahFrench SarahFrench force-pushed the make-pf-treat-empty-values-null branch from 78cee10 to 53a3cf4 Compare September 13, 2023 14:07
@SarahFrench SarahFrench force-pushed the make-pf-treat-empty-values-null branch from 53a3cf4 to d5f4195 Compare September 13, 2023 14:13
@modular-magician

Copy link
Copy Markdown
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.

Terraform GA: Diff ( 3 files changed, 238 insertions(+), 147 deletions(-))
Terraform Beta: Diff ( 3 files changed, 238 insertions(+), 147 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3037
Passed tests 2733
Skipped tests: 297
Affected tests: 7

Action taken

Found 7 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample|TestAccBigtableAppProfile_bigtableAppProfileAnyclusterExample|TestAccBigtableAppProfile_bigtableAppProfileSingleclusterExample|TestAccGKEHub2Scope_gkehubScopeBasicExample|TestAccGKEHub2ScopeIamBindingGenerated|TestAccGKEHub2ScopeIamMemberGenerated|TestAccGKEHub2ScopeIamPolicyGenerated

Get to know how VCR tests work

@modular-magician

Copy link
Copy Markdown
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample[Debug log]
TestAccBigtableAppProfile_bigtableAppProfileAnyclusterExample[Debug log]
TestAccBigtableAppProfile_bigtableAppProfileSingleclusterExample[Debug log]
TestAccGKEHub2Scope_gkehubScopeBasicExample[Debug log]
TestAccGKEHub2ScopeIamBindingGenerated[Debug log]
TestAccGKEHub2ScopeIamMemberGenerated[Debug log]
TestAccGKEHub2ScopeIamPolicyGenerated[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$
View the build log or the debug log for each test

@SarahFrench SarahFrench marked this pull request as ready for review September 13, 2023 17:32
Comment on lines +61 to +67
// Make the plugin framwork code behave like the SDK by ignoring zero values. This means re-setting zero values to null.
// This is added to fix https://github.com/hashicorp/terraform-provider-google/issues/14255 in a v4.x.x release
// TODO(SarahFrench) remove as part of https://github.com/hashicorp/terraform-provider-google/issues/14447 in 5.0.0
p.HandleZeroValues(ctx, data, diags)
if diags.HasError() {
return
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 5.0.0, when we stop ignoring empty strings provided in a user's Terraform configuration, I plan to delete this section and remove the HandleZeroValues function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding this functionality back for users that could not upgrade since 4.60 right? To give them access to remaining 4.x versions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's right. Users affected by hashicorp/terraform-provider-google#14255 could navigate the issue easily by removing empty strings from their provider config block, but that becomes less easy if they have a lot of different provider configs or if an empty string was 'baked into' a module that a user didn't have control over.

By making this change we're allowing any users on old provider versions to upgrade to the final 4.x.x version prior to 5.0.0 with everything behaving as they'd expect. Then they'll have the upgrade guide warning them about empty strings no longer being ignored in 5.0.0.

@SarahFrench SarahFrench requested a review from c2thorn September 13, 2023 17:45

@c2thorn c2thorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straightforward except for the batching bit, but looks correct.

@SarahFrench

SarahFrench commented Sep 14, 2023

Copy link
Copy Markdown
Contributor Author

The batching bit was a pain for me to figure out, but it works! I'll do some final manual testing tomorrow and will merge this PR then. Thanks for the approval! 🚀

…ntials=""` and `GOOGLE_CREDENTIALS` interact
@SarahFrench

SarahFrench commented Sep 14, 2023

Copy link
Copy Markdown
Contributor Author

Instead of manual testing, I've added an acceptance test in 16b27d4 that shows the behaviour (specifically for the bug mentioned in hashicorp/terraform-provider-google#14255) and how it's fixed following this PR. In future I'll update that test with another step when we intentionally reverse this bug fix in 5.0.0

@modular-magician

Copy link
Copy Markdown
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.

Terraform GA: Diff ( 4 files changed, 307 insertions(+), 147 deletions(-))
Terraform Beta: Diff ( 4 files changed, 307 insertions(+), 147 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3043
Passed tests 2745
Skipped tests: 298
Affected tests: 0

$\textcolor{green}{\textsf{All tests passed in REPLAYING mode.}}$
View the build log

@SarahFrench

Copy link
Copy Markdown
Contributor Author

Following addition of that test and all checks passing, I'll merge this PR once merging to main is resumed

@SarahFrench SarahFrench merged commit aaccd4a into main Sep 14, 2023
RileyHYZ pushed a commit to RileyHYZ/magic-modules that referenced this pull request Sep 15, 2023
…like the SDK (GoogleCloudPlatform#8798)

* Make PF config code change `project = ""` to null value before checking ENVs

* Make plugin framework config code change all empty strings in config to null values

* Fix defect in unit test for `project`, uncomment

* Uncomment empty string unit tests

* Fix defect in test; expeceted value should be null list

* Add handling of empty lists in `HandleZeroValues`

* Fix typo in comment

* Add test case asserting `impersonate_service_account` empty strings are overridden by an ENV

* Update SDK `batching` tests: rename test cases,  make it clear values are arbitary

* Update `HandleZeroValues` to handle `batching` argument

* Uncomment empty string test

* Change test inputs from 123s to 45s

This is because 123s is transformed to 2m3s, but 45s remains 45s

* Protect against Batching being null/unknown in `HandleZeroValues`

* Add non-VCR acceptance test that shows provider behaviour when `credentials=""` and `GOOGLE_CREDENTIALS` interact
joelkattapuram pushed a commit to joelkattapuram/magic-modules that referenced this pull request Sep 20, 2023
…like the SDK (GoogleCloudPlatform#8798)

* Make PF config code change `project = ""` to null value before checking ENVs

* Make plugin framework config code change all empty strings in config to null values

* Fix defect in unit test for `project`, uncomment

* Uncomment empty string unit tests

* Fix defect in test; expeceted value should be null list

* Add handling of empty lists in `HandleZeroValues`

* Fix typo in comment

* Add test case asserting `impersonate_service_account` empty strings are overridden by an ENV

* Update SDK `batching` tests: rename test cases,  make it clear values are arbitary

* Update `HandleZeroValues` to handle `batching` argument

* Uncomment empty string test

* Change test inputs from 123s to 45s

This is because 123s is transformed to 2m3s, but 45s remains 45s

* Protect against Batching being null/unknown in `HandleZeroValues`

* Add non-VCR acceptance test that shows provider behaviour when `credentials=""` and `GOOGLE_CREDENTIALS` interact
@SarahFrench SarahFrench deleted the make-pf-treat-empty-values-null branch September 26, 2023 13:43
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 configuration values supplied as empty strings/zero-values are no longer treated like null values (muxed provider, v4.60.2+)

3 participants