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 data source for retrieving multiple GCS buckets from a project #10444

Conversation

bestefreund
Copy link
Contributor

@bestefreund bestefreund commented Apr 14, 2024

Adds a new data source "data_google_storage_buckets", allowing to retrieve multiple GCS buckets from a project.

Fixes: hashicorp/terraform-provider-google#17845

Release Note Template for Downstream PRs (will be copied)

`google_storage_buckets`

@github-actions github-actions bot requested a review from BBBmau April 14, 2024 21:02
Copy link

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

@BBBmau, 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 need reviewer's approval to run presubmit tests label Apr 14, 2024
@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from 7be1c28 to cd71348 Compare April 15, 2024 13:38
@modular-magician modular-magician added service/storage and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Apr 15, 2024
@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, 309 insertions(+))
google-beta provider: Diff ( 4 files changed, 309 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 92
Passed tests: 85
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
TestAccDataSourceGoogleStorageBuckets_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from cd71348 to f4e5a0e Compare April 15, 2024 17:37
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 15, 2024
@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from f4e5a0e to aec48ca Compare April 15, 2024 19:23
@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from aec48ca to 2c5dfef Compare April 16, 2024 15:52
@bestefreund
Copy link
Contributor Author

bestefreund commented Apr 17, 2024

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

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

@BBBmau
Please, take a look.

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 17, 2024
@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, 311 insertions(+))
google-beta provider: Diff ( 4 files changed, 311 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 92
Passed tests: 85
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
TestAccDataSourceGoogleStorageBuckets_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

@bestefreund
Copy link
Contributor Author

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

Please fix these to complete your PR. View the build log or the debug log for each test

@BBBmau
Thanks for starting.
Please, let me know what the issue is and if I can contribute anything to the solution.
Unfortunately, I have no access to the build logs of the VCR test.
A few moments ago I ran all tests in my local environment and every test, including TestAccDataSourceGoogleStorageBuckets_basic, ran smoothly without any issue.

TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/storage -v -run=TestAccDataSourceGoogleStorageBuckets_ -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccDataSourceGoogleStorageBuckets_basic
=== PAUSE TestAccDataSourceGoogleStorageBuckets_basic
=== CONT  TestAccDataSourceGoogleStorageBuckets_basic
--- PASS: TestAccDataSourceGoogleStorageBuckets_basic (14.37s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/storage  14.416s

@BBBmau
Copy link
Collaborator

BBBmau commented Apr 17, 2024

Took a look and it could be something to do with the ordering of buckets, this is the output from the error message:

 vcr_utils.go:152: Step 1/1 error: Check failed: Check 10/13 error: data.google_storage_buckets.all: Attribute 'buckets.0.name' expected "tf-bucket-test-1-0j9dezonpv", got "01utcv4zm2"

looking at the API responses both buckets are using the same name:

---[ REQUEST ]---------------------------------------
GET /storage/v1/b/tf-bucket-test-1-0j9dezonpv/o?alt=json&prettyPrint=false&versions=true HTTP/1.1
Host: storage.googleapis.com
User-Agent: google-api-go-client/0.5 Terraform/1.2.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google-beta/acc
X-Goog-Api-Client: gl-go/1.21.9 gdcl/0.171.0
Accept-Encoding: gzip


-----------------------------------------------------
2024/04/17 17:35:21 [DEBUG] Google API Request Details:
---[ REQUEST ]---------------------------------------
GET /storage/v1/b/tf-bucket-test-2-0j9dezonpv/o?alt=json&prettyPrint=false&versions=true HTTP/1.1
Host: storage.googleapis.com
User-Agent: google-api-go-client/0.5 Terraform/1.2.5 (+https://www.terraform.io) Terraform-Plugin-SDK/2.33.0 terraform-provider-google-beta/acc
X-Goog-Api-Client: gl-go/1.21.9 gdcl/0.171.0
Accept-Encoding: gzip

@bestefreund
Copy link
Contributor Author

bestefreund commented Apr 17, 2024

Thank you for taking a look and sharing the information.

I got a similar error when I was testing in my own project.

It originated in that the test project wasn't clean and contained already buckets, which was why the response contained unexpected results.

Cleaning up the test project from all buckets resolved the issue in my case.

Maybe, the test project from VCR-Test contains buckets that compromise the results.

Would you mind to clean up the test project and re-run the pipeline?
Or using another clean project?

func TestAccDataSourceGoogleStorageBuckets_basic(t *testing.T) {
t.Parallel()

project := envvar.GetTestProjectFromEnv()
Copy link
Collaborator

@BBBmau BBBmau Apr 17, 2024

Choose a reason for hiding this comment

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

looking more into this, this is one of those cases where we'd want to also create a project as part of the test so that the environment stays consistent. This makes it so that only the two buckets that are created here will only exist for this project that's also created as part of running the test.

This is done in other resources, an example of this is found here:

resource "google_project" "acceptance" {
name = "tf-test-%{random_suffix}"
project_id = "tf-test-%{random_suffix}"
org_id = "%{organization}"
billing_account = "%{billing_account}"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really good approach.
Thank you very much!

I'd like to implement it, but I'm restricted to a single project and cannot run the tests locally then.

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 followed your suggestion and I've extended the test case with the deployment of it's own project to have a clean test environment.

Please, have a look on it.

@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from 2c5dfef to ca86d41 Compare April 17, 2024 19:22
@github-actions github-actions bot requested a review from BBBmau April 17, 2024 19:23
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 17, 2024
@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from ca86d41 to 65b5483 Compare April 17, 2024 20:56
@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 18, 2024
@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, 322 insertions(+))
google-beta provider: Diff ( 4 files changed, 322 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 92
Passed tests: 85
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
TestAccDataSourceGoogleStorageBuckets_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from 65b5483 to a169166 Compare April 18, 2024 06:52
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 18, 2024
@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from a169166 to f2044e1 Compare April 18, 2024 07:19
@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 22, 2024
@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, 323 insertions(+))
google-beta provider: Diff ( 4 files changed, 323 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 93
Passed tests: 86
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
TestAccDataSourceGoogleStorageBuckets_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

@bestefreund bestefreund force-pushed the feature/data_source_google_storage_buckets branch from f2044e1 to dd32a16 Compare April 22, 2024 20:06
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 22, 2024
@bestefreund
Copy link
Contributor Author

bestefreund commented Apr 24, 2024

@BBBmau
Please, restart the pipeline and have a look again.

I've fixed a typo and the acceptance test with the included project succeeded with my development environment.

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 25, 2024
@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, 323 insertions(+))
google-beta provider: Diff ( 4 files changed, 323 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 93
Passed tests: 86
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
TestAccDataSourceGoogleStorageBuckets_basic

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

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

Copy link
Collaborator

@BBBmau BBBmau left a comment

Choose a reason for hiding this comment

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

All looks great, Thanks for the contribution!

@BBBmau BBBmau merged commit 0afb6b5 into GoogleCloudPlatform:main Apr 25, 2024
11 checks passed
@bestefreund
Copy link
Contributor Author

Thanks for your patience and the review!

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 data source for retrieving multiple GCS buckets from a project
4 participants