diff --git a/aws/cluster/configuration.tf b/aws/cluster/configuration.tf index 77dc4990..cfc65192 100644 --- a/aws/cluster/configuration.tf +++ b/aws/cluster/configuration.tf @@ -1,12 +1,13 @@ -locals { - # apps config and merged ops config - workspaces = { - apps = var.configuration["apps"] - ops = merge(var.configuration["apps"], var.configuration["ops"]) - } +module "configuration" { + source = "../../common/configuration" + + configuration = var.configuration + base_key = var.base_key +} +locals { # current workspace config - cfg = local.workspaces[terraform.workspace] + cfg = module.configuration.merged[terraform.workspace] name_prefix = local.cfg["name_prefix"] diff --git a/aws/cluster/variables.tf b/aws/cluster/variables.tf index 89d2c16d..907dbd4f 100644 --- a/aws/cluster/variables.tf +++ b/aws/cluster/variables.tf @@ -8,3 +8,9 @@ variable "manifest_path" { description = "Path to Kustomize overlay to build." default = null } + +variable "base_key" { + type = string + description = "The key in the configuration map all other keys inherit from." + default = "apps" +} diff --git a/azurerm/cluster/configuration.tf b/azurerm/cluster/configuration.tf index 408613e3..eb86b5d6 100644 --- a/azurerm/cluster/configuration.tf +++ b/azurerm/cluster/configuration.tf @@ -1,12 +1,13 @@ -locals { - # apps config and merged ops config - workspaces = { - apps = var.configuration["apps"] - ops = merge(var.configuration["apps"], var.configuration["ops"]) - } +module "configuration" { + source = "../../common/configuration" + + configuration = var.configuration + base_key = var.base_key +} +locals { # current workspace config - cfg = local.workspaces[terraform.workspace] + cfg = module.configuration.merged[terraform.workspace] name_prefix = local.cfg["name_prefix"] diff --git a/azurerm/cluster/variables.tf b/azurerm/cluster/variables.tf index 89d2c16d..907dbd4f 100644 --- a/azurerm/cluster/variables.tf +++ b/azurerm/cluster/variables.tf @@ -8,3 +8,9 @@ variable "manifest_path" { description = "Path to Kustomize overlay to build." default = null } + +variable "base_key" { + type = string + description = "The key in the configuration map all other keys inherit from." + default = "apps" +} diff --git a/common/configuration/outputs.tf b/common/configuration/outputs.tf new file mode 100644 index 00000000..81761d83 --- /dev/null +++ b/common/configuration/outputs.tf @@ -0,0 +1,15 @@ +locals { + base = { + (var.base_key) = var.configuration[var.base_key] + } + + overlays = { + for name, _ in var.configuration : + name => merge(var.configuration[var.base_key], var.configuration[name]) + if name != var.base_key + } +} + +output "merged" { + value = merge(local.base, local.overlays) +} diff --git a/common/configuration/variables.tf b/common/configuration/variables.tf new file mode 100644 index 00000000..3dfd4c83 --- /dev/null +++ b/common/configuration/variables.tf @@ -0,0 +1,9 @@ +variable "configuration" { + type = map(map(string)) + description = "Map with per workspace cluster configuration." +} + +variable "base_key" { + type = string + description = "The key in the configuration map all other keys inherit from." +} diff --git a/common/configuration/versions.tf b/common/configuration/versions.tf new file mode 100644 index 00000000..ac97c6ac --- /dev/null +++ b/common/configuration/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/google/cluster/configuration.tf b/google/cluster/configuration.tf index c62f98c1..aeb414fc 100644 --- a/google/cluster/configuration.tf +++ b/google/cluster/configuration.tf @@ -1,12 +1,13 @@ -locals { - # apps config and merged ops config - workspaces = { - apps = var.configuration["apps"] - ops = merge(var.configuration["apps"], var.configuration["ops"]) - } +module "configuration" { + source = "../../common/configuration" + + configuration = var.configuration + base_key = var.base_key +} +locals { # current workspace config - cfg = local.workspaces[terraform.workspace] + cfg = module.configuration.merged[terraform.workspace] name_prefix = local.cfg["name_prefix"] diff --git a/google/cluster/variables.tf b/google/cluster/variables.tf index 89d2c16d..907dbd4f 100644 --- a/google/cluster/variables.tf +++ b/google/cluster/variables.tf @@ -8,3 +8,9 @@ variable "manifest_path" { description = "Path to Kustomize overlay to build." default = null } + +variable "base_key" { + type = string + description = "The key in the configuration map all other keys inherit from." + default = "apps" +} diff --git a/kind/cluster/configuration.tf b/kind/cluster/configuration.tf index e714c6ac..74ec779e 100644 --- a/kind/cluster/configuration.tf +++ b/kind/cluster/configuration.tf @@ -1,12 +1,13 @@ -locals { - # apps config and merged ops config - workspaces = { - apps = var.configuration["apps"] - ops = merge(var.configuration["apps"], var.configuration["ops"]) - } +module "configuration" { + source = "../../common/configuration" + + configuration = var.configuration + base_key = var.base_key +} +locals { # current workspace config - cfg = local.workspaces[terraform.workspace] + cfg = module.configuration.merged[terraform.workspace] name_prefix = local.cfg["name_prefix"] diff --git a/kind/cluster/variables.tf b/kind/cluster/variables.tf index 89d2c16d..907dbd4f 100644 --- a/kind/cluster/variables.tf +++ b/kind/cluster/variables.tf @@ -8,3 +8,9 @@ variable "manifest_path" { description = "Path to Kustomize overlay to build." default = null } + +variable "base_key" { + type = string + description = "The key in the configuration map all other keys inherit from." + default = "apps" +}