From 3292b07f718dc9c28dd85b0f341d560bbaf06035 Mon Sep 17 00:00:00 2001
From: michalbil <92343355+michalbil@users.noreply.github.com>
Date: Thu, 21 Dec 2023 18:18:40 +0100
Subject: [PATCH] feat(modules/tags): Remove tag_color_map var in favor of
static internal local value (#61)
---
modules/tags/README.md | 3 +--
modules/tags/main.tf | 47 ++++++++++++++++++++++++++++++++++--
modules/tags/variables.tf | 50 +--------------------------------------
3 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/modules/tags/README.md b/modules/tags/README.md
index 64c5776..a9a4973 100644
--- a/modules/tags/README.md
+++ b/modules/tags/README.md
@@ -101,8 +101,7 @@ No modules.
| [mode](#input\_mode) | The mode to use for the modules. Valid values are `panorama` and `ngfw`. | `string` | n/a | yes |
| [device\_group](#input\_device\_group) | Used if _mode_ is panorama, this defines the Device Group for the deployment | `string` | `"shared"` | no |
| [vsys](#input\_vsys) | Used if _mode_ is ngfw, this defines the vsys for the deployment | `string` | `"vsys1"` | no |
-| [tags](#input\_tags) | Map of the tag objects, where key is the tag object's name:
- `color`: (optional) The tag's color. This should either be an empty string (no color) or a string such as `color1`.
- `comment`: (optional) The description of the administrative tag.
Example:
tags = {|
DNS-SRV = {
comment = "Tag for DNS servers"
}
dns-proxy = {
color = "Olive"
comment = "dns-proxy"
}
}
map(object({| `{}` | no | -| [tag\_color\_map](#input\_tag\_color\_map) | Map of tag-color match, [provider documentation](https://registry.terraform.io/providers/PaloAltoNetworks/panos/latest/docs/resources/administrative_tag) | `map(string)` |
color = optional(string)
comment = optional(string)
}))
{| no | +| [tags](#input\_tags) | Map of the tag objects, where key is the tag object's name:
"azure_blue": "color24",
"black": "color14",
"blue": "color3",
"blue_gray": "color12",
"blue_violet": "color30",
"brown": "color16",
"burnt_sienna": "color41",
"cerulean_blue": "color25",
"chestnut": "color42",
"cobalt_blue": "color28",
"copper": "color5",
"cyan": "color10",
"forest_green": "color22",
"gold": "color15",
"gray": "color8",
"green": "color2",
"lavender": "color33",
"light_gray": "color11",
"light_green": "color9",
"lime": "color13",
"magenta": "color38",
"mahogany": "color40",
"maroon": "color19",
"medium_blue": "color27",
"medium_rose": "color32",
"medium_violet": "color31",
"midnight_blue": "color26",
"olive": "color17",
"orange": "color6",
"orchid": "color34",
"peach": "color36",
"purple": "color7",
"red": "color1",
"red_orange": "color20",
"red_violet": "color39",
"salmon": "color37",
"thistle": "color35",
"turquoise_blue": "color23",
"violet_blue": "color29",
"yellow": "color4",
"yellow_orange": "color21"
}
tags = {|
DNS-SRV = {
comment = "Tag for DNS servers"
}
dns-proxy = {
color = "Olive"
comment = "dns-proxy"
}
}
map(object({| `{}` | no | ### Outputs diff --git a/modules/tags/main.tf b/modules/tags/main.tf index 3e93c7d..b2aa65b 100644 --- a/modules/tags/main.tf +++ b/modules/tags/main.tf @@ -4,13 +4,56 @@ locals { ngfw = 1 # cloud_manager = 2 # Not yet supported } + tag_color_map = { + red = "color1" + green = "color2" + blue = "color3" + yellow = "color4" + copper = "color5" + orange = "color6" + purple = "color7" + gray = "color8" + light_green = "color9" + cyan = "color10" + light_gray = "color11" + blue_gray = "color12" + lime = "color13" + black = "color14" + gold = "color15" + brown = "color16" + olive = "color17" + maroon = "color19" + red_orange = "color20" + yellow_orange = "color21" + forest_green = "color22" + turquoise_blue = "color23" + azure_blue = "color24" + cerulean_blue = "color25" + midnight_blue = "color26" + medium_blue = "color27" + cobalt_blue = "color28" + violet_blue = "color29" + blue_violet = "color30" + medium_violet = "color31" + medium_rose = "color32" + lavender = "color33" + orchid = "color34" + thistle = "color35" + peach = "color36" + salmon = "color37" + magenta = "color38" + red_violet = "color39" + mahogany = "color40" + burnt_sienna = "color41" + chestnut = "color42" + } } resource "panos_panorama_administrative_tag" "this" { for_each = local.mode_map[var.mode] == 0 ? var.tags : {} name = each.key - color = try(var.tag_color_map[lower(replace(each.value.color, " ", "_"))], null) + color = try(local.tag_color_map[lower(replace(each.value.color, " ", "_"))], null) comment = try(each.value.comment, null) device_group = var.device_group @@ -23,7 +66,7 @@ resource "panos_administrative_tag" "this" { for_each = local.mode_map[var.mode] == 1 ? var.tags : {} name = each.key - color = try(var.tag_color_map[lower(replace(each.value.color, " ", "_"))], null) + color = try(local.tag_color_map[lower(replace(each.value.color, " ", "_"))], null) comment = try(each.value.comment, null) vsys = var.vsys diff --git a/modules/tags/variables.tf b/modules/tags/variables.tf index b221b96..c7c2676 100644 --- a/modules/tags/variables.tf +++ b/modules/tags/variables.tf @@ -22,7 +22,7 @@ variable "vsys" { variable "tags" { description = <<-EOF Map of the tag objects, where key is the tag object's name: - - `color`: (optional) The tag's color. This should either be an empty string (no color) or a string such as `color1`. + - `color`: (optional) The tag's color. This should either be an empty string (no color) or a string such as `Red`, `Green` etc. (full list of supported colors is available in [provider documentation](https://registry.terraform.io/providers/PaloAltoNetworks/panos/latest/docs/resources/administrative_tag)). - `comment`: (optional) The description of the administrative tag. Example: @@ -44,51 +44,3 @@ variable "tags" { comment = optional(string) })) } - -variable "tag_color_map" { - description = "Map of tag-color match, [provider documentation](https://registry.terraform.io/providers/PaloAltoNetworks/panos/latest/docs/resources/administrative_tag)" - default = { - red = "color1" - green = "color2" - blue = "color3" - yellow = "color4" - copper = "color5" - orange = "color6" - purple = "color7" - gray = "color8" - light_green = "color9" - cyan = "color10" - light_gray = "color11" - blue_gray = "color12" - lime = "color13" - black = "color14" - gold = "color15" - brown = "color16" - olive = "color17" - maroon = "color19" - red_orange = "color20" - yellow_orange = "color21" - forest_green = "color22" - turquoise_blue = "color23" - azure_blue = "color24" - cerulean_blue = "color25" - midnight_blue = "color26" - medium_blue = "color27" - cobalt_blue = "color28" - violet_blue = "color29" - blue_violet = "color30" - medium_violet = "color31" - medium_rose = "color32" - lavender = "color33" - orchid = "color34" - thistle = "color35" - peach = "color36" - salmon = "color37" - magenta = "color38" - red_violet = "color39" - mahogany = "color40" - burnt_sienna = "color41" - chestnut = "color42" - } - type = map(string) -}
color = optional(string)
comment = optional(string)
}))