Skip to content

Support full resource names in autokey_config.folder #11413

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

Merged
merged 5 commits into from
Sep 4, 2024

Conversation

tdbhacks
Copy link
Member

@tdbhacks tdbhacks commented Aug 9, 2024

Add pre_* custom code to drop the 'folders/' prefix from API requests, as well as a diff suppressor for the same reason. The ID also needs to be adjusted on post_create.

Side change: add a time delay after setting the autokey_config in the basic example, to try to address test flakiness (#18935)

NOTE: looking at the debug logs, I see the following error:

2024-08-09T16:37:55.977Z [WARN]  Provider "provider[\"registry.terraform.io/hashicorp/google-beta\"]" produced an unexpected new value for google_kms_autokey_config.example-autokeyconfig, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .folder: was cty.StringVal("folders/966201355962"), but now cty.StringVal("966201355962")

looking for guidance on whether my current approach is fine, or if this should be addressed in a different way.

Thank you!

Release Note Template for Downstream PRs (will be copied)

kms: updated the `google_kms_autokey_config` resource's `folder` field to accept values that are either full resource names (`folders/{folder_id}`) or just the folder id (`{folder_id}` only)

@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 ( 1 file changed, 8 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 4 files changed, 38 insertions(+), 145 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 7 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 38
Passed tests: 34
Skipped tests: 4
Affected tests: 0

Click here to see the affected service packages
  • kms

$\textcolor{green}{\textsf{All tests passed!}}$

View the build log

@tdbhacks tdbhacks marked this pull request as ready for review August 9, 2024 17:36
@github-actions github-actions bot requested a review from SarahFrench August 9, 2024 17:37
Copy link

github-actions bot commented Aug 9, 2024

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

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

@SarahFrench
Copy link
Contributor

Can I just check, is this PR to help with a situation where a user might set the folder argument to folder/123456 and this results in the provider creating a malformed URL: https://cloudkms.googleapis.com/v1/folders/folder/123456/autokeyConfig ? Is there a related GitHub issue you could link to?

@tdbhacks
Copy link
Member Author

Can I just check, is this PR to help with a situation where a user might set the folder argument to folder/123456 and this results in the provider creating a malformed URL: https://cloudkms.googleapis.com/v1/folders/folder/123456/autokeyConfig ? Is there a related GitHub issue you could link to?

You are spot on, this is to support the full resource name too in the folder argument, but avoid the duplicate folders/. No GitHub issue, but the internal chatter is at yaqs/2415509398479699968

@SarahFrench
Copy link
Contributor

I'm afraid I'm a HashiCorp employee so I can't see Google internal docs.

Does the internal discussion mention making changes to validation on the field so that users are only able to pass in values without the folder/ prefix? This wouldn't break any existing valid configurations using the resource. However if values like folder/123456 are returned from other resouces/data sources without a field that contains only 123456 I can see how users might have a lot of toil navigating that validation. Let me know your thoughts!

@tdbhacks
Copy link
Member Author

I'm afraid I'm a HashiCorp employee so I can't see Google internal docs.

Does the internal discussion mention making changes to validation on the field so that users are only able to pass in values without the folder/ prefix? This wouldn't break any existing valid configurations using the resource. However if values like folder/123456 are returned from other resouces/data sources without a field that contains only 123456 I can see how users might have a lot of toil navigating that validation. Let me know your thoughts!

ooops, apologies, my bad :)

As a summary:

  • the folder argument only supports IDs right now (eg. 123456789), though it's more of an implicit symptom of how the URLs are defined, because..
  • ..the URLs used in the .yaml resource definition expect such an ID, given that the folders/ prefix is hardcoded. See verbs definitions.
  • some users have expressed to us that it would be good to support both IDs (123456789) and full resource names (folders/123456789) as valid inputs for the folder argument
  • if I understand correctly, this wouldn't be a breaking change because ID-only values are still accepted after this change
  • as part of accepting full resource names, we need to adjust the URLs used, to avoid the folders/folders/123456789 issue that you identified correctly
  • my understanding of the diff suppressor is that it ensures 123456789 and folders/123456789 are considered the same for diff'ing purposes

Hope this helps, let me know if something doesn't make sense. @melinath and @zli82016 have chimed in on the internal discussions and can probably help here.

Copy link
Contributor

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

Some quick comments, including a required code change to re-add a sweeper to the Beta version of the provider.

url = strings.Replace(url, "folders/folders/", "folders/", 1)
folderValue := d.Get("folder").(string)
folderValue = strings.Replace(folderValue, "folders/", "", 1)
d.Set("folder", folderValue)
Copy link
Contributor

@SarahFrench SarahFrench Aug 14, 2024

Choose a reason for hiding this comment

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

Is it necessary to re-set (via d.Set) the value to be the original string with "folders/" removed? Is could be sufficient to just perform replacements of "folders/folders/" with "folders/" whenever a URL is being constructed using the folder value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, you're absolutely right, this was leftover from my initial attempt :) removed

Copy link
Contributor

Choose a reason for hiding this comment

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

The id issue raised below can be solved by this, like you said here. I can restore this on the PR for you

Add pre_* custom code to drop the 'folders/' prefix from API requests,
as well as a diff suppressor for the same reason. The ID also needs to
be adjusted on post_create.

Side change: add a time delay after setting the autokey_config in the
basic example, to try to address test flakiness (#18935)
@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 ( 1 file changed, 8 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 4 files changed, 32 insertions(+), 145 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 7 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 38
Passed tests: 33
Skipped tests: 4
Affected tests: 1

Click here to see the affected service packages
  • kms

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
  • TestAccKMSAutokeyConfig_kmsAutokeyConfigAllExample

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

$\textcolor{red}{\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$

View the build log or the debug log for each test

@tdbhacks
Copy link
Member Author

@SarahFrench re: test failure, this is a known issue, and apparently my attempt at fixing this by adding a timeout is not sufficient / the right approach? :( let me know if you notice something else that might need to be tweaked. I can try adding an even longer wait time, though I thought 15s would be enough..

@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 ( 2 files changed, 134 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 4 files changed, 34 insertions(+), 21 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 7 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 38
Passed tests: 33
Skipped tests: 4
Affected tests: 1

Click here to see the affected service packages
  • kms

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
  • TestAccKMSAutokeyConfig_kmsAutokeyConfigAllExample

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

$\textcolor{red}{\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$

View the build log or the debug log for each test

@tdbhacks
Copy link
Member Author

@SarahFrench alright, now that I've added back the sweeper, I've noticed that I'm probably handling the id incorrectly. What I'm doing right now is updating the id on post_create, which seemed like the right spot looking at where the code is injected, but I don't see that in the google-beta diffs, and if you look at the latest test failure, it's showing an id with the incorrect folders/folders/... value.

Thoughts?

@tdbhacks
Copy link
Member Author

One more note: I have a feeling the leftover change I had before (ie. modifying the folder value on pre_create and pre_update) was taking care of this ID issue, but I agree that the behavior would feel weird

@SarahFrench
Copy link
Contributor

Sorry, I've been pretty busy this past week! I'll review this PR on Monday

@github-actions github-actions bot requested a review from SarahFrench September 2, 2024 10:02
@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 ( 2 files changed, 134 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 4 files changed, 37 insertions(+), 21 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 7 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 40
Passed tests: 34
Skipped tests: 6
Affected tests: 0

Click here to see the affected service packages
  • kms

$\textcolor{green}{\textsf{All tests passed!}}$

View the build log

@tdbhacks
Copy link
Member Author

tdbhacks commented Sep 3, 2024

@SarahFrench thank you! Anything else I should change or double-check to make sure everything works correctly?

@SarahFrench
Copy link
Contributor

Nope, nothing more, I'll approve and merge. Thanks!

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.

3 participants