Skip to content

Commit d5ecda3

Browse files
authored
Merge pull request #22 from MaterializeInc/disable-bucket-versioning-by-default
configurable bucket versioning
2 parents c1834e6 + 00f9cfa commit d5ecda3

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ No resources.
7575
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix to be used for resource names | `string` | `"materialize"` | no |
7676
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The ID of the project where resources will be created | `string` | n/a | yes |
7777
| <a name="input_region"></a> [region](#input\_region) | The region where resources will be created | `string` | `"us-central1"` | no |
78+
| <a name="input_storage_bucket_version_ttl"></a> [storage\_bucket\_version\_ttl](#input\_storage\_bucket\_version\_ttl) | Sets the TTL (in days) on non current storage bucket objects. This must be set if storage\_bucket\_versioning is turned on. | `number` | `7` | no |
79+
| <a name="input_storage_bucket_versioning"></a> [storage\_bucket\_versioning](#input\_storage\_bucket\_versioning) | Enable bucket versioning. | `bool` | `true` | no |
7880
| <a name="input_use_local_chart"></a> [use\_local\_chart](#input\_use\_local\_chart) | Whether to use a local chart instead of one from a repository | `bool` | `false` | no |
7981
| <a name="input_use_self_signed_cluster_issuer"></a> [use\_self\_signed\_cluster\_issuer](#input\_use\_self\_signed\_cluster\_issuer) | Whether to install and use a self-signed ClusterIssuer for TLS. To work around limitations in Terraform, this will be treated as `false` if no materialize instances are defined. | `bool` | `true` | no |
8082

@@ -121,3 +123,11 @@ For existing users upgrading Materialize instances not previously configured for
121123
5. Update the `request_rollout` field of the Materialize instance.
122124
6. Run `terraform apply`. This will generate the certificates and configure your Materialize instance to use them.
123125
<!-- END_TF_DOCS -->
126+
127+
128+
129+
#### Storage Bucket Versioning
130+
By default storage bucket versioning is turned off. This both reduces
131+
costs and allows for easier cleanup of resources for testing. When running in
132+
production, versioning should be turned on with a sufficient TTL to meet any
133+
data-recovery requirements. See `storage_bucket_versioning` and `storage_bucket_version_ttl`.

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ module "storage" {
6767
region = var.region
6868
prefix = var.prefix
6969
service_account = module.gke.workload_identity_sa_email
70+
versioning = var.storage_bucket_versioning
71+
version_ttl = var.storage_bucket_version_ttl
7072

7173
labels = local.common_labels
7274
}

modules/storage/main.tf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
locals {
2+
version_ttl = (var.versioning && var.version_ttl != null) ? [{
3+
action = {
4+
type = "delete"
5+
}
6+
condition = {
7+
daysSinceNoncurrentTime = var.version_ttl
8+
}
9+
}] : []
10+
11+
lifecycle_rules = concat(var.lifecycle_rules, local.version_ttl)
12+
13+
}
14+
115
resource "google_storage_bucket" "materialize" {
216
name = "${var.prefix}-storage-${var.project_id}"
317
location = var.region
@@ -7,11 +21,11 @@ resource "google_storage_bucket" "materialize" {
721
uniform_bucket_level_access = true
822

923
versioning {
10-
enabled = true
24+
enabled = var.versioning
1125
}
1226

1327
dynamic "lifecycle_rule" {
14-
for_each = var.lifecycle_rules
28+
for_each = local.lifecycle_rules
1529
content {
1630
action {
1731
type = lifecycle_rule.value.action.type
@@ -26,6 +40,7 @@ resource "google_storage_bucket" "materialize" {
2640
}
2741
}
2842

43+
2944
labels = var.labels
3045
}
3146

modules/storage/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ variable "labels" {
2424
default = {}
2525
}
2626

27+
28+
variable "versioning" {
29+
description = "Enable bucket versioning. This should be enabled for production deployments."
30+
type = bool
31+
default = true
32+
}
33+
2734
variable "lifecycle_rules" {
2835
description = "List of lifecycle rules to configure"
2936
type = list(object({
@@ -50,3 +57,10 @@ variable "lifecycle_rules" {
5057
}
5158
]
5259
}
60+
61+
variable "version_ttl" {
62+
description = "Sets the TTL (in days) on non current storage bucket objects. This must be set if versioning is turned on."
63+
type = number
64+
default = 7
65+
66+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ variable "install_metrics_server" {
160160
default = false
161161
}
162162

163+
variable "storage_bucket_versioning" {
164+
description = "Enable bucket versioning. This should be enabled for production deployments."
165+
type = bool
166+
default = false
167+
}
168+
169+
variable "storage_bucket_version_ttl" {
170+
description = "Sets the TTL (in days) on non current storage bucket objects. This must be set if storage_bucket_versioning is turned on."
171+
type = number
172+
default = 7
173+
}
174+
163175
variable "install_cert_manager" {
164176
description = "Whether to install cert-manager."
165177
type = bool

0 commit comments

Comments
 (0)