Skip to content

Commit

Permalink
fix: tflint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
themaheshyadav committed Jun 8, 2023
1 parent c3515ca commit 2c511fa
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 40 deletions.
3 changes: 0 additions & 3 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ usage : |-
environment = "test"
label_order = ["name", "environment"]
attributes = ["private"]
extra_tags = {
Application = "test"
}
}
```
3 changes: 0 additions & 3 deletions _examples/complete/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ module "labels" {
environment = "test"
label_order = ["name", "environment"]
attributes = ["private"]
extra_tags = {
Application = "test"
}
}
18 changes: 0 additions & 18 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,19 @@
#Description : This terraform module is designed to generate consistent label names and tags
#for resources. You can use terraform-labels to implement a strict naming convention.
locals {
label_order_defaults = {
label_order = ["name", "environment"]
}

enabled = var.enabled == true ? true : false
id_context = {
name = var.name
environment = var.environment
}

label_order = length(var.label_order) > 0 ? var.label_order : local.label_order_defaults.label_order
# run loop for label order and set in value.
id_labels = [for l in var.label_order : local.id_context[l] if length(local.id_context[l]) > 0]

id = lower(join(var.delimiter, local.id_labels, var.attributes))
name = local.enabled == true ? lower(format("%v%s", "Name:-", var.name)) : ""
environment = local.enabled == true ? lower(format("%v%s", "Environment:-", var.environment)) : ""
managedby = local.enabled == true ? lower(format("%v%s", "Managedby:-", var.managedby)) : ""
attributes = local.enabled == true ? lower(format("%v", join(var.delimiter, compact(var.attributes)))) : ""
delimiter = local.enabled == true ? lower(format("%v%s", "delimiter:-", var.delimiter)) : ""

tags_context = {
# For digitalocean we need `Name` to be disambiguated sine it has a special meaning
name = local.id
environment = local.environment
managedby = local.managedby
}
generated_tags = { for l in keys(local.tags_context) : title(l) => local.tags_context[l] if length(local.tags_context[l]) > 0 }

tags = merge(local.generated_tags, var.extra_tags)

}

##-----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
# for resources. You can use terraform-labels to implement a strict naming
# convention.
output "id" {
value = join("", digitalocean_tag.id.*.id)
value = [for labels in digitalocean_tag.id : digitalocean_tag.id]
description = "Disambiguated ID."
}

output "name" {
value = join("", digitalocean_tag.name.*.name)
value = [for labels in digitalocean_tag.name : digitalocean_tag.name]
description = "Normalized name."
}

output "environment" {
value = join("", digitalocean_tag.environment.*.id)
value = [for labels in digitalocean_tag.environment : digitalocean_tag.environment]
description = "Normalized environment."
}

output "managedby" {
value = join("", digitalocean_tag.managedby.*.id)
value = [for labels in digitalocean_tag.managedby : digitalocean_tag.managedby]
description = "Normalized managedby."
}
12 changes: 0 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ variable "attributes" {
description = "Additional attributes (e.g. `1`)."
}

variable "tags" {
type = map(string)
default = {}
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)."
}

variable "managedby" {
type = string
default = "terraform-do-modules"
Expand All @@ -46,10 +40,4 @@ variable "delimiter" {
type = string
default = "-"
description = "Delimiter to be used between `organization`, `name`, `environment` and `attributes`."
}

variable "extra_tags" {
type = map(string)
default = {}
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)."
}

0 comments on commit 2c511fa

Please sign in to comment.