FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 38156df5 authored by Dr Abraham Martin's avatar Dr Abraham Martin
Browse files

Merge branch 'issue-6-custom-service-account-id' into 'master'

allow webapp service account id to be customised and SQL instance to be blank

Closes #5 and #6

See merge request !6
parents 769a0528 61a5460e
No related branches found
No related tags found
1 merge request!6allow webapp service account id to be customised and SQL instance to be blank
Pipeline #35906 passed
...@@ -3,12 +3,15 @@ ...@@ -3,12 +3,15 @@
# A service account which the webapp runs in the context of. # A service account which the webapp runs in the context of.
resource "google_service_account" "webapp" { resource "google_service_account" "webapp" {
project = var.project project = var.project
account_id = "webapp-run" account_id = coalesce(var.service_account_id, "${var.name}-run")
display_name = "Web application Cloud Run service account" display_name = coalesce(var.service_account_display_name, "Web application Cloud Run service account")
} }
# The webapp service account has the ability to connect to the SQL instance. # The webapp service account has the ability to connect to the SQL instance.
# (Only if sql_instance_connection_name is non-empty.)
resource "google_project_iam_member" "webapp_sql_client" { resource "google_project_iam_member" "webapp_sql_client" {
count = (var.sql_instance_connection_name != "") ? 1 : 0
project = local.sql_instance_project project = local.sql_instance_project
role = "roles/cloudsql.client" role = "roles/cloudsql.client"
member = "serviceAccount:${google_service_account.webapp.email}" member = "serviceAccount:${google_service_account.webapp.email}"
...@@ -25,23 +28,29 @@ resource "google_cloud_run_service" "webapp" { ...@@ -25,23 +28,29 @@ resource "google_cloud_run_service" "webapp" {
template { template {
metadata { metadata {
annotations = { annotations = merge(
# Maximum number of auto-scaled instances. For a container with # Annotations which are always set:
# N-workers, maxScale should be less than 1/N of the maximum connection {
# count for the Cloud SQL instance. # Maximum number of auto-scaled instances. For a container with
"autoscaling.knative.dev/maxScale" = var.max_scale # N-workers, maxScale should be less than 1/N of the maximum connection
# count for the Cloud SQL instance.
# Cloud SQL instances to auto-magically make appear in the container as "autoscaling.knative.dev/maxScale" = var.max_scale
# Unix sockets.
"run.googleapis.com/cloudsql-instances" = var.sql_instance_connection_name # As mentioned at https://www.terraform.io/docs/configuration/resources.html#ignore_changes
# placeholders need to be created as the adding the key to the map is
# As mentioned at https://www.terraform.io/docs/configuration/resources.html#ignore_changes # considered a change and not ignored by ignore_changes
# placeholders need to be created as the adding the key to the map is "client.knative.dev/user-image" = "placeholder"
# considered a change and not ignored by ignore_changes "run.googleapis.com/client-name" = "placeholder"
"client.knative.dev/user-image" = "placeholder" "run.googleapis.com/client-version" = "placeholder"
"run.googleapis.com/client-name" = "placeholder" },
"run.googleapis.com/client-version" = "placeholder"
} # Annotations which are only set if there is a Cloud SQL instance:
(var.sql_instance_connection_name != "") ? {
# Cloud SQL instances to auto-magically make appear in the container as
# Unix sockets.
"run.googleapis.com/cloudsql-instances" = var.sql_instance_connection_name
} : {}
)
} }
spec { spec {
......
...@@ -16,7 +16,7 @@ variable "sql_instance_project" { ...@@ -16,7 +16,7 @@ variable "sql_instance_project" {
variable "sql_instance_connection_name" { variable "sql_instance_connection_name" {
description = "SQL instance connection name" description = "SQL instance connection name"
type = string default = ""
} }
variable "cloud_run_region" { variable "cloud_run_region" {
...@@ -69,3 +69,19 @@ If and only if a domain mapping has been created, the ...@@ -69,3 +69,19 @@ If and only if a domain mapping has been created, the
EOI EOI
default = "" default = ""
} }
variable "service_account_id" {
default = ""
description = <<EOI
A service account is always created for the web application. If non-empty this
variable overrides the default service account id. The default id is formed
from the "name" variable value with "-run" appended.
EOI
}
variable "service_account_display_name" {
default = ""
description = <<EOI
If non-empty, override the default display name of the webapp service account.
EOI
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment