Skip to content

Commit

Permalink
Biganimal module - pg and proxy image can be set or ignored with an e…
Browse files Browse the repository at this point in the history
…nvironment variable
  • Loading branch information
bryan-bar committed Jun 22, 2024
1 parent c2bd0a4 commit 999de2c
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion docs/examples/aws/biganimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions edbterraform/data/templates/aws/validation.tf.j2
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 10 additions & 4 deletions edbterraform/data/templates/azure/validation.tf.j2
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
14 changes: 10 additions & 4 deletions edbterraform/data/templates/gcloud/validation.tf.j2
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions edbterraform/data/terraform/aws/modules/specification/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions edbterraform/data/terraform/common_vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 999de2c

Please sign in to comment.