Skip to content

Commit

Permalink
Update tags to current standard. Output tag list of maps. Cleanup all…
Browse files Browse the repository at this point in the history
… autoscaling references
  • Loading branch information
Steven Nemetz committed May 17, 2018
1 parent 96d827e commit e875c36
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
5 changes: 2 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")}"
}
56 changes: 17 additions & 39 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
*/

9 changes: 1 addition & 8 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 47 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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"
}

0 comments on commit e875c36

Please sign in to comment.