-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathndo_tenant_templates.tf
More file actions
219 lines (203 loc) · 11.2 KB
/
ndo_tenant_templates.tf
File metadata and controls
219 lines (203 loc) · 11.2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
locals {
tenant_templates_tenants = [
for template in local.tenant_templates : template.tenant
]
template_ids = { for template in try(jsondecode(data.mso_rest.templates.content), []) : template.templateName => { "id" : template.templateId } if template.templateType == "tenantPolicy" }
}
data "mso_rest" "templates" {
path = "api/v1/templates/summaries"
}
data "mso_tenant" "tenant_templates_tenant" {
for_each = toset([for tenant in distinct(local.tenant_templates_tenants) : tenant if !contains(local.managed_tenants, tenant) && var.manage_tenant_templates])
name = each.value
}
locals {
tenant_templates_sites = flatten(distinct([
for template in local.tenant_templates : [
for site in try(template.sites, []) : {
key = "${template.name}/${site}"
template_name = template.name
site_name = site
}
]
]))
}
data "mso_site" "tenant_templates_site" {
for_each = toset(distinct([for site in local.tenant_templates_sites : site.site_name if(!var.manage_sites || local.ndo_platform_version == "4.1") && var.manage_tenant_templates]))
name = each.value
}
locals {
tenant_policies = flatten([
for template in local.tenant_templates : [{
name = template.name
tenant = contains(local.managed_tenants, template.tenant) ? mso_tenant.tenant[template.tenant].id : data.mso_tenant.tenant_templates_tenant[template.tenant].id
sites = [for site in try(template.sites, []) : var.manage_sites && local.ndo_platform_version != "4.1" ? mso_site.site[site].id : data.mso_site.tenant_templates_site[site].id] }]
])
}
resource "mso_template" "tenant_template" {
for_each = { for template in local.tenant_policies : template.name => template }
template_name = each.value.name
template_type = "tenant"
tenant_id = each.value.tenant
sites = each.value.sites
}
locals {
dhcp_provider_epgs = flatten([
for template in local.tenant_templates : [
for policy in try(template.dhcp_relay_policies, []) : [
for provider in try(policy.providers, []) : {
key = "${provider.schema}/${provider.template}/${provider.application_profile}/${provider.endpoint_group}"
schema = provider.schema
template = provider.template
application_profile = try(provider.application_profile, null)
endpoint_group = try(provider.endpoint_group, null)
} if provider.type == "epg"
]
]
])
dhcp_provider_external_epgs = flatten([
for template in local.tenant_templates : [
for policy in try(template.dhcp_relay_policies, []) : [
for provider in try(policy.providers, []) : {
key = "${provider.schema}/${provider.template}/${provider.external_endpoint_group}"
schema = provider.schema
template = provider.template
external_endpoint_group = try(provider.external_endpoint_group, null)
} if provider.type == "external_epg"
]
]
])
}
data "mso_schema_template_anp_epg" "schema_template_anp_epg" {
for_each = { for provider in distinct(local.dhcp_provider_epgs) : provider.key => provider if(!var.manage_schemas || (var.manage_schemas && !contains(local.managed_schemas, provider.schema))) }
schema_id = local.schema_ids[each.value.schema].id
template_name = each.value.template
anp_name = each.value.application_profile
name = each.value.endpoint_group
}
data "mso_schema_template_external_epg" "schema_template_external_epg" {
for_each = { for provider in distinct(local.dhcp_provider_external_epgs) : provider.key => provider if(!var.manage_schemas || (var.manage_schemas && !contains(local.managed_schemas, provider.schema))) }
schema_id = local.schema_ids[each.value.schema].id
template_name = each.value.template
external_epg_name = each.value.external_endpoint_group
}
locals {
dhcp_relay_policies = flatten([
for template in local.tenant_templates : [
for policy in try(template.dhcp_relay_policies, []) : {
name = policy.name
template_name = template.name
description = try(policy.description, null)
providers = [for provider in try(policy.providers, []) : {
key = "${template.name}/${policy.name}/${provider.name}/${provider.type}"
name = provider.name
type = provider.type
ip = provider.ip
schema = provider.schema
use_server_vrf = try(provider.use_server_vrf, local.defaults.ndo.tenant_templates.tenant_policies.dhcp_relay_policies.providers.use_server_vrf)
epg_path = provider.type == "epg" ? "${provider.schema}/${provider.template}/${try(provider.application_profile, "")}/${try(provider.endpoint_group, "")}" : null
ext_epg_path = provider.type == "external_epg" ? "${provider.schema}/${provider.template}/${try(provider.external_endpoint_group, "")}" : null
}]
}
]
])
}
resource "mso_tenant_policies_dhcp_relay_policy" "tenant_policies_dhcp_relay_policy" {
for_each = { for policy in local.dhcp_relay_policies : policy.name => policy }
name = each.value.name
template_id = mso_template.tenant_template[each.value.template_name].id
description = each.value.description
dynamic "dhcp_relay_providers" {
for_each = { for provider in try(each.value.providers, []) : provider.name => provider if provider.type == "epg" }
content {
dhcp_server_address = dhcp_relay_providers.value.ip
application_epg_uuid = !var.manage_schemas || (var.manage_schemas && !contains(local.managed_schemas, dhcp_relay_providers.value.schema)) ? data.mso_schema_template_anp_epg.schema_template_anp_epg[dhcp_relay_providers.value.epg_path].uuid : mso_schema_template_anp_epg.schema_template_anp_epg[dhcp_relay_providers.value.epg_path].uuid
dhcp_server_vrf_preference = dhcp_relay_providers.value.use_server_vrf
}
}
dynamic "dhcp_relay_providers" {
for_each = { for provider in try(each.value.providers, []) : provider.name => provider if provider.type == "external_epg" }
content {
dhcp_server_address = dhcp_relay_providers.value.ip
external_epg_uuid = !var.manage_schemas || (var.manage_schemas && !contains(local.managed_schemas, dhcp_relay_providers.value.schema)) ? data.mso_schema_template_external_epg.schema_template_external_epg[dhcp_relay_providers.value.ext_epg_path].uuid : mso_schema_template_external_epg.schema_template_external_epg[dhcp_relay_providers.value.ext_epg_path].uuid
dhcp_server_vrf_preference = dhcp_relay_providers.value.use_server_vrf
}
}
depends_on = [
mso_schema_template_anp_epg.schema_template_anp_epg,
mso_schema_template_external_epg.schema_template_external_epg
]
}
locals {
ipsla_policies = flatten([
for template in local.tenant_templates : [
for policy in try(template.ip_sla_policies, []) : {
name = policy.name
template_name = template.name
description = try(policy.description, null)
sla_type = try(policy.sla_type, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.sla_type)
destination_port = try(policy.sla_type, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.sla_type) == "http" ? 80 : try(policy.sla_type, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.sla_type) == "tcp" ? try(policy.port, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.port) : null
http_version = try(policy.http_version, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.http_version)
http_uri = try(policy.http_uri, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.http_uri)
sla_frequency = try(policy.frequency, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.frequency)
detect_multiplier = try(policy.multiplier, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.multiplier)
request_data_size = try(policy.request_data_size, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.request_data_size)
type_of_service = try(policy.type_of_service, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.type_of_service)
operation_timeout = try(policy.timeout, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.timeout)
threshold = try(policy.threshold, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.threshold)
ipv6_traffic_class = try(policy.ipv6_traffic_class, local.defaults.ndo.tenant_templates.tenant_policies.ip_sla_policies.ipv6_traffic_class)
}
]
])
}
resource "mso_tenant_policies_ipsla_monitoring_policy" "tenant_policies_ipsla_monitoring_policy" {
for_each = { for policy in local.ipsla_policies : policy.name => policy }
template_id = mso_template.tenant_template[each.value.template_name].id
name = each.value.name
description = each.value.description
sla_type = each.value.sla_type
destination_port = each.value.destination_port
http_version = each.value.http_version
http_uri = each.value.http_uri
sla_frequency = each.value.sla_frequency
detect_multiplier = each.value.detect_multiplier
request_data_size = each.value.request_data_size
type_of_service = each.value.type_of_service
operation_timeout = each.value.operation_timeout
threshold = each.value.threshold
ipv6_traffic_class = each.value.ipv6_traffic_class
}
locals {
multicast_route_maps = flatten([
for template in local.tenant_templates : [
for policy in try(template.multicast_route_maps, []) : {
name = policy.name
template_name = template.name
description = try(policy.description, null)
entries = [for entry in try(policy.entries, []) : {
order = entry.order
group_ip = entry.group_ip
source_ip = entry.source_ip
rendezvous_point_ip = try(entry.rp_ip, local.defaults.ndo.tenant_templates.tenant_policies.multicast_route_maps.entries.rp_ip)
action = try(entry.action, local.defaults.ndo.tenant_templates.tenant_policies.multicast_route_maps.entries.action)
}]
}
]
])
}
resource "mso_tenant_policies_route_map_policy_multicast" "tenant_policies_route_map_policy_multicast" {
for_each = { for policy in local.multicast_route_maps : policy.name => policy }
template_id = mso_template.tenant_template[each.value.template_name].id
name = each.value.name
description = each.value.description
dynamic "route_map_multicast_entries" {
for_each = { for entry in try(each.value.entries, []) : entry.order => entry }
content {
order = route_map_multicast_entries.value.order
group_ip = route_map_multicast_entries.value.group_ip
source_ip = route_map_multicast_entries.value.source_ip
rendezvous_point_ip = route_map_multicast_entries.value.rendezvous_point_ip
action = route_map_multicast_entries.value.action
}
}
}