forked from netascode/terraform-mso-nac-ndo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndo_tenants.tf
48 lines (43 loc) · 1.86 KB
/
ndo_tenants.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
locals {
default_users = distinct(concat([{ name = "admin" }], try(local.defaults.ndo.tenants.users, [])))
tenant_users = flatten(distinct([
for tenant in local.tenants : [
for user in distinct(concat(try(tenant.users, []), local.default_users)) : user.name
]
]))
tenant_sites = flatten(distinct([
for tenant in local.tenants : [
for site in try(tenant.sites, []) : site.name
]
]))
}
data "mso_user" "tenant_user" {
for_each = toset(local.tenant_users)
username = each.value
}
data "mso_site" "tenant_site" {
for_each = !var.manage_sites ? toset(local.tenant_sites) : []
name = each.value
}
resource "mso_tenant" "tenant" {
for_each = { for tenant in local.tenants : tenant.name => tenant }
name = each.value.name
display_name = each.value.name
description = try(each.value.description, "")
orchestrator_only = try(each.value.orchestrator_only, local.defaults.ndo.tenants.orchestrator_only)
dynamic "user_associations" {
for_each = { for user in distinct(concat(try(each.value.users, []), local.default_users)) : user.name => user }
content {
user_id = data.mso_user.tenant_user[user_associations.value.name].id
}
}
dynamic "site_associations" {
for_each = { for site in try(each.value.sites, []) : site.name => site }
content {
site_id = var.manage_sites ? mso_site.site[site_associations.value.name].id : data.mso_site.tenant_site[site_associations.value.name].id
vendor = try(site_associations.value.azure_subscription_id, null) != null ? "azure" : null
azure_subscription_id = try(site_associations.value.azure_subscription_id, null) != null ? site_associations.value.azure_subscription_id : null
azure_access_type = try(site_associations.value.azure_subscription_id, null) != null ? "managed" : null
}
}
}