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

fixed artifact_registry_repository permadiff in unordered array #9376

Merged
merged 9 commits into from
Dec 1, 2023

Conversation

Subserial
Copy link
Contributor

@Subserial Subserial commented Oct 27, 2023

Suppress diff of artifact_registry_repository.virtual_repository_config.upstream_policies order using set semantics.
Fixes hashicorp/terraform-provider-google#16381

Release Note Template for Downstream PRs (will be copied)

artifactregistry: fixed permadiff due to unsorted `virtual_repository_config` array in `google_artifact_registry_repository`

@modular-magician
Copy link
Collaborator

Hello! I am a robot. It looks like you are a: Community Contributor Googler Core Contributor. Tests will require approval to run.

@trodge, 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.

@modular-magician modular-magician added the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Oct 27, 2023
@Subserial
Copy link
Contributor Author

How do I get magician to read my account as a Googler?

@trodge
Copy link
Contributor

trodge commented Oct 30, 2023

How do I get magician to read my account as a Googler?

The magician would have checked your membership using the GitHub api for the googlers and GoogleCloudPlatform orgs. If you recently made your membership public perhaps it had not yet reached the API when the magician made the request.

Sorry for the delay.

@modular-magician modular-magician removed the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Oct 30, 2023
@modular-magician
Copy link
Collaborator

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

Breaking Change(s) Detected

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

  • Field virtual_repository_config.upstream_policies changed from TypeList to TypeSet on google_artifact_registry_repository - 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.

Diff report

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

Terraform GA: Diff ( 1 file changed, 29 insertions(+), 23 deletions(-))
Terraform Beta: Diff ( 1 file changed, 29 insertions(+), 23 deletions(-))
TF Conversion: Diff ( 1 file changed, 1 insertion(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 3184
Passed tests 2859
Skipped tests: 325
Affected tests: 0

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

@melinath
Copy link
Member

@Subserial drive-by comment: see go/terraform-contribution-guide#before-you-begin for more details

Copy link
Contributor

@trodge trodge left a comment

Choose a reason for hiding this comment

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

Unfortunately, you will need to find a different way to fix this bug, since making a list into a set would be a breaking change for existing users. See this comment for details.

When such a way is found, please re-request review on this PR.

@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.

Terraform GA: Diff ( 1 file changed, 44 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 1 file changed, 44 insertions(+), 2 deletions(-))
TF Conversion: Diff ( 1 file changed, 42 insertions(+))

@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.

Terraform GA: Diff ( 1 file changed, 44 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 1 file changed, 44 insertions(+), 2 deletions(-))
TF Conversion: Diff ( 1 file changed, 42 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 3206
Passed tests 2880
Skipped tests: 325
Affected tests: 1

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
TestAccLoggingProjectSink_updatePreservesCustomWriter

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccLoggingProjectSink_updatePreservesCustomWriter[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

@Subserial
Copy link
Contributor Author

I'm not sure what the requested change feature in Github is, but otherwise I've updated the strategy for addressing the permadiff.

Copy link
Contributor

@trodge trodge left a comment

Choose a reason for hiding this comment

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

"Request changes" just means make changes to your PR and then re-request review when you want your reviewer to take another look.

Edit- also take a look at my third comment before addressing the other two, they didn't come out in the order I expected.

}
hashFunc := func(val any) string {
x := val.(map[string]any)
return fmt.Sprintf("[id:%v priority:%v repository:%v]", x["id"], x["priority"], x["repository"])
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is equivalent to

return fmt.Sprintf("%v", x)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if golang is consistent with map key order within the same process. This was to prevent two maps from outputting different strings with the same information.

}

func arrayDiffSuppress(old, new []any, hashFunc func(x any) string) bool {
oldMap := map[string]bool{}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're just making a set here we can use map[string]struct{}, if we need a boolean value that's distinct from omitting the key, use map[string]bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with schema.Set.

# limitations under the License.
-%>
func upstreamPoliciesDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
log.Printf("%v, %v, %v\n", k, old, new)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we have a reason to do this by hand, it would probably be better to use the sdk provided set methods such as schema.NewSet and Set.Equal to ensure we don't miss anything with casting the types around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! Switched over to using schema.Set.

@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.

Terraform GA: Diff ( 1 file changed, 24 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 1 file changed, 24 insertions(+), 2 deletions(-))
TF Conversion: Diff ( 1 file changed, 21 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 3226
Passed tests 2893
Skipped tests: 329
Affected tests: 4

Action taken

Found 4 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccDataprocClusterIamPolicy|TestAccDataprocJobIamPolicy|TestAccLoggingProjectSink_updatePreservesCustomWriter|TestAccDataSourceGoogleServiceAccountJwt

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataprocClusterIamPolicy[Debug log]
TestAccDataprocJobIamPolicy[Debug log]
TestAccDataSourceGoogleServiceAccountJwt[Debug log]

Rerun these tests in REPLAYING mode to catch issues

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


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccLoggingProjectSink_updatePreservesCustomWriter[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

Copy link
Contributor

@trodge trodge left a comment

Choose a reason for hiding this comment

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

LGTM, but it looks like the test isn't running in VCR. Would it be possible to modify an existing test so that it will be re-recorded? Ideally we would just add another element to upstream_policies to make sure the diff suppress works as expected.

}
hashFunc := func(val any) int {
x := val.(map[string]any)
hashStr := fmt.Sprintf("[id:%v priority:%v repository:%v]", x["id"], x["priority"], x["repository"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance we could see a panic if val isn't a map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible if the returned field doesn't fit the expected schema, somehow. I updated it to avoid panicking on a bad cast.

@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.

Terraform GA: Diff ( 3 files changed, 60 insertions(+), 14 deletions(-))
Terraform Beta: Diff ( 3 files changed, 60 insertions(+), 14 deletions(-))
TF Conversion: Diff ( 1 file changed, 21 insertions(+))
TF OiCS: Diff ( 1 file changed, 18 insertions(+), 6 deletions(-))

@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.

Terraform GA: Diff ( 3 files changed, 73 insertions(+), 14 deletions(-))
Terraform Beta: Diff ( 3 files changed, 73 insertions(+), 14 deletions(-))
TF Conversion: Diff ( 1 file changed, 34 insertions(+))
TF OiCS: Diff ( 1 file changed, 18 insertions(+), 6 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 3236
Passed tests 2902
Skipped tests: 330
Affected tests: 4

Action taken

Found 4 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccArtifactRegistryRepository_artifactRegistryRepositoryVirtualExample|TestAccLoggingProjectSink_updatePreservesCustomWriter|TestAccDataSourceGoogleServiceAccountJwt|TestAccDataSourceGoogleServiceAccountIdToken_impersonation

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccArtifactRegistryRepository_artifactRegistryRepositoryVirtualExample[Debug log]
TestAccDataSourceGoogleServiceAccountJwt[Debug log]
TestAccDataSourceGoogleServiceAccountIdToken_impersonation[Debug log]

Rerun these tests in REPLAYING mode to catch issues

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


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccLoggingProjectSink_updatePreservesCustomWriter[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

@Subserial
Copy link
Contributor Author

The failed test is not caused by this pull request.

@trodge trodge merged commit 9988136 into GoogleCloudPlatform:main Dec 1, 2023
14 of 15 checks passed
trodge pushed a commit to trodge/magic-modules that referenced this pull request Dec 8, 2023
…leCloudPlatform#9376)

* fixed permadiff in unordered array

* changed permadiff fix strategy for upstream policies

* removed no-op field

* change diff semantics to use schema.Set

* updated virtual example with intentional out-of-order priorities

* update virtual policy comparison to not panic on bad cast (if possible)
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.

Permadiff on google_artifact_registry_repository.virtual_repository_config
4 participants