Skip to content

Commit b65e3eb

Browse files
feat!: add hierarchical namespace flag (#375)
Co-authored-by: Awais Malik <awmalik@google.com>
1 parent 6ea3139 commit b65e3eb

File tree

12 files changed

+62
-2
lines changed

12 files changed

+62
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Functional examples are included in the
6363
| encryption\_key\_names | Optional map of lowercase unprefixed name => string, empty strings are ignored. | `map(string)` | `{}` | no |
6464
| folders | Map of lowercase unprefixed name => list of top level folder objects. | `map(list(string))` | `{}` | no |
6565
| force\_destroy | Optional map of lowercase unprefixed name => boolean, defaults to false. | `map(bool)` | `{}` | no |
66+
| hierarchical\_namespace | Optional map of lowercase unprefixed bucket name => boolean, defaults to false. | `map(bool)` | `{}` | no |
6667
| hmac\_key\_admins | IAM-style members who will be granted roles/storage.hmacKeyAdmin on all buckets. | `list(string)` | `[]` | no |
6768
| hmac\_service\_accounts | List of HMAC service accounts to grant access to GCS. | `map(string)` | `{}` | no |
6869
| labels | Labels to be attached to the buckets | `map(string)` | `{}` | no |

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ resource "google_storage_bucket" "buckets" {
7676
false,
7777
)
7878
}
79+
hierarchical_namespace {
80+
enabled = lookup(
81+
var.hierarchical_namespace,
82+
lower(each.value),
83+
false,
84+
)
85+
}
7986
# Having a permanent encryption block with default_kms_key_name = "" works but results in terraform applying a change every run
8087
# There is no enabled = false attribute available to ask terraform to ignore the block
8188
dynamic "encryption" {

metadata.display.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ spec:
7575
force_destroy:
7676
name: force_destroy
7777
title: Force Destroy
78+
hierarchical_namespace:
79+
name: hierarchical_namespace
80+
title: Hierarchical Namespace
7881
hmac_key_admins:
7982
name: hmac_key_admins
8083
title: Hmac Key Admins

metadata.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ spec:
7676
description: Optional map of lowercase unprefixed bucket name => boolean, defaults to false.
7777
varType: map(bool)
7878
defaultValue: {}
79+
- name: hierarchical_namespace
80+
description: Optional map of lowercase unprefixed bucket name => boolean, defaults to false.
81+
varType: map(bool)
82+
defaultValue: {}
7983
- name: encryption_key_names
8084
description: Optional map of lowercase unprefixed name => string, empty strings are ignored.
8185
varType: map(string)
@@ -330,6 +334,11 @@ spec:
330334
- - object
331335
- default_kms_key_name: string
332336
force_destroy: bool
337+
hierarchical_namespace:
338+
- list
339+
- - object
340+
- enabled: bool
341+
terminal_storage_class: string
333342
id: string
334343
labels:
335344
- map
@@ -448,6 +457,11 @@ spec:
448457
- - object
449458
- default_kms_key_name: string
450459
force_destroy: bool
460+
hierarchical_namespace:
461+
- list
462+
- - object
463+
- enabled: bool
464+
terminal_storage_class: string
451465
id: string
452466
labels:
453467
- map
@@ -567,6 +581,11 @@ spec:
567581
- - object
568582
- default_kms_key_name: string
569583
force_destroy: bool
584+
hierarchical_namespace:
585+
- list
586+
- - object
587+
- enabled: bool
588+
terminal_storage_class: string
570589
id: string
571590
labels:
572591
- map

modules/simple_bucket/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Functional examples are included in the
4444
| custom\_placement\_config | Configuration of the bucket's custom location in a dual-region bucket setup. If the bucket is designated a single or multi-region, the variable are null. | <pre>object({<br> data_locations = list(string)<br> })</pre> | `null` | no |
4545
| encryption | A Cloud KMS key that will be used to encrypt objects inserted into this bucket. The key name should follow the format of `projects/<project-name>/locations/<location-name>/keyRings/<keyring-name>/cryptoKeys/<key-name>`. To use a Cloud KMS key automatically created by this module use the `internal_encryption_config` input variable. | <pre>object({<br> default_kms_key_name = string<br> })</pre> | `null` | no |
4646
| force\_destroy | When deleting a bucket, this boolean option will delete all contained objects. If false, Terraform will fail to delete buckets which contain objects. | `bool` | `false` | no |
47+
| hierarchical\_namespace | When set to true, hierarchical namespace is enable for this bucket. | `bool` | `false` | no |
4748
| iam\_members | The list of IAM members to grant permissions on the bucket. | <pre>list(object({<br> role = string<br> member = string<br> }))</pre> | `[]` | no |
4849
| internal\_encryption\_config | Configuration for the creation of an internal Google Cloud Key Management Service (KMS) Key for use as Customer-managed encryption key (CMEK) for the GCS Bucket<br> instead of creating one in advance and providing the key in the variable `encryption.default_kms_key_name`.<br> create\_encryption\_key: If `true` a Google Cloud Key Management Service (KMS) KeyRing and a Key will be created<br> prevent\_destroy: Set the prevent\_destroy lifecycle attribute on keys.<br> key\_destroy\_scheduled\_duration: Set the period of time that versions of keys spend in the `DESTROY_SCHEDULED` state before transitioning to `DESTROYED`.<br> key\_rotation\_period: Generate a new key every time this period passes. | <pre>object({<br> create_encryption_key = optional(bool, false)<br> prevent_destroy = optional(bool, false)<br> key_destroy_scheduled_duration = optional(string, null)<br> key_rotation_period = optional(string, "7776000s")<br> })</pre> | `{}` | no |
4950
| labels | A set of key/value label pairs to assign to the bucket. | `map(string)` | `null` | no |

modules/simple_bucket/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ resource "google_storage_bucket" "bucket" {
3737
enabled = var.autoclass
3838
}
3939

40+
hierarchical_namespace {
41+
enabled = var.hierarchical_namespace
42+
}
43+
4044
dynamic "retention_policy" {
4145
for_each = var.retention_policy == null ? [] : [var.retention_policy]
4246
content {

modules/simple_bucket/metadata.display.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ spec:
4949
force_destroy:
5050
name: force_destroy
5151
title: Force Destroy
52+
invisible: false
53+
hierarchical_namespace:
54+
name: hierarchical_namespace
55+
title: Hierarchical Namespace
5256
iam_members:
5357
name: iam_members
5458
title: Iam Members

modules/simple_bucket/metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ spec:
9696
description: While set to true, autoclass is enabled for this bucket.
9797
varType: bool
9898
defaultValue: false
99+
- name: hierarchical_namespace
100+
description: While set to true, hierarchical namespace is enabled for this bucket.
101+
varType: bool
102+
defaultValue: false
99103
- name: retention_policy
100104
description: Configuration of the bucket's data retention policy for how long objects in the bucket should be retained.
101105
varType: |-
@@ -247,6 +251,11 @@ spec:
247251
- - object
248252
- default_kms_key_name: string
249253
force_destroy: bool
254+
hierarchical_namespace:
255+
- list
256+
- - object
257+
- enabled: bool
258+
terminal_storage_class: string
250259
id: string
251260
labels:
252261
- map

modules/simple_bucket/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ variable "autoclass" {
7575
default = false
7676
}
7777

78+
variable "hierarchical_namespace" {
79+
description = "When set to true, hierarchical namespace is enable for this bucket."
80+
type = bool
81+
default = false
82+
}
83+
7884
variable "retention_policy" {
7985
description = "Configuration of the bucket's data retention policy for how long objects in the bucket should be retained."
8086
type = object({

modules/simple_bucket/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ terraform {
2020

2121
google = {
2222
source = "hashicorp/google"
23-
version = ">= 5.43.0, < 7"
23+
version = ">= 6.9.0, < 7"
2424
}
2525
}
2626

0 commit comments

Comments
 (0)