From e72085766c13b733df47dda19f436066ba263d38 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 23 Jul 2024 22:24:11 +0100 Subject: [PATCH] refactor: Update meraki_networks.tf to use local variable for switch access control lists --- meraki_networks.tf | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/meraki_networks.tf b/meraki_networks.tf index 5b2696d..46f6ee8 100644 --- a/meraki_networks.tf +++ b/meraki_networks.tf @@ -296,6 +296,37 @@ resource "meraki_networks_snmp" "snmp_settings" { # # rules_response = try(each.value.data.rules_response, null) # } +locals { + network_acls = flatten([ + for domain in try(local.meraki.domains, []) : [ + for org in try(domain.organizations, []) : [ + for network in try(org.networks, []) : { + network_id = meraki_networks.networks["${domain.name}/${org.name}/${network.name}"].id + switch_access_control_lists = { + rules = [for rule in try(network.switch_access_control_lists.rules, []) : { + comment = try(rule.comment, null) + policy = try(rule.policy, null) + ip_version = try(rule.ip_version, null) + protocol = try(rule.protocol, null) + src_cidr = try(rule.src_cidr, null) + src_port = try(rule.src_port, null) + dst_cidr = try(rule.dst_cidr, null) + dst_port = try(rule.dst_port, null) + vlan = try(rule.vlan, null) + }] + } + } + ] + ] + ]) +} + +resource "meraki_networks_switch_access_control_lists" "example" { + for_each = { for i, v in local.network_acls : i => v } + + network_id = each.value.network_id + rules = each.value.switch_access_control_lists.rules +} # locals { # networks_switch_access_policies = flatten([