Skip to content

Commit 88cc064

Browse files
committed
feature: Set sensitive variables
1 parent 2aa7fe4 commit 88cc064

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

cloudsql_dumps_bucket.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ resource "google_storage_bucket" "cloudsql_dumps" {
3535

3636
lifecycle_rule {
3737
action {
38-
type = "SetStorageClass"
38+
type = "SetStorageClass"
3939
storage_class = "COLDLINE"
4040
}
4141
condition {

examples/test.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ my_drupal_projects_list = [
1515
bucket_name = "test-project-bucket-name"
1616
bucket_append_random_suffix = false
1717
bucket_enable_disaster_recovery = false
18-
bucket_labels = {
18+
bucket_labels = {
1919
"project" = "test-project"
2020
"env" = "stage"
2121
}

secrets.tf

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
locals {
2-
map_of_drupal_buckets = var.create_buckets == true ? {
2+
map_of_drupal_buckets = var.create_buckets ? {
33
for o in local.drupal_buckets_list : o.name => o
44
} : {}
5-
map_of_drupal_databases = trimspace(var.cloudsql_instance_name) != "" && trimspace(var.cloudsql_privileged_user_name) != "" && trimspace(var.cloudsql_privileged_user_password) != "" && var.create_databases_and_users == true ? {
5+
map_of_drupal_databases = trimspace(var.cloudsql_instance_name) != "" && trimspace(var.cloudsql_privileged_user_name) != "" && trimspace(var.cloudsql_privileged_user_password) != "" && var.create_databases_and_users ? {
66
for o in local.drupal_database_and_user_list : o.database => o
77
} : {}
8-
map_of_output_drupal_databases = trimspace(var.cloudsql_instance_name) != "" && trimspace(var.cloudsql_privileged_user_name) != "" && trimspace(var.cloudsql_privileged_user_password) != "" && var.create_databases_and_users == true ? {
8+
map_of_drupal_databases_indexed = {
9+
for idx, o in local.map_of_drupal_databases : tostring(idx) => o
10+
}
11+
map_of_output_drupal_databases = trimspace(var.cloudsql_instance_name) != "" && trimspace(var.cloudsql_privileged_user_name) != "" && trimspace(var.cloudsql_privileged_user_password) != "" && var.create_databases_and_users ? {
912
for o in module.drupal_databases_and_users[0].sql_users_creds : o.database => o
1013
} : {}
1114
}
1215

1316
resource "kubernetes_secret" "bucket_secret_name" {
1417
for_each = {
1518
for o in local.map_of_drupal_buckets : o.name => o
16-
if var.create_buckets == true
19+
if var.create_buckets
1720
}
1821

1922
metadata {
@@ -23,7 +26,7 @@ resource "kubernetes_secret" "bucket_secret_name" {
2326
name = each.value.helm_release_name == null ? "drupal-${each.value.release_branch_name}-${each.value.project_id}-bucket" : "${each.value.helm_release_name}-bucket"
2427
namespace = var.use_existing_kubernetes_namespaces ? each.value.namespace : kubernetes_namespace.namespace[each.value.namespace].metadata[0].name
2528
annotations = {}
26-
labels = var.default_k8s_labels
29+
labels = var.default_k8s_labels
2730
}
2831
data = {
2932
"endpoint" = each.value.host
@@ -36,8 +39,8 @@ resource "kubernetes_secret" "bucket_secret_name" {
3639

3740
resource "kubernetes_secret" "database_secret_name" {
3841
for_each = {
39-
for o in local.map_of_drupal_databases : o.database => o
40-
if trimspace(o.namespace) != "" && var.create_databases_and_users == true
42+
for idx, o in local.map_of_drupal_databases_indexed : idx => o
43+
if trimspace(o.namespace) != "" && var.create_databases_and_users
4144
}
4245
metadata {
4346
# If not specified, we suppose that the Helm release name is defined with
@@ -46,13 +49,13 @@ resource "kubernetes_secret" "database_secret_name" {
4649
name = each.value.helm_release_name == null ? "drupal-${each.value.release_branch_name}-${each.value.project_id}-db-user" : "${each.value.helm_release_name}-db-user"
4750
namespace = var.use_existing_kubernetes_namespaces ? each.value.namespace : kubernetes_namespace.namespace[each.value.namespace].metadata[0].name
4851
annotations = {}
49-
labels = var.default_k8s_labels
52+
labels = var.default_k8s_labels
5053
}
5154
data = {
5255
"endpoint" = each.value.host != null ? each.value.host : ""
5356
"port" = each.value.port
54-
"database" = local.map_of_output_drupal_databases[each.key].database
55-
"username" = local.map_of_output_drupal_databases[each.key].user
56-
"password" = local.map_of_output_drupal_databases[each.key].password
57+
"database" = local.map_of_output_drupal_databases[each.value.database].database
58+
"username" = local.map_of_output_drupal_databases[each.value.database].user
59+
"password" = local.map_of_output_drupal_databases[each.value.database].password
5760
}
5861
}

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ variable "cloudsql_privileged_user_name" {
2323
variable "cloudsql_privileged_user_password" {
2424
type = string
2525
description = "The password of the privileged user of the Cloud SQL instance"
26+
sensitive = true
2627
default = ""
2728
}
2829

0 commit comments

Comments
 (0)