Terraform for Resource Group Management - Anyone Able to Share?
Hey folks,
Working to wrap my head around Terraform for Resource Group Management. My current struggle has to do with finding an optimal way to handle nested grouping, without needing to have a bunch of extra resource statements.
Currently, I have established a list of objects for each and every individual group that needs to be created. Something like the following:
types_list = [
{
name: "APC",
applies_to: "isAPC()"
},
{
name: "F5 Load Balancers - Nodes"
applies_to: "system.displayname =~ \"lb-\" && system.displayname !~ \"vip\" && system.devicetype == \"0\""
parent_group: "F5 Load Balancers"
},
{
name: "F5 Load Balancers - VIPs",
applies_to: "system.displayname =~ \"lb-.*vip\"",
parent_group: "F5"
custom_properties: [
{
name: "system.categories",
value: "F5Active"
}
]
}
This is paired with the following main.tf:
resource "logicmonitor_device_group" "types" {
for_each = { for type in var.types_list : type.name => type }
name = "${each.value.name}-tf"
parent_id = logicmonitor_device_group.devices_by_type.id
group_type = each.value.group_type
applies_to = each.value.applies_to
custom_properties = each.value.custom_properties
}
Note that we don't do anything with the parent_group attributes at the moment
Creating these as flat groups with a statically-defined Parent group ID isn't terribly difficult, and works perfectly well. However, if I wanted to create a nested group structure, I'm having trouble discerning if there's a way for me to implement this that doesn't require me establishing some kind of 'layer' schema (i.e. multiple resource statements). An example of this (wasn't necessarily working, but to help illustrate the format):
resource "logicmonitor_device_group" "types_layer2" {
for_each = { for type in var.types_list_layer2 : type.name => type }
name = "${each.value.name}-tf"
parent_id = logicmonitor_device_group.types_layer1[each.value.parent_group].id
group_type = each.value.group_type
applies_to = each.value.applies_to
custom_properties = each.value.custom_properties
}
What, if anything, have other folks tried to incorporate to assist with building nested groups?