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

Add project_number field to google_storage_bucket resource and datasource, enable providing project argument to data source #10312

Merged
merged 4 commits into from
Mar 28, 2024

Conversation

SarahFrench
Copy link
Contributor

@SarahFrench SarahFrench commented Mar 28, 2024

Closes hashicorp/terraform-provider-google#17166

This PR aims to address an edge case where users do not want to give the identity/service account used by Terraform permissions on the Compute API and want to provision GCS buckets. Previously if a project name was not supplied to the data source via provider defaults then the data source would:

  • retrieve information about the bucket from the Storage API, including the project number it's linked to
  • call the Compute API to get a human-readable project id for that project number, and use that to populate the project field

By letting users set the project field on the data source they can avoid that call to the Compute API. There is a chance that the project id they supply doesn't match the project number linked to the GCS bucket. This isn't ideal, but was OK'd during triage as it matches the existing behaviour on import.

This PR also adds a new field, project_number, to surface the information returned from the Storage API which is guaranteed to be accurate. This enables users to perform any checks etc to verify the project id and number are a correct pairing.

Release Note Template for Downstream PRs (will be copied)

storage: added `project_number` attribute to `google_storage_bucket` resource and data source
storage: added ability to provide `project` argument to `google_storage_bucket` data source. This will not impact reading the resource's data, instead this helps users avoid calls to the Compute API within the data source.

This does not impact the data source retrieving data about the bucket. Providing this argument only serves to prevent a call to the Compute API to populate that field after reading the bucket's data. Storage API only returns the project number, so Compute API is used to get the project id in the absence of a user-supplied value.
… project argument can be provided and is non-functional (therefore can be set to "foobar" without negatice impact)
@SarahFrench SarahFrench requested a review from zli82016 March 28, 2024 12:21
@SarahFrench SarahFrench marked this pull request as ready for review March 28, 2024 12:21
@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 ( 4 files changed, 85 insertions(+), 7 deletions(-))
google-beta provider: Diff ( 4 files changed, 85 insertions(+), 7 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 91
Passed tests: 84
Skipped tests: 6
Affected tests: 1

Click here to see the affected service packages
  • storage

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
TestAccDataSourceGoogleStorageBucket_avoidComputeAPI

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

$\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

@zli82016
Copy link
Member

By letting users set the project field on the data source they can avoid that call to the Compute API. There is a chance that the project id they supply doesn't match the project number linked to the GCS bucket. This isn't ideal, but was OK'd during triage as it matches the existing behaviour on import.

Instead of adding the project field to data source, maybe we can consider creating a new function for data source, similar to setStorageBucket, but without the project checking code. It will avoid the incorrect project provided by the users for the data source.

@SarahFrench
Copy link
Contributor Author

Yeah that's another option & I'm happy to pursue it. That function is trying to cover a lot of scenarios!

I'll probably pick that up next week, as I'm OOO Friday-Monday

@SarahFrench
Copy link
Contributor Author

Ah, I just thought. A change like that would be a breaking change for all users who are happy with the resource interacting with the Compute API. I'm opening this PR for a small minority of users who don't want Compute API to be used inside this data source but there may be users out there relying on this behaviour

@zli82016
Copy link
Member

zli82016 commented Mar 28, 2024

Ah, I just thought. A change like that would be a breaking change for all users who are happy with the resource interacting with the Compute API. I'm opening this PR for a small minority of users who don't want Compute API to be used inside this data source but there may be users out there relying on this behaviour

I see. I didn't realize that. We can go with the current change. Can we also add note for providing the correct project to the data source documentation ? Thanks.

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

Copy link
Member

@zli82016 zli82016 left a comment

Choose a reason for hiding this comment

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

LGTM if all of the checks pass.

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 91
Passed tests: 85
Skipped tests: 6
Affected tests: 0

Click here to see the affected service packages
  • storage

$\textcolor{green}{\textsf{All tests passed!}}$
View the build log

@SarahFrench
Copy link
Contributor Author

Thanks!

@SarahFrench SarahFrench merged commit b256de4 into main Mar 28, 2024
11 checks passed
pjotrekk pushed a commit to pjotrekk/magic-modules that referenced this pull request Apr 2, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
cmfeng pushed a commit to cmfeng/cmfeng-magic-modules that referenced this pull request Apr 5, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
hao-nan-li pushed a commit to hao-nan-li/magic-modules that referenced this pull request Apr 9, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
balanaguharsha pushed a commit to balanaguharsha/magic-modules that referenced this pull request Apr 19, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
balanaguharsha pushed a commit to balanaguharsha/magic-modules that referenced this pull request May 2, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
balanaguharsha pushed a commit to balanaguharsha/magic-modules that referenced this pull request May 2, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
pawelJas pushed a commit to pawelJas/magic-modules that referenced this pull request May 16, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
pengq-google pushed a commit to pengq-google/magic-modules that referenced this pull request May 21, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
Cheriit pushed a commit to Cheriit/magic-modules that referenced this pull request Jun 4, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
@SarahFrench SarahFrench deleted the SarahFrench-patch-gcs-bucket-projectnumbers branch June 10, 2024 13:50
pcostell pushed a commit to pcostell/magic-modules that referenced this pull request Jul 16, 2024
…source, enable providing `project` argument to data source (GoogleCloudPlatform#10312)
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.

Add opt-in behaviour to allow google_storage_bucket to be used without requiring Compute API permissions
3 participants