diff --git a/README.md b/README.md index 9e5b37d3..58d60aaf 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,10 @@ BigAnimal specific environment variables that can be used during `terraform plan - Expired token is reused - `TF_VAR_ba_project_id` - Biganimal project id if not defined within the yaml configuration. - For persistence, a tfvars file can be created with `ba_project_id` defined. +- 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`) ### 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 2b44a700..9871d507 100644 --- a/docs/examples/aws/biganimal.yml +++ b/docs/examples/aws/biganimal.yml @@ -11,7 +11,11 @@ aws: # or it can be configured per cluster configuration: #project: # id: prj_1234567890 - # password: "ndslniv&03ind**vDdjfnjv" # auto-generated if not provided + # password: "" # auto-generated if not provided + # Only available for dev environments and can be set as environment variables + #image: + # pg: "" + # proxy: "" data_groups: one: cloud_account: false diff --git a/edbterraform/data/templates/aws/validation.tf.j2 b/edbterraform/data/templates/aws/validation.tf.j2 index 7174c7fd..faa4d363 100644 --- a/edbterraform/data/templates/aws/validation.tf.j2 +++ b/edbterraform/data/templates/aws/validation.tf.j2 @@ -1,12 +1,19 @@ # All modules should reference this module's outputs -# During terraform plan, will act as basic validation of yaml input(var.spec) with variable validation and preconditions -# During terraform apply, will check for availability of resources with data sources and postconditions +# During terraform plan, will act as basic validation of yaml input(var.spec) with: +# - variable validation +# - preconditions +# - data sources as long as there is no resource dependency, which then postpones it to 'terraform apply' module "spec" { source = "./modules/specification" spec = var.spec + force_ssh_access = var.force_service_machines + ba_project_id_default = var.ba_project_id + ba_ignore_image_default = var.ba_ignore_image + ba_pg_image_default = var.ba_pg_image + ba_proxy_image_default = var.ba_proxy_image } # All modules should use the last created module in their depends_on through jinja diff --git a/edbterraform/data/templates/azure/validation.tf.j2 b/edbterraform/data/templates/azure/validation.tf.j2 index 0ad2af87..6fb08c6b 100644 --- a/edbterraform/data/templates/azure/validation.tf.j2 +++ b/edbterraform/data/templates/azure/validation.tf.j2 @@ -1,13 +1,19 @@ -# All modules should reference this module's outputs for input from user -# All modules should reference this module in depends_on -# During terraform plan, will act as basic validation of yaml input(var.spec) with variable validation and preconditions -# During terraform apply, will check for availability of resources with data sources and postconditions +# All modules should reference this module's outputs +# During terraform plan, will act as basic validation of yaml input(var.spec) with: +# - variable validation +# - preconditions +# - data sources as long as there is no resource dependency, which then postpones it to 'terraform apply' module "spec" { source = "./modules/specification" spec = var.spec + force_ssh_access = var.force_service_machines + ba_project_id_default = var.ba_project_id + ba_ignore_image_default = var.ba_ignore_image + ba_pg_image_default = var.ba_pg_image + ba_proxy_image_default = var.ba_proxy_image } resource "null_resource" "validation" { diff --git a/edbterraform/data/templates/gcloud/validation.tf.j2 b/edbterraform/data/templates/gcloud/validation.tf.j2 index 0ad2af87..6fb08c6b 100644 --- a/edbterraform/data/templates/gcloud/validation.tf.j2 +++ b/edbterraform/data/templates/gcloud/validation.tf.j2 @@ -1,13 +1,19 @@ -# All modules should reference this module's outputs for input from user -# All modules should reference this module in depends_on -# During terraform plan, will act as basic validation of yaml input(var.spec) with variable validation and preconditions -# During terraform apply, will check for availability of resources with data sources and postconditions +# All modules should reference this module's outputs +# During terraform plan, will act as basic validation of yaml input(var.spec) with: +# - variable validation +# - preconditions +# - data sources as long as there is no resource dependency, which then postpones it to 'terraform apply' module "spec" { source = "./modules/specification" spec = var.spec + force_ssh_access = var.force_service_machines + ba_project_id_default = var.ba_project_id + ba_ignore_image_default = var.ba_ignore_image + ba_pg_image_default = var.ba_pg_image + ba_proxy_image_default = var.ba_proxy_image } resource "null_resource" "validation" { diff --git a/edbterraform/data/terraform/aws/modules/specification/outputs.tf b/edbterraform/data/terraform/aws/modules/specification/outputs.tf index 213314a2..804d2896 100644 --- a/edbterraform/data/terraform/aws/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/aws/modules/specification/outputs.tf @@ -139,7 +139,13 @@ output "region_auroras" { output "biganimal" { value = { for name, biganimal_spec in var.spec.biganimal : name => merge(biganimal_spec, { - project = biganimal_spec.project.id == null ? {"id":"${var.ba_project_id_default}"} : biganimal_spec.project + project = { + id = biganimal_spec.project.id == null || biganimal_spec.project.id == "" ? var.ba_project_id_default : biganimal_spec.project.id + } + image = var.ba_ignore_image_default ? { pg = null, proxy = null } : { + pg = biganimal_spec.image.pg == null || biganimal_spec.image.pg == "" ? var.ba_pg_image_default : biganimal_spec.image.pg + proxy = biganimal_spec.image.proxy == null || biganimal_spec.image.proxy == "" ? var.ba_proxy_image_default : biganimal_spec.image.proxy + } # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) diff --git a/edbterraform/data/terraform/aws/modules/specification/variables.tf b/edbterraform/data/terraform/aws/modules/specification/variables.tf index 34c042b2..4fb68a95 100644 --- a/edbterraform/data/terraform/aws/modules/specification/variables.tf +++ b/edbterraform/data/terraform/aws/modules/specification/variables.tf @@ -226,6 +226,27 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_pg_image_default" { + description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_proxy_image_default" { + description = "Dev only: BigAnimal proxy image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_ignore_image_default" { + description = "Ignore biganimal custom images" + type = bool + nullable = false + default = false +} + locals { cluster_name = can(var.spec.tags.cluster_name) ? var.spec.tags.cluster_name : "AWS-Cluster-default" created_by = can(var.spec.tags.created_by) ? var.spec.tags.created_by : "EDB-Terraform-AWS" diff --git a/edbterraform/data/terraform/azure/modules/specification/outputs.tf b/edbterraform/data/terraform/azure/modules/specification/outputs.tf index e3012e92..3900ee06 100644 --- a/edbterraform/data/terraform/azure/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/azure/modules/specification/outputs.tf @@ -127,7 +127,13 @@ output "region_databases" { output "biganimal" { value = { for name, biganimal_spec in var.spec.biganimal : name => merge(biganimal_spec, { - project = biganimal_spec.project.id == null ? {"id":"${var.ba_project_id_default}"} : biganimal_spec.project + project = { + id = biganimal_spec.project.id == null || biganimal_spec.project.id == "" ? var.ba_project_id_default : biganimal_spec.project.id + } + image = var.ba_ignore_image_default ? { pg = null, proxy = null } : { + pg = biganimal_spec.image.pg == null || biganimal_spec.image.pg == "" ? var.ba_pg_image_default : biganimal_spec.image.pg + proxy = biganimal_spec.image.proxy == null || biganimal_spec.image.proxy == "" ? var.ba_proxy_image_default : biganimal_spec.image.proxy + } # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) diff --git a/edbterraform/data/terraform/azure/modules/specification/variables.tf b/edbterraform/data/terraform/azure/modules/specification/variables.tf index 5a7abd46..058dace1 100644 --- a/edbterraform/data/terraform/azure/modules/specification/variables.tf +++ b/edbterraform/data/terraform/azure/modules/specification/variables.tf @@ -181,6 +181,27 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_pg_image_default" { + description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_proxy_image_default" { + description = "Dev only: BigAnimal proxy image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_ignore_image_default" { + description = "Ignore biganimal custom images" + type = bool + nullable = false + default = false +} + locals { cluster_name = can(var.spec.tags.cluster_name) ? var.spec.tags.cluster_name : "Azure-Cluster-default" created_by = can(var.spec.tags.created_by) ? var.spec.tags.created_by : "EDB-Terraform-Azure" diff --git a/edbterraform/data/terraform/common_vars.tf b/edbterraform/data/terraform/common_vars.tf index 024179b8..babc779c 100644 --- a/edbterraform/data/terraform/common_vars.tf +++ b/edbterraform/data/terraform/common_vars.tf @@ -26,6 +26,27 @@ variable "ba_project_id" { default = null } +variable "ba_pg_image" { + description = "Dev only: BigAnimal postgres image to use 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" + type = string + nullable = true + default = null +} + +variable "ba_ignore_image" { + description = "Ignore biganimal custom images" + type = bool + nullable = false + default = false +} + variable "public_cidrblocks" { description = "Public CIDR block" type = list(string) diff --git a/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf b/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf index 5fffbbc5..f5e6bf44 100644 --- a/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf +++ b/edbterraform/data/terraform/gcloud/modules/specification/outputs.tf @@ -130,7 +130,13 @@ output "region_alloys" { output "biganimal" { value = { for name, biganimal_spec in var.spec.biganimal : name => merge(biganimal_spec, { - project = biganimal_spec.project.id == null ? {"id":"${var.ba_project_id_default}"} : biganimal_spec.project + project = { + id = biganimal_spec.project.id == null || biganimal_spec.project.id == "" ? var.ba_project_id_default : biganimal_spec.project.id + } + image = var.ba_ignore_image_default ? { pg = null, proxy = null } : { + pg = biganimal_spec.image.pg == null || biganimal_spec.image.pg == "" ? var.ba_pg_image_default : biganimal_spec.image.pg + proxy = biganimal_spec.image.proxy == null || biganimal_spec.image.proxy == "" ? var.ba_proxy_image_default : biganimal_spec.image.proxy + } # spec project tags tags = merge(local.tags, biganimal_spec.tags, { Name = format("%s-%s-%s", name, local.cluster_name, random_id.apply.id) diff --git a/edbterraform/data/terraform/gcloud/modules/specification/variables.tf b/edbterraform/data/terraform/gcloud/modules/specification/variables.tf index bb5219f6..bcfbc9e5 100644 --- a/edbterraform/data/terraform/gcloud/modules/specification/variables.tf +++ b/edbterraform/data/terraform/gcloud/modules/specification/variables.tf @@ -191,6 +191,27 @@ variable "ba_project_id_default" { nullable = true } +variable "ba_pg_image_default" { + description = "Dev only: BigAnimal postgres image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_proxy_image_default" { + description = "Dev only: BigAnimal proxy image to use if not defined within the biganimal configuration" + type = string + nullable = true + default = null +} + +variable "ba_ignore_image_default" { + description = "Ignore biganimal custom images" + type = bool + nullable = false + default = false +} + locals { cluster_name = can(var.spec.tags.cluster_name) ? var.spec.tags.cluster_name : "GCloud-Cluster-default" created_by = can(var.spec.tags.created_by) ? var.spec.tags.created_by : "EDB-Terraform-GCloud"