From 5a93c347439e613fdc3dc95d60fb27051322c906 Mon Sep 17 00:00:00 2001 From: Michael Barroco Date: Fri, 12 Apr 2024 17:02:09 +0200 Subject: [PATCH] [terraform] Make cockroach DB cluster name configurable (#1018) * [terraform] add configuration variable crdb_cluster_name [terraform] add configuration variable crdb_cluster_name * Update documentation and variables.tf * Propagate new environment variable * Update example files * Format tf * Update text --- .../dependencies/terraform-commons-dss/helm.tf | 2 +- .../terraform-commons-dss/variables.tf | 16 ++++++++++++++++ .../modules/terraform-aws-dss/TFVARS.md | 15 +++++++++++++++ .../modules/terraform-aws-dss/main.tf | 1 + .../terraform.dev.example.tfvars | 5 ++++- .../modules/terraform-aws-dss/variables.tf | 16 ++++++++++++++++ .../modules/terraform-google-dss/TFVARS.md | 15 +++++++++++++++ .../modules/terraform-google-dss/main.tf | 1 + .../terraform.dev.example.tfvars | 6 ++++-- .../modules/terraform-google-dss/variables.tf | 16 ++++++++++++++++ .../utils/definitions/crdb_cluster_name.tf | 14 ++++++++++++++ deploy/infrastructure/utils/variables.py | 1 + deploy/operations/ci/aws-1/main.tf | 1 + deploy/operations/ci/aws-1/terraform.tfvars | 1 + deploy/operations/ci/aws-1/variables.tf | 16 ++++++++++++++++ 15 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 deploy/infrastructure/utils/definitions/crdb_cluster_name.tf diff --git a/deploy/infrastructure/dependencies/terraform-commons-dss/helm.tf b/deploy/infrastructure/dependencies/terraform-commons-dss/helm.tf index 8c28e3b07..f40cae86f 100644 --- a/deploy/infrastructure/dependencies/terraform-commons-dss/helm.tf +++ b/deploy/infrastructure/dependencies/terraform-commons-dss/helm.tf @@ -12,7 +12,7 @@ resource "local_file" "helm_chart_values" { conf = { join = var.crdb_external_nodes - cluster-name = "dss-aws-1" + cluster-name = var.crdb_cluster_name single-node = false locality = "zone=${var.crdb_locality}" } diff --git a/deploy/infrastructure/dependencies/terraform-commons-dss/variables.tf b/deploy/infrastructure/dependencies/terraform-commons-dss/variables.tf index 360d2dc41..8b437e057 100644 --- a/deploy/infrastructure/dependencies/terraform-commons-dss/variables.tf +++ b/deploy/infrastructure/dependencies/terraform-commons-dss/variables.tf @@ -155,6 +155,22 @@ variable "desired_scd_db_version" { default = "latest" } +variable "crdb_cluster_name" { + type = string + description = <<-EOT + A string that specifies a CRDB cluster name. This is used together to ensure that all newly created + nodes join the intended cluster when you are running multiple clusters. + The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. + The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, + and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + + At the moment, this variable is only used for helm charts deployments. + + Example: interuss_us_production + EOT +} + + variable "crdb_locality" { type = string description = <<-EOT diff --git a/deploy/infrastructure/modules/terraform-aws-dss/TFVARS.md b/deploy/infrastructure/modules/terraform-aws-dss/TFVARS.md index 236be8056..31764261c 100644 --- a/deploy/infrastructure/modules/terraform-aws-dss/TFVARS.md +++ b/deploy/infrastructure/modules/terraform-aws-dss/TFVARS.md @@ -237,6 +237,21 @@ Use `latest` to use the latest schema version. Example: `3.1.0` +### crdb_cluster_name + +*Type: `string`* + +A string that specifies a CRDB cluster name. This is used together to ensure that all newly created +nodes join the intended cluster when you are running multiple clusters. +The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. +The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, +and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + +At the moment, this variable is only used for helm charts deployments. + +Example: interuss_us_production + + ### crdb_locality *Type: `string`* diff --git a/deploy/infrastructure/modules/terraform-aws-dss/main.tf b/deploy/infrastructure/modules/terraform-aws-dss/main.tf index eb3cf4b42..414258f04 100644 --- a/deploy/infrastructure/modules/terraform-aws-dss/main.tf +++ b/deploy/infrastructure/modules/terraform-aws-dss/main.tf @@ -20,6 +20,7 @@ module "terraform-commons-dss" { kubernetes_namespace = var.kubernetes_namespace kubernetes_storage_class = var.aws_kubernetes_storage_class app_hostname = var.app_hostname + crdb_cluster_name = var.crdb_cluster_name crdb_hostname_suffix = var.crdb_hostname_suffix should_init = var.should_init authorization = var.authorization diff --git a/deploy/infrastructure/modules/terraform-aws-dss/terraform.dev.example.tfvars b/deploy/infrastructure/modules/terraform-aws-dss/terraform.dev.example.tfvars index cc03ee927..22dda4111 100644 --- a/deploy/infrastructure/modules/terraform-aws-dss/terraform.dev.example.tfvars +++ b/deploy/infrastructure/modules/terraform-aws-dss/terraform.dev.example.tfvars @@ -23,6 +23,9 @@ image = "latest" authorization = { public_key_pem_path = "/test-certs/auth2.pem" } -should_init = true +should_init = true + +# CockroachDB +crdb_cluster_name = "interuss_example" crdb_locality = "interuss_dss-aws-ew1" crdb_external_nodes = [] diff --git a/deploy/infrastructure/modules/terraform-aws-dss/variables.tf b/deploy/infrastructure/modules/terraform-aws-dss/variables.tf index 79c2524a4..ac88d72c5 100644 --- a/deploy/infrastructure/modules/terraform-aws-dss/variables.tf +++ b/deploy/infrastructure/modules/terraform-aws-dss/variables.tf @@ -247,6 +247,22 @@ variable "desired_scd_db_version" { default = "latest" } +variable "crdb_cluster_name" { + type = string + description = <<-EOT + A string that specifies a CRDB cluster name. This is used together to ensure that all newly created + nodes join the intended cluster when you are running multiple clusters. + The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. + The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, + and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + + At the moment, this variable is only used for helm charts deployments. + + Example: interuss_us_production + EOT +} + + variable "crdb_locality" { type = string description = <<-EOT diff --git a/deploy/infrastructure/modules/terraform-google-dss/TFVARS.md b/deploy/infrastructure/modules/terraform-google-dss/TFVARS.md index df1f8f068..dcdfbdf94 100644 --- a/deploy/infrastructure/modules/terraform-google-dss/TFVARS.md +++ b/deploy/infrastructure/modules/terraform-google-dss/TFVARS.md @@ -231,6 +231,21 @@ Use `latest` to use the latest schema version. Example: `3.1.0` +### crdb_cluster_name + +*Type: `string`* + +A string that specifies a CRDB cluster name. This is used together to ensure that all newly created +nodes join the intended cluster when you are running multiple clusters. +The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. +The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, +and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + +At the moment, this variable is only used for helm charts deployments. + +Example: interuss_us_production + + ### crdb_locality *Type: `string`* diff --git a/deploy/infrastructure/modules/terraform-google-dss/main.tf b/deploy/infrastructure/modules/terraform-google-dss/main.tf index 1d58ca9d8..5f3eff4f9 100644 --- a/deploy/infrastructure/modules/terraform-google-dss/main.tf +++ b/deploy/infrastructure/modules/terraform-google-dss/main.tf @@ -19,6 +19,7 @@ module "terraform-commons-dss" { kubernetes_namespace = var.kubernetes_namespace kubernetes_storage_class = var.google_kubernetes_storage_class app_hostname = var.app_hostname + crdb_cluster_name = var.crdb_cluster_name crdb_hostname_suffix = var.crdb_hostname_suffix should_init = var.should_init authorization = var.authorization diff --git a/deploy/infrastructure/modules/terraform-google-dss/terraform.dev.example.tfvars b/deploy/infrastructure/modules/terraform-google-dss/terraform.dev.example.tfvars index 93ecb6afd..a89ab29d0 100644 --- a/deploy/infrastructure/modules/terraform-google-dss/terraform.dev.example.tfvars +++ b/deploy/infrastructure/modules/terraform-google-dss/terraform.dev.example.tfvars @@ -24,7 +24,9 @@ image_pull_secret = "" authorization = { public_key_pem_path = "/test-certs/auth2.pem" } -should_init = true -crdb_locality = "interuss_dss-dev-w6a" +should_init = true +# CockroachDB +crdb_cluster_name = "interuss_example" +crdb_locality = "interuss_dss-dev-w6a" crdb_external_nodes = [] diff --git a/deploy/infrastructure/modules/terraform-google-dss/variables.tf b/deploy/infrastructure/modules/terraform-google-dss/variables.tf index 9e91072f9..a53f98373 100644 --- a/deploy/infrastructure/modules/terraform-google-dss/variables.tf +++ b/deploy/infrastructure/modules/terraform-google-dss/variables.tf @@ -238,6 +238,22 @@ variable "desired_scd_db_version" { default = "latest" } +variable "crdb_cluster_name" { + type = string + description = <<-EOT + A string that specifies a CRDB cluster name. This is used together to ensure that all newly created + nodes join the intended cluster when you are running multiple clusters. + The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. + The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, + and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + + At the moment, this variable is only used for helm charts deployments. + + Example: interuss_us_production + EOT +} + + variable "crdb_locality" { type = string description = <<-EOT diff --git a/deploy/infrastructure/utils/definitions/crdb_cluster_name.tf b/deploy/infrastructure/utils/definitions/crdb_cluster_name.tf new file mode 100644 index 000000000..f97d9e507 --- /dev/null +++ b/deploy/infrastructure/utils/definitions/crdb_cluster_name.tf @@ -0,0 +1,14 @@ +variable "crdb_cluster_name" { + type = string + description = <<-EOT + A string that specifies a CRDB cluster name. This is used together to ensure that all newly created + nodes join the intended cluster when you are running multiple clusters. + The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. + The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, + and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + + At the moment, this variable is only used for helm charts deployments. + + Example: interuss_us_production + EOT +} diff --git a/deploy/infrastructure/utils/variables.py b/deploy/infrastructure/utils/variables.py index 45db6bad6..e91d72769 100755 --- a/deploy/infrastructure/utils/variables.py +++ b/deploy/infrastructure/utils/variables.py @@ -34,6 +34,7 @@ "should_init", "desired_rid_db_version", "desired_scd_db_version", + "crdb_cluster_name", "crdb_locality", "crdb_external_nodes", "kubernetes_namespace" diff --git a/deploy/operations/ci/aws-1/main.tf b/deploy/operations/ci/aws-1/main.tf index 9358b15f2..350f3f02f 100644 --- a/deploy/operations/ci/aws-1/main.tf +++ b/deploy/operations/ci/aws-1/main.tf @@ -17,6 +17,7 @@ module "terraform-aws-dss" { aws_region = var.aws_region aws_route53_zone_id = var.aws_route53_zone_id cluster_name = var.cluster_name + crdb_cluster_name = var.crdb_cluster_name crdb_hostname_suffix = var.crdb_hostname_suffix crdb_locality = var.crdb_locality crdb_external_nodes = var.crdb_external_nodes diff --git a/deploy/operations/ci/aws-1/terraform.tfvars b/deploy/operations/ci/aws-1/terraform.tfvars index 51b8b9b84..ba4530f30 100644 --- a/deploy/operations/ci/aws-1/terraform.tfvars +++ b/deploy/operations/ci/aws-1/terraform.tfvars @@ -23,6 +23,7 @@ authorization = { public_key_pem_path = "/test-certs/auth2.pem" } should_init = true +crdb_cluster_name = "interuss_ci" crdb_locality = "interuss_dss-ci-aws-ue1" crdb_external_nodes = [] diff --git a/deploy/operations/ci/aws-1/variables.tf b/deploy/operations/ci/aws-1/variables.tf index 79c2524a4..ac88d72c5 100644 --- a/deploy/operations/ci/aws-1/variables.tf +++ b/deploy/operations/ci/aws-1/variables.tf @@ -247,6 +247,22 @@ variable "desired_scd_db_version" { default = "latest" } +variable "crdb_cluster_name" { + type = string + description = <<-EOT + A string that specifies a CRDB cluster name. This is used together to ensure that all newly created + nodes join the intended cluster when you are running multiple clusters. + The CRDB cluster is automatically given a randomly-generated name if an empty string is provided. + The CRDB cluster name must be 6-20 characters in length, and can include lowercase letters, numbers, + and dashes (but no leading or trailing dashes). A cluster's name cannot be edited after it is created. + + At the moment, this variable is only used for helm charts deployments. + + Example: interuss_us_production + EOT +} + + variable "crdb_locality" { type = string description = <<-EOT