Skip to content

Commit

Permalink
refactor: Update Meraki organization network configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-humphries committed Jun 11, 2024
1 parent b0a0905 commit 8e73689
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 43 deletions.
70 changes: 27 additions & 43 deletions meraki_organization.tf
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
data "meraki_organizations" "organizations" {
organization_id = "1575199"
}
output "test" {
value = data.meraki_organizations.organizations.items
}
# locals {
# organization_map = { for organization in data.meraki_organizations.organizations.items : organization.name => organization.id }
# networks = flatten([
# for org in try(local.meraki.domains.organizations, []) : [
# for network in try(org.networks, []) : {
# key = format("%s/%s", org.name, network.name)
# organization_id = local.organization_map[org.name]
# name = try(network.name, local.defaults.meraki.organizations.networks.name)
# notes = try(network.notes, local.defaults.meraki.organizations.networks.notes)
# product_types = try(network.product_types, local.defaults.meraki.organizations.networks.product_types)
# tags = try(network.tags, local.defaults.meraki.organizations.networks.tags)
# time_zone = try(network.timezone, local.defaults.meraki.organizations.networks.timezone)
# }
# ]
# ])
# }
# output "meraki_domains_organizations" {
# description = "Output the value of local.meraki.domains.organizations for debugging"
# value = local.meraki.domains.organizations
# }

# output "organization_map" {
# description = "Output the value of local.organization_map for debugging"
# value = local.organization_map
# }

# output "networks" {
# description = "Output the value of local.networks for debugging"
# value = local.networks
# }
# resource "meraki_networks" "networks" {
# for_each = { for network in local.networks : network.key => network }

# name = each.value.name
# notes = each.value.notes
# organization_id = each.value.organization_id
# product_types = each.value.product_types
# tags = each.value.tags
# time_zone = each.value.time_zone
# }
locals {
organization_map = { for organization in data.meraki_organizations.organizations.items : organization.name => organization.id }
networks = flatten([
for domain in try(local.meraki.domains, []) : [
for org in try(domain.organizations, []) : [
for network in try(org.networks, []) : {
key = format("%s/%s/%s", domain.name, org.name, network.name)
organization_id = local.organization_map[org.name]
name = try(network.name, local.defaults.meraki.organizations.networks.name)
notes = try(network.notes, local.defaults.meraki.organizations.networks.notes)
product_types = try(network.product_types, local.defaults.meraki.organizations.networks.product_types)
tags = try(network.tags, local.defaults.meraki.organizations.networks.tags)
time_zone = try(network.timezone, local.defaults.meraki.organizations.networks.timezone)
}
]
]
])
}
resource "meraki_networks" "networks" {
for_each = { for network in local.networks : network.key => network }
name = each.value.name
notes = each.value.notes
organization_id = each.value.organization_id
product_types = each.value.product_types
tags = each.value.tags
time_zone = each.value.time_zone
}

# locals {
# admins = flatten([
Expand Down
10 changes: 10 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ output "model" {
description = "Full model."
value = local.model
}
# Output the organization map
output "organization_map" {
value = local.organization_map
}
# output "domains" {
# value = local.meraki.domains
# }
output "test" {
value = local.model_strings
}

0 comments on commit 8e73689

Please sign in to comment.