From 1774999a9c70c853d8921c5df665487b30c75e22 Mon Sep 17 00:00:00 2001 From: Andrew Mackett Date: Tue, 30 Mar 2021 16:59:54 +0100 Subject: [PATCH] fix: Add force_destroy option for included GCS bucket (#545) --- README.md | 1 + main.tf | 1 + modules/core_project_factory/main.tf | 9 +++++---- modules/core_project_factory/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 67be58a3..e107baf4 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ determining that location is as follows: | activate\_apis | The list of apis to activate within the project | `list(string)` |
[
"compute.googleapis.com"
]
| no | | auto\_create\_network | Create the default network | `bool` | `false` | no | | billing\_account | The ID of the billing account to associate this project with | `string` | n/a | yes | +| bucket\_force\_destroy | Force the deletion of all objects within the GCS bucket when deleting the bucket (optional) | `bool` | `false` | no | | bucket\_labels | A map of key/value label pairs to assign to the bucket (optional) | `map` | `{}` | no | | 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 | diff --git a/main.tf b/main.tf index a2a5df77..4097a002 100644 --- a/main.tf +++ b/main.tf @@ -57,6 +57,7 @@ module "project-factory" { bucket_location = var.bucket_location bucket_versioning = var.bucket_versioning bucket_labels = var.bucket_labels + bucket_force_destroy = var.bucket_force_destroy 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 0b7c7b0e..f4506f64 100644 --- a/modules/core_project_factory/main.tf +++ b/modules/core_project_factory/main.tf @@ -278,10 +278,11 @@ resource "google_project_usage_export_bucket" "usage_report_export" { resource "google_storage_bucket" "project_bucket" { count = local.create_bucket ? 1 : 0 - 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 - labels = var.bucket_labels + 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 + labels = var.bucket_labels + force_destroy = var.bucket_force_destroy versioning { enabled = var.bucket_versioning diff --git a/modules/core_project_factory/variables.tf b/modules/core_project_factory/variables.tf index a49b9772..28a01cc8 100644 --- a/modules/core_project_factory/variables.tf +++ b/modules/core_project_factory/variables.tf @@ -181,6 +181,12 @@ variable "bucket_labels" { default = {} } +variable "bucket_force_destroy" { + description = "Force the deletion of all objects within the GCS bucket when deleting the bucket (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 3f2f3dbf..4a284b76 100644 --- a/variables.tf +++ b/variables.tf @@ -181,6 +181,12 @@ variable "bucket_labels" { default = {} } +variable "bucket_force_destroy" { + description = "Force the deletion of all objects within the GCS bucket when deleting the bucket (optional)" + type = bool + default = false +} + variable "auto_create_network" { description = "Create the default network" type = bool