From 7a0d746862199f9345282b831684776b3c77ec7e Mon Sep 17 00:00:00 2001 From: Aleksandr Skoriy Date: Wed, 22 Jul 2020 23:57:38 +0300 Subject: [PATCH] feat: Enable GCS bucket versioning (#431) Co-authored-by: Morgante Pell --- README.md | 1 + main.tf | 1 + modules/core_project_factory/main.tf | 4 ++++ modules/core_project_factory/variables.tf | 6 ++++++ modules/gsuite_enabled/README.md | 1 + modules/gsuite_enabled/main.tf | 1 + modules/gsuite_enabled/variables.tf | 6 ++++++ modules/shared_vpc/main.tf | 1 + modules/shared_vpc/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 10 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 5a7db6b6..9bed1468 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ determining that location is as follows: | bucket\_location | The location for a GCS bucket to create (optional) | string | `"US"` | no | | bucket\_name | A name for a GCS bucket to create (in the bucket_project project), useful for Terraform state (optional) | string | `""` | no | | bucket\_project | A project to create a GCS bucket (bucket_name) in, useful for Terraform state (optional) | string | `""` | no | +| bucket\_versioning | Enable versioning for a GCS bucket to create (optional) | bool | `"false"` | no | | budget\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` | string | `"null"` | no | | budget\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded | list(number) | `` | no | | budget\_amount | The amount to use for a budget alert | number | `"null"` | no | diff --git a/main.tf b/main.tf index 6b37a315..6221b7fc 100644 --- a/main.tf +++ b/main.tf @@ -51,6 +51,7 @@ module "project-factory" { bucket_project = var.bucket_project bucket_name = var.bucket_name bucket_location = var.bucket_location + bucket_versioning = var.bucket_versioning auto_create_network = var.auto_create_network disable_services_on_destroy = var.disable_services_on_destroy default_service_account = var.default_service_account diff --git a/modules/core_project_factory/main.tf b/modules/core_project_factory/main.tf index e9ba793e..b3545118 100644 --- a/modules/core_project_factory/main.tf +++ b/modules/core_project_factory/main.tf @@ -394,6 +394,10 @@ resource "google_storage_bucket" "project_bucket" { name = local.project_bucket_name project = var.bucket_project == local.base_project_id ? google_project.main.project_id : var.bucket_project location = var.bucket_location + + versioning { + enabled = var.bucket_versioning + } } /*********************************************** diff --git a/modules/core_project_factory/variables.tf b/modules/core_project_factory/variables.tf index c85ecf58..d8a9794f 100644 --- a/modules/core_project_factory/variables.tf +++ b/modules/core_project_factory/variables.tf @@ -143,6 +143,12 @@ variable "bucket_location" { default = "US" } +variable "bucket_versioning" { + description = "Enable versioning for a GCS bucket to create (optional)" + type = bool + default = false +} + variable "auto_create_network" { description = "Create the default network" type = bool diff --git a/modules/gsuite_enabled/README.md b/modules/gsuite_enabled/README.md index 21aba33f..b139a0eb 100644 --- a/modules/gsuite_enabled/README.md +++ b/modules/gsuite_enabled/README.md @@ -65,6 +65,7 @@ The roles granted are specifically: | bucket\_location | The location for a GCS bucket to create (optional) | string | `""` | no | | bucket\_name | A name for a GCS bucket to create (in the bucket_project project), useful for Terraform state (optional) | string | `""` | no | | bucket\_project | A project to create a GCS bucket (bucket_name) in, useful for Terraform state (optional) | string | `""` | no | +| bucket\_versioning | Enable versioning for a GCS bucket to create (optional) | bool | `"false"` | no | | budget\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` | string | `"null"` | no | | budget\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded | list(number) | `` | no | | budget\_amount | The amount to use for a budget alert | number | `"null"` | no | diff --git a/modules/gsuite_enabled/main.tf b/modules/gsuite_enabled/main.tf index fab2caae..243bb10e 100644 --- a/modules/gsuite_enabled/main.tf +++ b/modules/gsuite_enabled/main.tf @@ -93,6 +93,7 @@ module "project-factory" { bucket_project = var.bucket_project bucket_name = var.bucket_name bucket_location = var.bucket_location + bucket_versioning = var.bucket_versioning auto_create_network = var.auto_create_network disable_services_on_destroy = var.disable_services_on_destroy default_service_account = var.default_service_account diff --git a/modules/gsuite_enabled/variables.tf b/modules/gsuite_enabled/variables.tf index d23e3dab..75868c2a 100644 --- a/modules/gsuite_enabled/variables.tf +++ b/modules/gsuite_enabled/variables.tf @@ -137,6 +137,12 @@ variable "bucket_location" { default = "" } +variable "bucket_versioning" { + description = "Enable versioning for a GCS bucket to create (optional)" + type = bool + default = false +} + variable "api_sa_group" { description = "A G Suite group to place the Google APIs Service Account for the project in" default = "" diff --git a/modules/shared_vpc/main.tf b/modules/shared_vpc/main.tf index d532ba1c..083a1040 100755 --- a/modules/shared_vpc/main.tf +++ b/modules/shared_vpc/main.tf @@ -44,6 +44,7 @@ module "project-factory" { activate_apis = var.activate_apis usage_bucket_name = var.usage_bucket_name usage_bucket_prefix = var.usage_bucket_prefix + bucket_versioning = var.bucket_versioning credentials_path = var.credentials_path shared_vpc_subnets = var.shared_vpc_subnets labels = var.labels diff --git a/modules/shared_vpc/variables.tf b/modules/shared_vpc/variables.tf index 8fb21be6..1f863c43 100755 --- a/modules/shared_vpc/variables.tf +++ b/modules/shared_vpc/variables.tf @@ -129,6 +129,12 @@ variable "bucket_location" { default = "US" } +variable "bucket_versioning" { + description = "Enable versioning for a GCS bucket to create (optional)" + type = bool + default = false +} + variable "auto_create_network" { description = "Create the default network" type = bool diff --git a/variables.tf b/variables.tf index 30077d44..e8ba93e9 100644 --- a/variables.tf +++ b/variables.tf @@ -137,6 +137,12 @@ variable "bucket_location" { default = "US" } +variable "bucket_versioning" { + description = "Enable versioning for a GCS bucket to create (optional)" + type = bool + default = false +} + variable "auto_create_network" { description = "Create the default network" type = bool