Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions terraform/environments/gcp/compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ module "compute_gke" {
database_password_secret_name = module.secrets.database_password_secret_name

# Application configuration
admin_email = var.admin_email
admin_password_secret_name = coalesce(module.secrets.admin_password_secret_name, "")
auto_migrate = var.auto_migrate
admin_email = var.admin_email
admin_password_secret_name = coalesce(module.secrets.admin_password_secret_name, "")
enable_admin_password_writer = true # secret name comes from secrets module output, not a literal
auto_migrate = var.auto_migrate

# Per-secret IAM bindings for the GKE workload SA. Without these the pod
# could only read `database_password_secret_name`, so any code path
Expand Down
20 changes: 20 additions & 0 deletions terraform/modules/compute/gcp/gke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ resource "google_secret_manager_secret_iam_member" "workload" {
member = "serviceAccount:${google_service_account.workload.email}"
}

# Admin password secret: the app reads it at startup and adds a version when
# the admin password changes, so the SA needs both roles. No `project`, same
# reason as `workload`. Gated by a literal bool because the secret name is
# known only after apply (sensitive-value-in-count).
resource "google_secret_manager_secret_iam_member" "admin_password_reader" {
count = var.enable_admin_password_writer ? 1 : 0

secret_id = var.admin_password_secret_name
role = "roles/secretmanager.secretAccessor"
member = "serviceAccount:${google_service_account.workload.email}"
}

resource "google_secret_manager_secret_iam_member" "admin_password_writer" {
count = var.enable_admin_password_writer ? 1 : 0

secret_id = var.admin_password_secret_name
role = "roles/secretmanager.secretVersionAdder"
member = "serviceAccount:${google_service_account.workload.email}"
}

resource "google_secret_manager_secret_iam_member" "workload_additional" {
for_each = var.additional_secret_accessor_ids

Expand Down
6 changes: 6 additions & 0 deletions terraform/modules/compute/gcp/gke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ variable "admin_password_secret_name" {
default = ""
}

variable "enable_admin_password_writer" {
description = "Grant the workload SA read and version-add access to the admin password secret. Set to true when admin_password_secret_name comes from a resource attribute (known after apply) to avoid sensitive-value-in-count Terraform limitation."
type = bool
default = false
}

variable "auto_migrate" {
description = "Automatically run database migrations on startup"
type = bool
Expand Down
Loading