Skip to content

Commit

Permalink
Merge pull request #127 from kbst/customenvnames
Browse files Browse the repository at this point in the history
Extend configuration inheritance implementation
  • Loading branch information
pst authored Aug 24, 2020
2 parents 08ab0e6 + e18c6b7 commit 74484ff
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 28 deletions.
15 changes: 8 additions & 7 deletions aws/cluster/configuration.tf
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
6 changes: 6 additions & 0 deletions aws/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
15 changes: 8 additions & 7 deletions azurerm/cluster/configuration.tf
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
6 changes: 6 additions & 0 deletions azurerm/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
15 changes: 15 additions & 0 deletions common/configuration/outputs.tf
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 9 additions & 0 deletions common/configuration/variables.tf
Original file line number Diff line number Diff line change
@@ -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."
}
4 changes: 4 additions & 0 deletions common/configuration/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
15 changes: 8 additions & 7 deletions google/cluster/configuration.tf
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
6 changes: 6 additions & 0 deletions google/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
15 changes: 8 additions & 7 deletions kind/cluster/configuration.tf
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
6 changes: 6 additions & 0 deletions kind/cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 74484ff

Please sign in to comment.