From e875c36436e8fd2bd3d610c05a59f7123dd90e22 Mon Sep 17 00:00:00 2001 From: Steven Nemetz Date: Thu, 17 May 2018 13:47:12 -0700 Subject: [PATCH] Update tags to current standard. Output tag list of maps. Cleanup all autoscaling references --- examples/complete/main.tf | 5 ++-- main.tf | 56 +++++++++++-------------------------- outputs.tf | 9 +----- variables.tf | 59 +++++++++++++++++++++++++++++++-------- 4 files changed, 67 insertions(+), 62 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index c4e9358..d709e0f 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -6,7 +6,6 @@ module "complete" { namespace-org = true #attributes = ["role", "policy", "use", ""] - attributes = ["8080"] - tags = "${map("Key", "Value")}" - autoscaling_group = true + attributes = ["8080"] + tags = "${map("Key", "Value")}" } diff --git a/main.tf b/main.tf index 2f290b5..9fadde9 100644 --- a/main.tf +++ b/main.tf @@ -3,14 +3,6 @@ # # TODO: # Change where replace is done. Move to earlier in process. On initial `name`? -# Create tags_asg list from tags map. If possible -# New input tags_asg -> tags_asg with standard tags added - -module "autoscaling_group" { - source = "devops-workflow/boolean/local" - version = "0.1.1" - value = "${var.autoscaling_group}" -} module "enabled" { source = "devops-workflow/boolean/local" @@ -114,50 +106,36 @@ data "null_data_source" "ids-trunc-attr" { } } -# 2 lists keys and values -# TODO: need to change to list of maps for all label names +# Create tags as 2 lists keys and values data "null_data_source" "tags" { count = "${module.enabled.value ? length(var.names) : 0}" inputs = { #TODO: only add Organization if not "" - tag_keys = "Name,Environment,Organization,Terraform" + tag_keys = "Name,Component,Environment,Monitor,Organization,Owner,Product,Service,Team,Terraform" tag_vals = "${join(",",list( element(data.null_data_source.ids.*.outputs.id, count.index), + var.component, local.env, + var.monitor, local.org, - "true") - )}" + var.owner, + var.product, + var.service, + var.team, + "true" + ))}" } } -/* -data "null_data_source" "tag_list" { +# Rebuild tags into list of maps and add any tags passed in +data "null_data_source" "tags_list" { count = "${module.enabled.value ? length(var.names) : 0}" - inputs = { - tags = "${}" - } -} -/* -output "tags" { - description = "Tags map merged with standard tags" - value = "${merge( - zipmap(split(",",data.null_data_source.tags.*.outputs.tag_keys[0]), - split(",",data.null_data_source.tags.*.outputs.tag_vals[0])), + + inputs = "${merge( + zipmap( + compact(split(",", element(data.null_data_source.tags.*.outputs.tag_keys, count.index))), + compact(split(",", element(data.null_data_source.tags.*.outputs.tag_vals, count.index)))), var.tags)}" } -/**/ -/* -resource "null_resource" "this" { - count = "${module.enabled.value ? length(var.names) : 0}" - # TODO: change all name related refs to array refs - # split into multi resources to be able to reference created labels - triggers = { - } - lifecycle { - create_before_destroy = true - } -} -*/ - diff --git a/outputs.tf b/outputs.tf index c555ed2..12b87f9 100644 --- a/outputs.tf +++ b/outputs.tf @@ -53,15 +53,8 @@ output "organization" { value = "${local.org}" } -# TODO: need to change to list of maps for all label names output "tags" { - description = "Tags map merged with standard tags" - - value = "${merge( - zipmap( - split(",", element(concat(data.null_data_source.tags.*.outputs.tag_keys, list("")),0)), - split(",", element(concat(data.null_data_source.tags.*.outputs.tag_vals, list("")),0))), - var.tags)}" + value = "${data.null_data_source.tags_list.*.outputs}" } //debugging diff --git a/variables.tf b/variables.tf index 09daba0..4787804 100644 --- a/variables.tf +++ b/variables.tf @@ -4,28 +4,27 @@ variable "attributes" { default = [] } -variable "autoscaling_group" { - description = "DOES NOTHING YET. If true, generate ASG tags map resource" - default = false +variable "component" { + description = "TAG: Underlying, dedicated piece of service (Cache, DB, ...)" + type = "string" + default = "UNDEF" } variable "delimiter" { description = "Delimiter to be used between `name`, `namespaces`, `attributes`, etc." + type = "string" default = "-" } -variable "enabled" { - description = "" - default = true -} - variable "environment" { description = "Environment (ex: `dev`, `qa`, `stage`, `prod`). (Second or top level namespace. Depending on namespacing options)" + type = "string" } -variable "names" { - description = "Base names for resources" - type = "list" +variable "monitor" { + description = "TAG: Should resource be monitored" + type = "string" + default = "UNDEF" } variable "namespace-env" { @@ -39,12 +38,48 @@ variable "namespace-org" { } variable "organization" { - description = "Organization name (Top level namespace)." + description = "Organization name (Top level namespace)" + type = "string" default = "" } +variable "owner" { + description = "TAG: Owner of the service" + type = "string" + default = "UNDEF" +} + +variable "product" { + description = "TAG: Company/business product" + type = "string" + default = "UNDEF" +} + +variable "service" { + description = "TAG: Application (microservice) name" + type = "string" + default = "UNDEF" +} + variable "tags" { description = "A map of additional tags" type = "map" default = {} } + +variable "team" { + description = "TAG: Department/team of people responsible for service" + type = "string" + default = "UNDEF" +} + +// Variables different than in terraform-local-label +variable "enabled" { + description = "Set to false to prevent the module from creating anything" + default = true +} + +variable "names" { + description = "Base names for resources" + type = "list" +}