Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Introduce variables for destroying things (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Jun 29, 2023
1 parent 2312469 commit 2041f77
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion terraform/build.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "google_storage_bucket" "cloudbuild-cache" {
name = "${var.project}-cloudbuild-cache"
location = var.storage_location

force_destroy = true
force_destroy = var.force_destroy
uniform_bucket_level_access = true

// Automatically expire cached objects.
Expand Down
6 changes: 5 additions & 1 deletion terraform/database.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resource "google_sql_database_instance" "db-inst" {
region = var.db_location
database_version = var.db_version

deletion_protection = !var.force_destroy

settings {
tier = var.cloudsql_tier
disk_size = var.cloudsql_disk_size_gb
Expand Down Expand Up @@ -81,6 +83,8 @@ resource "google_sql_database_instance" "replicas" {

master_instance_name = google_sql_database_instance.db-inst.name

deletion_protection = !var.force_destroy

// These are REGIONAL replicas, which cannot auto-failover. The default
// configuration has auto-failover in zones. This is for super disaster
// recovery in which an entire region is down for an extended period of time.
Expand Down Expand Up @@ -223,7 +227,7 @@ resource "google_storage_bucket" "backups" {
name = "${var.project}-backups"
location = var.storage_location

force_destroy = true
force_destroy = var.force_destroy
uniform_bucket_level_access = true

versioning {
Expand Down
2 changes: 2 additions & 0 deletions terraform/storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ resource "google_storage_bucket" "export" {
type = "Delete"
}
}

force_destroy = var.force_destroy
}

resource "google_storage_bucket_iam_member" "public" {
Expand Down
7 changes: 7 additions & 0 deletions terraform/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

variable "force_destroy" {
type = bool
default = false

description = "Allow resources like buckets and database instances to be destroyed."
}

variable "create_env_file" {
type = bool
default = false
Expand Down

0 comments on commit 2041f77

Please sign in to comment.