diff --git a/README.md b/README.md index f8c5dbc..a88e908 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,8 @@ The module creates: | ip_cidr_range | The IP CIDR range for the subnetwork used by the GKE cluster | string | 10.0.0.0/16 | no | | secondary_ip_range_for_services | The secondary IP range for the subnetwork used by the GKE cluster. This range is used for services | string | 192.168.16.0/22 | no | | secondary_ip_range_for_pods | The secondary IP range for the subnetwork used by the GKE cluster. This range is used for pods | string | 192.168.0.0/20 | no | -| enable_external_workers | Switch this to true if you want to run workers from outside of the GCP infrastructure. | string | false | no | +| enable_external_workers | Switch this to true if you want to run workers from outside of the GCP infrastructure. | bool | false | no | +| enable_database | Switch this to false if you don't want to deploy a new Cloud SQL instance for Spacelift. | bool | true | no | ### Outputs diff --git a/main.tf b/main.tf index c42b67f..7e6070a 100644 --- a/main.tf +++ b/main.tf @@ -50,6 +50,7 @@ module "gke" { module "db" { source = "./modules/db" seed = random_id.seed.hex + count = var.enable_database ? 1 : 0 backend_service_account_email = module.iam.backend_service_account_email compute_network_id = module.network.network_id diff --git a/outputs.tf b/outputs.tf index 098f6e0..46c5459 100644 --- a/outputs.tf +++ b/outputs.tf @@ -81,27 +81,27 @@ output "artifact_repository_url" { ### Database ### output "db_instance_name" { - value = module.db.instance_name + value = var.enable_database ? module.db[0].instance_name : "" description = "Name of the database instance" } output "db_connection_name" { - value = module.db.database_connection_name + value = var.enable_database ? module.db[0].database_connection_name : "" description = "Connection name of the database cluster. Needs to be passed to the Cloud SQL sidecar proxy See https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine#proxy" } output "db_private_ip_address" { - value = module.db.database_private_ip_address + value = var.enable_database ? module.db[0].database_private_ip_address : "" description = "Private IP address of the database instance." } output "db_database_name" { - value = module.db.database_name + value = var.enable_database ? module.db[0].database_name : "" description = "Internal PostgreSQL db name inside the Cloud SQL instance." } output "db_root_password" { - value = module.db.database_root_password + value = var.enable_database ? module.db[0].database_root_password : "" description = "The database root password" sensitive = true } @@ -201,10 +201,10 @@ output "shell" { OBJECT_STORAGE_BUCKET_UPLOADS_URL = "https://storage.googleapis.com" # Database - DATABASE_NAME = module.db.database_name - DATABASE_USER = module.db.database_iam_user - DATABASE_CONNECTION_NAME = module.db.database_connection_name - DB_ROOT_PASSWORD = module.db.database_root_password + DATABASE_NAME = var.enable_database ? module.db[0].database_name : "" + DATABASE_USER = var.enable_database ? module.db[0].database_iam_user : "" + DATABASE_CONNECTION_NAME = var.enable_database ? module.db[0].database_connection_name : "" + DB_ROOT_PASSWORD = var.enable_database ? module.db[0].database_root_password : "" #GKE GKE_CLUSTER_NAME = module.gke.gke_cluster_name diff --git a/variables.tf b/variables.tf index 8b93cbe..8eb6ae6 100644 --- a/variables.tf +++ b/variables.tf @@ -28,6 +28,12 @@ variable "app_service_account_name" { default = "spacelift-backend" } +variable "enable_database" { + type = bool + default = true + description = "Switch this to false if you don't want to deploy a new Cloud SQL instance for Spacelift." +} + variable "database_edition" { description = "Edition of the Cloud SQL instance. Can be either ENTERPRISE or ENTERPRISE_PLUS." default = "ENTERPRISE"