Skip to content

Commit 8b98274

Browse files
authored
Add ephemeral to GCP storage enabling resources deletion (#65)
1 parent 5090ca2 commit 8b98274

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

deployment/modules/gcp/conformance/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module "storage" {
88
project_id = var.project_id
99
base_name = var.base_name
1010
location = var.location
11+
ephemeral = true
1112
}
1213

1314
module "secretmanager" {

deployment/modules/gcp/storage/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ resource "google_spanner_instance" "log_spanner" {
4444
config = "regional-${var.location}"
4545
display_name = var.base_name
4646
processing_units = 100
47+
48+
force_destroy = var.ephemeral
4749
}
4850

4951
resource "google_spanner_database" "log_db" {
@@ -54,6 +56,8 @@ resource "google_spanner_database" "log_db" {
5456
"CREATE TABLE Seq (id INT64 NOT NULL, seq INT64 NOT NULL, v BYTES(MAX),) PRIMARY KEY (id, seq)",
5557
"CREATE TABLE IntCoord (id INT64 NOT NULL, seq INT64 NOT NULL,) PRIMARY KEY (id)",
5658
]
59+
60+
deletion_protection = !var.ephemeral
5761
}
5862

5963
resource "google_spanner_database" "dedup_db" {
@@ -62,4 +66,6 @@ resource "google_spanner_database" "dedup_db" {
6266
ddl = [
6367
"CREATE TABLE IDSeq (id INT64 NOT NULL, h BYTES(MAX) NOT NULL, idx INT64 NOT NULL, timestamp INT64 NOT NULL,) PRIMARY KEY (id, h)",
6468
]
69+
70+
deletion_protection = !var.ephemeral
6571
}

deployment/modules/gcp/storage/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ variable "location" {
1212
description = "Location in which to create resources"
1313
type = string
1414
}
15+
16+
variable "ephemeral" {
17+
description = "Set to true if this is a throwaway/temporary log instance. Will set attributes on created resources to allow them to be disabled/deleted more easily."
18+
type = bool
19+
}

deployment/modules/gcp/test/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module "storage" {
88
project_id = var.project_id
99
base_name = var.base_name
1010
location = var.location
11+
ephemeral = false
1112
}
1213

1314
module "secretmanager" {

0 commit comments

Comments
 (0)