From 94ab0ef521075d85f06dff3cb26bd0722b67b66a Mon Sep 17 00:00:00 2001 From: Ben Doerr Date: Fri, 1 Sep 2023 16:55:47 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(feature):=20Adds=20new=20'project'?= =?UTF-8?q?=20field=20to=20support=20label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/complete/complete.tfvars | 1 + examples/complete/ctx_full.tf | 1 + examples/complete/variables.tf | 8 ++++++++ main.tf | 2 ++ outputs.tf | 6 ++++++ test/examples_complete_test.go | 3 +++ variables.tf | 9 +++++++++ 7 files changed, 30 insertions(+) diff --git a/examples/complete/complete.tfvars b/examples/complete/complete.tfvars index a6437aa..558c962 100644 --- a/examples/complete/complete.tfvars +++ b/examples/complete/complete.tfvars @@ -6,6 +6,7 @@ region = "us-west-2" region_short = "uw2" instance = "demo" instance_short = "dmo" +project = "test" attributes = [ "attr1" ] diff --git a/examples/complete/ctx_full.tf b/examples/complete/ctx_full.tf index f8e84e3..a92d1d6 100644 --- a/examples/complete/ctx_full.tf +++ b/examples/complete/ctx_full.tf @@ -8,6 +8,7 @@ module "ctx_full" { region_short = var.region_short instance = var.instance instance_short = var.instance_short + project = var.project attributes = var.attributes tags = var.tags } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 53e7c22..f863c00 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -71,6 +71,14 @@ variable "instance_short" { EOT } +variable "project" { + type = string + default = "" + description = <<-EOT + Unique identifier for this project + EOT +} + variable "attributes" { type = list(string) default = [] diff --git a/main.tf b/main.tf index 90dc92b..dff2f90 100644 --- a/main.tf +++ b/main.tf @@ -49,11 +49,13 @@ locals { region_tags = { "Region" = local.gvn_region } instance_tags = { "Instance" = local.gvn_instance } context_worksp_tags = { "Workspace" = terraform.workspace } + project_tags = { "Project" = var.project } tags = merge( local.gvn_tags, local.gvn_role != "" ? local.role_tags : {}, local.gvn_region != "" ? local.region_tags : {}, local.gvn_instance != "" ? local.instance_tags : {}, + var.project != "" ? local.project_tags : {}, terraform.workspace != "" ? local.context_worksp_tags : {}, ) } diff --git a/outputs.tf b/outputs.tf index 0fc631d..8a9f069 100644 --- a/outputs.tf +++ b/outputs.tf @@ -38,6 +38,11 @@ output "instance_short" { description = "The evaluated instance" } +output "project" { + value = var.project + description = "The evaluated project" +} + output "dns_namespace" { value = local.dns_namespace description = "A DNS namespace" @@ -65,6 +70,7 @@ output "shared" { instance = local.gvn_instance instance_short = local.instance_short namespace = local.gvn_namespace + project = var.project tags = local.tags } description = "Used for sharing the context with other modules" diff --git a/test/examples_complete_test.go b/test/examples_complete_test.go index aafe36b..920453f 100644 --- a/test/examples_complete_test.go +++ b/test/examples_complete_test.go @@ -42,6 +42,7 @@ func TestExamplesComplete(t *testing.T) { Region_Short string Role string Role_Short string + Project string Tags map[string]string } @@ -65,12 +66,14 @@ func TestExamplesComplete(t *testing.T) { Region_Short: "uw2", Role: "production", Role_Short: "prd", + Project: "test", Tags: map[string]string{ "ExtraTag": "ExtraTagValue", "Instance": "demo", "Region": "us-west-2", "Role": "production", "Workspace": "default", + "Project": "test", }, }, }, diff --git a/variables.tf b/variables.tf index 72158b7..ed2de6d 100644 --- a/variables.tf +++ b/variables.tf @@ -71,6 +71,14 @@ variable "instance_short" { EOT } +variable "project" { + type = string + default = "" + description = <<-EOT + Unique identifier for this project + EOT +} + variable "attributes" { type = list(string) default = [] @@ -96,6 +104,7 @@ variable "context" { region_short = "" role = "" role_short = "" + project = "" tags = {} } description = "Allows the merging of an existing context with this one."