From e4e2ecfb3efed57a0da881359e33403c8df43987 Mon Sep 17 00:00:00 2001 From: Bryan Barajas Date: Thu, 8 Aug 2024 23:35:01 +0000 Subject: [PATCH] Biganimal module - expose a boolean variable 'TF_VAR_ba_cloud_account' to set a default for biganimal's 'cloud_account' configuration option --- README.md | 15 ++++++++------- docs/examples/aws/biganimal.yml | 19 +++++++++++-------- .../data/templates/aws/validation.tf.j2 | 1 + .../data/templates/azure/validation.tf.j2 | 1 + .../data/templates/gcloud/validation.tf.j2 | 1 + .../aws/modules/specification/outputs.tf | 12 +++++++++++- .../aws/modules/specification/variables.tf | 6 ++++++ .../azure/modules/specification/outputs.tf | 12 +++++++++++- .../azure/modules/specification/variables.tf | 6 ++++++ edbterraform/data/terraform/common_vars.tf | 15 +++++++++++---- .../gcloud/modules/specification/outputs.tf | 12 +++++++++++- .../gcloud/modules/specification/variables.tf | 6 ++++++ 12 files changed, 84 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 58d60aaf..5360d799 100644 --- a/README.md +++ b/README.md @@ -240,22 +240,23 @@ Pairing can be done by setting the allow list for the provider or using vpc-peer - To change the allow list after provisioning, the file `terraform.tfvars.json` can be directly modified and use `terraform apply` again. BigAnimal specific environment variables that can be used during `terraform plan` or `terraform apply`: -- `BA_API_URI` - api endpoint +- `BA_API_URI` (string) - api endpoint - Default: `https://portal.biganimal.com/api/v3/` - Setting access key - - `BA_ACCESS_KEY` (priority) + - `BA_ACCESS_KEY` (string) - Priority credential over BA_BEARER_TOKEN - Go to `https://portal.biganimal.com/access-keys` to create an access token that last 1-365 days. - - `BA_BEARER_TOKEN` (deprecated). + - `BA_BEARER_TOKEN` (string) - Deprecated in favor of BA_ACCESS_KEY. - [get-token.sh script](https://raw.githubusercontent.com/EnterpriseDB/cloud-utilities/main/api/get-token.sh) requires manual intervention every: - New token request - 30 days since initial token request - Expired token is reused -- `TF_VAR_ba_project_id` - Biganimal project id if not defined within the yaml configuration. +- `TF_VAR_ba_project_id` (string) - Biganimal project id default if not defined within the yaml configuration. - For persistence, a tfvars file can be created with `ba_project_id` defined. +- `TF_VAR_ba_cloud_account` (boolean) - Biganimal bring-your-own-account default if not defined within the yaml configuration. - Custom Image (Only available for dev environments) - - `TF_VAR_ba_pg_image` - Biganimal postgres image if not defined within the yaml configuration - - `TF_VAR_ba_proxy_image` - Biganimal proxy image if not defined within the yaml configuration - - `TF_VAR_ba_ignore_image` - Ignore image values (Default: `false`) + - `TF_VAR_ba_pg_image` (string) - Biganimal postgres image default if not defined within the yaml configuration + - `TF_VAR_ba_proxy_image` (string) - Biganimal proxy image default if not defined within the yaml configuration + - `TF_VAR_ba_ignore_image` (string) - Ignore image values (Default: `false`) ### Environment variables Terraform allows for top-level variables to be defined with cli arguments or environment variables. diff --git a/docs/examples/aws/biganimal.yml b/docs/examples/aws/biganimal.yml index 9871d507..d8b3af54 100644 --- a/docs/examples/aws/biganimal.yml +++ b/docs/examples/aws/biganimal.yml @@ -17,19 +17,22 @@ aws: # pg: "" # proxy: "" data_groups: + # only pgd support multiple data nodes, single and ha should only define a single data node one: - cloud_account: false + # Environment variable 'TF_VAR_ba_cloud_account' can be used to set a default instead of hardcoding + # cloud_account: false region: us-east-1 - type: pgd - node_count: 3 - engine: epas + # type must match across data nodes + type: pgd # single | ha | pgd - supports 1-2 data nodes + node_count: 3 # single = 1 node | ha = 2-3 nodes | pgd = 2-3 nodes for 1 data group or 3 for 2 data groups + engine: epas # epas | pgextended | postgres engine_version: 14 instance_type: c5.large volume: type: gp3 properties: gp3 size_gb: 32 - # Use this to create a separate volume for the WAL + # Create a separate volume for the WAL #wal_volume: # type: gp3 # properties: gp3 @@ -48,7 +51,7 @@ aws: allowed_machines: - "*" two: - cloud_account: false + # cloud_account: false region: us-east-2 type: pgd node_count: 3 @@ -59,7 +62,6 @@ aws: type: gp3 properties: gp3 size_gb: 32 - # Use this to create a separate volume for the WAL #wal_volume: # type: gp3 # properties: gp3 @@ -77,9 +79,10 @@ aws: description: localhost allowed_machines: - "*" + # Witness group only required when 2 data groups are configured witness_groups: one: - cloud_account: false + # cloud_account: false region: us-west-2 cloud_service_provider: aws tags: diff --git a/edbterraform/data/templates/aws/validation.tf.j2 b/edbterraform/data/templates/aws/validation.tf.j2 index faa4d363..3249de4c 100644 --- a/edbterraform/data/templates/aws/validation.tf.j2 +++ b/edbterraform/data/templates/aws/validation.tf.j2 @@ -12,6 +12,7 @@ module "spec" { ba_project_id_default = var.ba_project_id ba_ignore_image_default = var.ba_ignore_image + ba_cloud_account_default = var.ba_cloud_account ba_pg_image_default = var.ba_pg_image ba_proxy_image_default = var.ba_proxy_image } diff --git a/edbterraform/data/templates/azure/validation.tf.j2 b/edbterraform/data/templates/azure/validation.tf.j2 index 6fb08c6b..2beeee1a 100644 --- a/edbterraform/data/templates/azure/validation.tf.j2 +++ b/edbterraform/data/templates/azure/validation.tf.j2 @@ -12,6 +12,7 @@ module "spec" { ba_project_id_default = var.ba_project_id ba_ignore_image_default = var.ba_ignore_image + ba_cloud_account_default = var.ba_cloud_account ba_pg_image_default = var.ba_pg_image ba_proxy_image_default = var.ba_proxy_image } diff --git a/edbterraform/data/templates/gcloud/validation.tf.j2 b/edbterraform/data/templates/gcloud/validation.tf.j2 index 6fb08c6b..2beeee1a 100644 --- a/edbterraform/data/templates/gcloud/validation.tf.j2 +++ b/edbterraform/data/templates/gcloud/validation.tf.j2 @@ -12,6 +12,7 @@ module "spec" { ba_project_id_default = var.ba_project_id ba_ignore_image_default = var.ba_ignore_image + ba_cloud_account_default = var.ba_cloud_account ba_pg_image_default = var.ba_pg_image ba_proxy_image_default = var.ba_proxy_image } diff --git a/edbterraform/data/terraform/aws/modules/specification/outputs.tf b/edbterraform/data/terraform/aws/modules/specification/outputs.tf index 804d2896..7d5b0948 100644 --- a/edbterraform/data/terraform/aws/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/aws/modules/specification/outputs.tf @@ -149,7 +149,17 @@ output "biganimal" { # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) - }) + }) + data_groups = { + for data_group_name, data_group_spec in biganimal_spec.data_groups : data_group_name => merge(data_group_spec, { + cloud_account = data_group_spec.cloud_account == null ? var.ba_cloud_account_default : data_group_spec.cloud_account + }) + } + witness_groups = { + for witness_group_name, witness_group_spec in biganimal_spec.witness_groups : witness_group_name => merge(witness_group_spec, { + cloud_account = witness_group_spec.cloud_account == null ? var.ba_cloud_account_default : witness_group_spec.cloud_account + }) + } }) } } diff --git a/edbterraform/data/terraform/aws/modules/specification/variables.tf b/edbterraform/data/terraform/aws/modules/specification/variables.tf index 4fb68a95..dd87047e 100644 --- a/edbterraform/data/terraform/aws/modules/specification/variables.tf +++ b/edbterraform/data/terraform/aws/modules/specification/variables.tf @@ -226,6 +226,12 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_cloud_account_default" { + description = "BigAnimal cloud account default" + type = string + nullable = true +} + variable "ba_pg_image_default" { description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" type = string diff --git a/edbterraform/data/terraform/azure/modules/specification/outputs.tf b/edbterraform/data/terraform/azure/modules/specification/outputs.tf index 3900ee06..eabdc69f 100644 --- a/edbterraform/data/terraform/azure/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/azure/modules/specification/outputs.tf @@ -137,7 +137,17 @@ output "biganimal" { # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) - }) + }) + data_groups = { + for data_group_name, data_group_spec in biganimal_spec.data_groups : data_group_name => merge(data_group_spec, { + cloud_account = data_group_spec.cloud_account == null ? var.ba_cloud_account_default : data_group_spec.cloud_account + }) + } + witness_groups = { + for witness_group_name, witness_group_spec in biganimal_spec.witness_groups : witness_group_name => merge(witness_group_spec, { + cloud_account = witness_group_spec.cloud_account == null ? var.ba_cloud_account_default : witness_group_spec.cloud_account + }) + } }) } } diff --git a/edbterraform/data/terraform/azure/modules/specification/variables.tf b/edbterraform/data/terraform/azure/modules/specification/variables.tf index 058dace1..ff900b70 100644 --- a/edbterraform/data/terraform/azure/modules/specification/variables.tf +++ b/edbterraform/data/terraform/azure/modules/specification/variables.tf @@ -181,6 +181,12 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_cloud_account_default" { + description = "BigAnimal cloud account default" + type = string + nullable = true +} + variable "ba_pg_image_default" { description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" type = string diff --git a/edbterraform/data/terraform/common_vars.tf b/edbterraform/data/terraform/common_vars.tf index babc779c..5e957b0f 100644 --- a/edbterraform/data/terraform/common_vars.tf +++ b/edbterraform/data/terraform/common_vars.tf @@ -20,28 +20,35 @@ variable "cloud_service_provider" { } variable "ba_project_id" { - description = "BigAnimal project ID to use if not defined within the biganimal configuration" + description = "BigAnimal project ID default if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_cloud_account" { + description = "Bring-Your-Own-Account default if 'cloud_account' is not defined within the biganimal configuration" type = string nullable = true default = null } variable "ba_pg_image" { - description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" + description = "Dev only: BigAnimal postgres image default if not defined within the biganimal configuration" type = string nullable = true default = null } variable "ba_proxy_image" { - description = "Dev only: BigAnimal proxy image to use if not defined within the biganimal configuration" + description = "Dev only: BigAnimal proxy image default if not defined within the biganimal configuration" type = string nullable = true default = null } variable "ba_ignore_image" { - description = "Ignore biganimal custom images" + description = "Ignore biganimal custom images input" type = bool nullable = false default = false diff --git a/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf b/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf index f5e6bf44..21cfb62b 100644 --- a/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf @@ -140,7 +140,17 @@ output "biganimal" { # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) - }) + }) + data_groups = { + for data_group_name, data_group_spec in biganimal_spec.data_groups : data_group_name => merge(data_group_spec, { + cloud_account = data_group_spec.cloud_account == null ? var.ba_cloud_account_default : data_group_spec.cloud_account + }) + } + witness_groups = { + for witness_group_name, witness_group_spec in biganimal_spec.witness_groups : witness_group_name => merge(witness_group_spec, { + cloud_account = witness_group_spec.cloud_account == null ? var.ba_cloud_account_default : witness_group_spec.cloud_account + }) + } }) } } diff --git a/edbterraform/data/terraform/gcloud/modules/specification/variables.tf b/edbterraform/data/terraform/gcloud/modules/specification/variables.tf index bcfbc9e5..c608dba6 100644 --- a/edbterraform/data/terraform/gcloud/modules/specification/variables.tf +++ b/edbterraform/data/terraform/gcloud/modules/specification/variables.tf @@ -191,6 +191,12 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_cloud_account_default" { + description = "BigAnimal cloud account default" + type = string + nullable = true +} + variable "ba_pg_image_default" { description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" type = string