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
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,23 @@ func ResourceStorageBucket() *schema.Resource {
},
},
},
"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

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

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

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

ForceNew: true,
Description: `Set this enabled flag to true when folders with logical files structure. Default value is false.`,
},
},
},
},
},
UseJSONNumber: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ import (
"google.golang.org/api/storage/v1"
)

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

bucketName := acctest.TestBucketName(t)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccStorageBucketDestroyProducer(t),
Steps: []resource.TestStep{
{
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

),
},
{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}

func testAccStorageBucket_basic_hns(bucketName string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
location = "US"
uniform_bucket_level_access = true
hierarchical_namespace {
enabled = true
}
}
`, bucketName)
}

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

Expand Down
Loading