Skip to content

Commit d651fc4

Browse files
committed
feat: Add support for anywhere cache
1 parent af4934f commit d651fc4

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

community/modules/file-system/cloud-storage-bucket/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ No modules.
128128

129129
| Name | Type |
130130
|------|------|
131+
| [google-beta_google_storage_anywhere_cache.cache_instances](https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_storage_anywhere_cache) | resource |
131132
| [google-beta_google_storage_bucket.bucket](https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_storage_bucket) | resource |
132133
| [google_storage_bucket_iam_binding.viewers](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket_iam_binding) | resource |
133134
| [random_id.resource_name_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
@@ -136,6 +137,7 @@ No modules.
136137

137138
| Name | Description | Type | Default | Required |
138139
|------|-------------|------|---------|:--------:|
140+
| <a name="input_anywhere_cache"></a> [anywhere\_cache](#input\_anywhere\_cache) | Anywhere Cache configurations.<br/>When you create a cache for a bucket, the cache must be created in a zone within the location of your bucket.<br/>For example, if your bucket is located in the us-east1 region, you can create a cache in us-east1-b but not us-central1-c.<br/>If your bucket is located in the ASIA dual-region, you can create a cache in any zones that make up the asia-east1 and asia-southeast1 regions.<br/>This validation only works for single regions. | <pre>object({<br/> zones = list(string)<br/> ttl = optional(string, "86400s")<br/> admission_policy = optional(string, "admit-on-first-miss")<br/> })</pre> | `null` | no |
139141
| <a name="input_autoclass"></a> [autoclass](#input\_autoclass) | Configure bucket autoclass setup<br/><br/>The autoclass config supports automatic transitions of objects in the bucket to appropriate storage classes based on each object's access pattern.<br/><br/>The terminal storage class defines that objects in the bucket eventually transition to if they are not read for a certain length of time. <br/>Supported values include: 'NEARLINE', 'ARCHIVE' (Default 'NEARLINE')<br/><br/>See Cloud documentation for more details:<br/><br/>https://cloud.google.com/storage/docs/autoclass | <pre>object({<br/> enabled = optional(bool, false)<br/> terminal_storage_class = optional(string, null)<br/> })</pre> | <pre>{<br/> "enabled": false<br/>}</pre> | no |
140142
| <a name="input_deployment_name"></a> [deployment\_name](#input\_deployment\_name) | Name of the HPC deployment; used as part of name of the GCS bucket. | `string` | n/a | yes |
141143
| <a name="input_enable_hierarchical_namespace"></a> [enable\_hierarchical\_namespace](#input\_enable\_hierarchical\_namespace) | If true, enables hierarchical namespace for the bucket. This option must be configured during the initial creation of the bucket. | `bool` | `false` | no |
@@ -162,6 +164,7 @@ No modules.
162164

163165
| Name | Description |
164166
|------|-------------|
167+
| <a name="output_anywhere_cache_ids"></a> [anywhere\_cache\_ids](#output\_anywhere\_cache\_ids) | The IDs of the created Anywhere Cache instances. |
165168
| <a name="output_client_install_runner"></a> [client\_install\_runner](#output\_client\_install\_runner) | Runner that performs client installation needed to use gcs fuse. |
166169
| <a name="output_gcs_bucket_name"></a> [gcs\_bucket\_name](#output\_gcs\_bucket\_name) | Bucket name. |
167170
| <a name="output_gcs_bucket_path"></a> [gcs\_bucket\_path](#output\_gcs\_bucket\_path) | The gsutil bucket path with format of `gs://<bucket-name>`. |

community/modules/file-system/cloud-storage-bucket/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,14 @@ resource "google_storage_bucket_iam_binding" "viewers" {
124124
role = "roles/storage.objectViewer"
125125
members = var.viewers
126126
}
127+
128+
resource "google_storage_anywhere_cache" "cache_instances" {
129+
for_each = var.anywhere_cache != null ? toset(var.anywhere_cache.zones) : toset([])
130+
131+
provider = google-beta
132+
133+
bucket = google_storage_bucket.bucket.name
134+
zone = each.value
135+
ttl = var.anywhere_cache.ttl
136+
admission_policy = var.anywhere_cache.admission_policy
137+
}

community/modules/file-system/cloud-storage-bucket/outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ output "gcs_bucket_name" {
6767
description = "Bucket name."
6868
value = google_storage_bucket.bucket.name
6969
}
70+
71+
output "anywhere_cache_ids" {
72+
description = "The IDs of the created Anywhere Cache instances."
73+
value = [
74+
for instance in google_storage_anywhere_cache.cache_instances : instance.id
75+
]
76+
}

community/modules/file-system/cloud-storage-bucket/variables.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,49 @@ variable "enable_object_retention" {
252252
type = bool
253253
default = false
254254
}
255+
256+
variable "anywhere_cache" {
257+
description = <<-EOT
258+
Anywhere Cache configurations.
259+
When you create a cache for a bucket, the cache must be created in a zone within the location of your bucket.
260+
For example, if your bucket is located in the us-east1 region, you can create a cache in us-east1-b but not us-central1-c.
261+
If your bucket is located in the ASIA dual-region, you can create a cache in any zones that make up the asia-east1 and asia-southeast1 regions.
262+
This validation only works for single regions.
263+
EOT
264+
type = object({
265+
zones = list(string)
266+
ttl = optional(string, "86400s")
267+
admission_policy = optional(string, "admit-on-first-miss")
268+
})
269+
default = null
270+
271+
validation {
272+
condition = var.anywhere_cache == null || alltrue([
273+
for zone in var.anywhere_cache.zones : startswith(zone, var.region)
274+
])
275+
error_message = "The zone for the Anywhere Cache must be within the bucket's region."
276+
}
277+
278+
validation {
279+
condition = var.anywhere_cache == null || contains(
280+
["admit-on-first-miss", "admit-on-second-miss"],
281+
var.anywhere_cache.admission_policy
282+
)
283+
error_message = "Allowed policies are 'admit-on-first-miss' or 'admit-on-second-miss'."
284+
}
285+
286+
validation {
287+
condition = var.anywhere_cache == null || length(var.anywhere_cache.zones) == length(distinct(var.anywhere_cache.zones))
288+
error_message = "Each Anywhere Cache configuration must specify a unique zone."
289+
}
290+
291+
validation {
292+
condition = var.anywhere_cache == null || (
293+
can(regex("^([0-9]+)s$", var.anywhere_cache.ttl)) ? (
294+
tonumber(regex("^([0-9]+)s$", var.anywhere_cache.ttl)[0]) >= 86400 &&
295+
tonumber(regex("^([0-9]+)s$", var.anywhere_cache.ttl)[0]) <= 604800
296+
) : false
297+
)
298+
error_message = "TTL must be between 1 day (86400s) and 7 days (604800s) and in the format 'Xs'."
299+
}
300+
}

examples/storage-gke.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ deployment_groups:
9494
random_suffix: true
9595
force_destroy: true
9696

97+
anywhere_cache:
98+
zones: [$(vars.zone)]
99+
ttl: "86400s"
100+
admission_policy: "admit-on-first-miss"
101+
97102
- id: data-bucket-pv
98103
source: modules/file-system/gke-persistent-volume
99104
use: [gke_cluster, data-bucket]

0 commit comments

Comments
 (0)