Skip to content

Commit

Permalink
feat: allow to disable deploying database (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecharra authored Dec 18, 2024
1 parent 8e74dd9 commit ac11577
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ac11577

Please sign in to comment.