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

feat: add HNS support for storage bucket #11852

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

gurusai-voleti
Copy link

@gurusai-voleti gurusai-voleti commented Sep 27, 2024

Adds support to enable hierarchical_namespace for storage buckets

Release Note Template for Downstream PRs (will be copied)

storage: added 'hierarchical_namespace' to 'google_storage_bucket' resource

Copy link

google-cla bot commented Sep 27, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

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

@rileykarson, 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 Sep 27, 2024
@gurusai-voleti gurusai-voleti marked this pull request as draft September 27, 2024 07:26
"hierarchical_namespace": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

I think the whole block should be configured with ForceNew behavior. This block can not be changes or remove from the config once it is configured, Right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes updated block with ForceNew

@kautikdk
Copy link
Member

Apart from the field behavior comments, Please check bucket deletion. If the bucket is configured with force_destroy=true then while deleting bucket, it should delete all the folders and objects within the it. This may require changing logic in deletion operation.
Also please add documentation of the newly added fields and PR description as well.

Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Default: false,
Copy link
Member

Choose a reason for hiding this comment

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

No need to set Default: false, If it is not API default. I believe this field should marked with Required=true as I can see that empty "hierarchical_namespace" won't be returned in the API response.

Copy link
Author

Choose a reason for hiding this comment

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

removed Default

"enabled": {
Type: schema.TypeBool,
Default: false,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

Can remove this in favor of Required: true,

Copy link
Author

Choose a reason for hiding this comment

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

removed Optional and added required true

@gurusai-voleti
Copy link
Author

gurusai-voleti commented Sep 30, 2024

Apart from the field behavior comments, Please check bucket deletion. If the bucket is configured with force_destroy=true then while deleting bucket, it should delete all the folders and objects within the it. This may require changing logic in deletion operation. Also please add documentation of the newly added fields and PR description as well.

->> ran manual test case locally as below

  1. create HNS enabled bucket with force_destroy=true and upload files in bucket
  2. check bucket is created with contents
  3. when tried to delete bucket, terraform deleted the all the files in bucket and deleted the bucket

so no code changes needed for force_destroy for HNS bucket

update: added force destroy test case in acceptance tests

Description: `The bucket's HNS support, which defines bucket can organize folders in logical file system structure`,
Elem : &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Copy link
Member

Choose a reason for hiding this comment

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

Should we mark this field with ForceNew as well since it is not mutable?

Copy link
Author

Choose a reason for hiding this comment

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

currently this block contains only one resource I see no need of adding again here as the whole block is enforce with ForceNew true,

please suggest otherwise I will add ForceNew also at enabled field level @kautikdk

@@ -880,6 +900,12 @@ func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error
}
}

if d.HasChange("hierarchical_namespace") {
if v, ok := d.GetOk("hierarchical_namespace"); ok {
sb.HierarchicalNamespace = expandBucketHierachicalNamespace(v.([]interface{}))
Copy link
Member

Choose a reason for hiding this comment

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

I believe, There is no need for checking this block in update as the block is marked with ForceNew which will never allow having updates for the block.

Copy link
Author

Choose a reason for hiding this comment

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

removed this block

Config: testAccStorageBucket_basic_hns(bucketName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"google_storage_bucket.bucket", "hierarchical_namespace.0.enabled", "true"),
Copy link
Member

Choose a reason for hiding this comment

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

Since we are not adding update tests, It would be worth adding test for false value as well.

Copy link
Author

Choose a reason for hiding this comment

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

added false test case

`, bucketName)
}

func testAccStorageBucket_basic_hns_with_data(bucketName string, enabled bool, forceDestroy bool) string {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure where are we adding data here?

Copy link
Author

@gurusai-voleti gurusai-voleti Sep 30, 2024

Choose a reason for hiding this comment

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

in config we are creating the bucket and in check we are calling testAccCheckStorageBucketPutItem where a file is uploaded to bucket,

I debugged the test case with TF_LOG=DEBUG and it executed as below

  1. bucket created
  2. object uploaded to bucket
  3. after test is successful, in infra cleaning step, as we enforced force_destroy true, objects got deleted and then bucket deleted
    @kautikdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants