Skip to content

Commit

Permalink
feat(modules/tags): Remove tag_color_map var in favor of static inter…
Browse files Browse the repository at this point in the history
…nal local value (#61)
  • Loading branch information
michalbil authored Dec 21, 2023
1 parent c5f7401 commit 3292b07
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 53 deletions.
3 changes: 1 addition & 2 deletions modules/tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ No modules.
| <a name="input_mode"></a> [mode](#input\_mode) | The mode to use for the modules. Valid values are `panorama` and `ngfw`. | `string` | n/a | yes |
| <a name="input_device_group"></a> [device\_group](#input\_device\_group) | Used if _mode_ is panorama, this defines the Device Group for the deployment | `string` | `"shared"` | no |
| <a name="input_vsys"></a> [vsys](#input\_vsys) | Used if _mode_ is ngfw, this defines the vsys for the deployment | `string` | `"vsys1"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of the tag objects, where key is the tag object's name:<br>- `color`: (optional) The tag's color. This should either be an empty string (no color) or a string such as `color1`.<br>- `comment`: (optional) The description of the administrative tag.<br><br>Example:<pre>tags = {<br> DNS-SRV = {<br> comment = "Tag for DNS servers"<br> }<br> dns-proxy = {<br> color = "Olive"<br> comment = "dns-proxy"<br> }<br>}</pre> | <pre>map(object({<br> color = optional(string)<br> comment = optional(string)<br> }))</pre> | `{}` | no |
| <a name="input_tag_color_map"></a> [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)` | <pre>{<br> "azure_blue": "color24",<br> "black": "color14",<br> "blue": "color3",<br> "blue_gray": "color12",<br> "blue_violet": "color30",<br> "brown": "color16",<br> "burnt_sienna": "color41",<br> "cerulean_blue": "color25",<br> "chestnut": "color42",<br> "cobalt_blue": "color28",<br> "copper": "color5",<br> "cyan": "color10",<br> "forest_green": "color22",<br> "gold": "color15",<br> "gray": "color8",<br> "green": "color2",<br> "lavender": "color33",<br> "light_gray": "color11",<br> "light_green": "color9",<br> "lime": "color13",<br> "magenta": "color38",<br> "mahogany": "color40",<br> "maroon": "color19",<br> "medium_blue": "color27",<br> "medium_rose": "color32",<br> "medium_violet": "color31",<br> "midnight_blue": "color26",<br> "olive": "color17",<br> "orange": "color6",<br> "orchid": "color34",<br> "peach": "color36",<br> "purple": "color7",<br> "red": "color1",<br> "red_orange": "color20",<br> "red_violet": "color39",<br> "salmon": "color37",<br> "thistle": "color35",<br> "turquoise_blue": "color23",<br> "violet_blue": "color29",<br> "yellow": "color4",<br> "yellow_orange": "color21"<br>}</pre> | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of the tag objects, where key is the tag object's name:<br>- `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)).<br>- `comment`: (optional) The description of the administrative tag.<br><br>Example:<pre>tags = {<br> DNS-SRV = {<br> comment = "Tag for DNS servers"<br> }<br> dns-proxy = {<br> color = "Olive"<br> comment = "dns-proxy"<br> }<br>}</pre> | <pre>map(object({<br> color = optional(string)<br> comment = optional(string)<br> }))</pre> | `{}` | no |

### Outputs

Expand Down
47 changes: 45 additions & 2 deletions modules/tags/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
50 changes: 1 addition & 49 deletions modules/tags/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}

0 comments on commit 3292b07

Please sign in to comment.