forked from netascode/terraform-mso-nac-ndo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathndo_schemas.tf
1748 lines (1628 loc) · 89.6 KB
/
ndo_schemas.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
locals {
template_tenants = flatten(distinct([
for schema in local.schemas : [
for template in try(schema.templates, []) : template.tenant
]
]))
managed_schemas = [for schema in local.schemas : schema.name]
schema_ids = { for schema in try(jsondecode(data.mso_rest.schemas.content).schemas, []) : schema.displayName => { "id" : schema.id } }
}
data "mso_rest" "schemas" {
path = "api/v1/schemas/list-identity"
}
data "mso_tenant" "template_tenant" {
for_each = toset([for tenant in local.template_tenants : tenant if !var.manage_tenants && var.manage_schemas])
name = each.value
}
resource "mso_schema" "schema" {
for_each = { for schema in local.schemas : schema.name => schema }
name = each.value.name
dynamic "template" {
for_each = { for template in try(each.value.templates, []) : template.name => template }
content {
name = template.value.name
display_name = template.value.name
description = try(template.value.description, null)
tenant_id = var.manage_tenants ? mso_tenant.tenant[template.value.tenant].id : data.mso_tenant.template_tenant[template.value.tenant].id
template_type = try(template.value.type, local.defaults.ndo.schemas.templates.type) == "autonomous" ? "aci_autonomous" : "aci_multi_site"
}
}
}
locals {
template_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for site in try(template.sites, []) : {
key = "${schema.name}/${template.name}/${site}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
site_name = site
}
]
]
])
}
data "mso_site" "template_site" {
for_each = toset(distinct([for site in local.template_sites : site.site_name if !var.manage_sites && var.manage_schemas]))
name = each.value
}
resource "mso_schema_site" "schema_site" {
for_each = { for site in local.template_sites : site.key => site }
schema_id = each.value.schema_id
template_name = each.value.template_name
site_id = var.manage_sites ? mso_site.site[each.value.site_name].id : data.mso_site.template_site[each.value.site_name].id
undeploy_on_destroy = true
depends_on = [mso_schema.schema]
}
locals {
filter_entries = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for filter in try(template.filters, []) : [
for entry in try(filter.entries, []) : {
key = "${schema.name}/${template.name}/${filter.name}/${entry.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
name = "${filter.name}${local.defaults.ndo.schemas.templates.filters.name_suffix}"
display_name = "${filter.name}${local.defaults.ndo.schemas.templates.filters.name_suffix}"
entry_name = "${entry.name}${local.defaults.ndo.schemas.templates.filters.entries.name_suffix}"
entry_display_name = "${entry.name}${local.defaults.ndo.schemas.templates.filters.entries.name_suffix}"
entry_description = try(entry.description, "")
ether_type = try(entry.ethertype, local.defaults.ndo.schemas.templates.filters.entries.ethertype)
arp_flag = "unspecified"
ip_protocol = contains(["ip", "ipv4", "ipv6"], try(entry.ethertype, local.defaults.ndo.schemas.templates.filters.entries.ethertype)) ? try(entry.protocol, local.defaults.ndo.schemas.templates.filters.entries.protocol) : "unspecified"
match_only_fragments = false
stateful = try(entry.stateful, local.defaults.ndo.schemas.templates.filters.entries.stateful)
destination_from = try(entry.destination_from_port, local.defaults.ndo.schemas.templates.filters.entries.destination_from_port)
destination_to = try(entry.destination_to_port, entry.destination_from_port, local.defaults.ndo.schemas.templates.filters.entries.destination_from_port)
source_from = try(entry.source_from_port, local.defaults.ndo.schemas.templates.filters.entries.source_from_port)
source_to = try(entry.source_to_port, entry.source_from_port, local.defaults.ndo.schemas.templates.filters.entries.source_from_port)
tcp_session_rules = ["unspecified"]
}
]
]
]
])
}
resource "mso_schema_template_filter_entry" "schema_template_filter_entry" {
for_each = { for entry in local.filter_entries : entry.key => entry }
schema_id = each.value.schema_id
template_name = each.value.template_name
name = each.value.name
display_name = each.value.display_name
entry_name = each.value.entry_name
entry_display_name = each.value.entry_display_name
entry_description = each.value.entry_description
ether_type = each.value.ether_type
arp_flag = each.value.arp_flag
ip_protocol = each.value.ip_protocol
match_only_fragments = each.value.match_only_fragments
stateful = each.value.stateful
destination_from = each.value.destination_from
destination_to = each.value.destination_to
source_from = each.value.source_from
source_to = each.value.source_to
tcp_session_rules = each.value.tcp_session_rules
}
locals {
contracts = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for contract in try(template.contracts, []) : {
key = "${schema.name}/${template.name}/${contract.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
display_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
filter_type = try(contract.type, local.defaults.ndo.schemas.templates.contracts.type)
scope = try(contract.scope, local.defaults.ndo.schemas.templates.contracts.scope)
filter_relationship = flatten(concat(
[
for filter in try(contract.filters, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${filter.name}/both"
filter_type = "bothWay"
filter_schema_id = contains(local.managed_schemas, try(filter.schema, schema.name)) ? mso_schema.schema[try(filter.schema, schema.name)].id : local.schema_ids[filter.schema].id
filter_template_name = try(filter.template, template.name)
filter_name = "${filter.name}${local.defaults.ndo.schemas.templates.filters.name_suffix}"
directives = [try(filter.log, local.defaults.ndo.schemas.templates.contracts.filters.log) ? "log" : "none"]
}
],
[
for filter in try(contract.provider_to_consumer_filters, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${filter.name}/provider"
filter_type = "provider_to_consumer"
filter_schema_id = contains(local.managed_schemas, try(filter.schema, schema.name)) ? mso_schema.schema[try(filter.schema, schema.name)].id : local.schema_ids[filter.schema].id
filter_template_name = try(filter.template, template.name)
filter_name = "${filter.name}${local.defaults.ndo.schemas.templates.filters.name_suffix}"
directives = [try(filter.log, local.defaults.ndo.schemas.templates.contracts.filters.log) ? "log" : "none"]
}
],
[
for filter in try(contract.consumer_to_provider_filters, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${filter.name}/consumer"
filter_type = "consumer_to_provider"
filter_schema_id = contains(local.managed_schemas, try(filter.schema, schema.name)) ? mso_schema.schema[try(filter.schema, schema.name)].id : local.schema_ids[filter.schema].id
filter_template_name = try(filter.template, template.name)
filter_name = "${filter.name}${local.defaults.ndo.schemas.templates.filters.name_suffix}"
directives = [try(filter.log, local.defaults.ndo.schemas.templates.contracts.filters.log) ? "log" : "none"]
}
]
))
}
]
]
])
}
resource "mso_schema_template_contract" "schema_template_contract" {
for_each = { for contract in local.contracts : contract.key => contract }
schema_id = each.value.schema_id
template_name = each.value.template_name
contract_name = each.value.contract_name
display_name = each.value.display_name
filter_type = each.value.filter_type
scope = each.value.scope
dynamic "filter_relationship" {
for_each = { for filter in try(each.value.filter_relationship, []) : filter.key => filter }
content {
filter_schema_id = filter_relationship.value.filter_schema_id
filter_template_name = filter_relationship.value.filter_template_name
filter_name = filter_relationship.value.filter_name
filter_type = filter_relationship.value.filter_type
directives = filter_relationship.value.directives
}
}
depends_on = [mso_schema_template_filter_entry.schema_template_filter_entry]
}
locals {
contracts_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for contract in try(template.contracts, []) : [
for site in try(template.sites, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${site}"
schema_id = mso_schema.schema[schema.name].id
patch = [{
op = "add"
path = "/sites/${var.manage_sites ? mso_site.site[site].id : data.mso_site.template_site[site].id}-${template.name}/contracts/-"
value = {
contractRef = {
contractName = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
schemaId = mso_schema.schema[schema.name].id
templateName = template.name
}
}
}]
}
]
]
]
])
}
resource "mso_rest" "schema_site_contract" {
for_each = { for contract in local.contracts_sites : contract.key => contract if local.ndo_version == "3.7" }
path = "api/v1/schemas/${each.value.schema_id}?validate=false"
method = "PATCH"
payload = jsonencode(each.value.patch)
depends_on = [
mso_schema_site.schema_site,
mso_schema_template_contract.schema_template_contract,
]
}
locals {
contracts_service_graphs = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for contract in try(template.contracts, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${contract.service_graph.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
service_graph_name = "${contract.service_graph.name}${local.defaults.ndo.schemas.templates.service_graphs.name_suffix}"
service_graph_schema_id = contains(local.managed_schemas, try(contract.service_graph.schema, schema.name)) ? mso_schema.schema[try(contract.service_graph.schema, schema.name)].id : local.schema_ids[contract.service_graph.schema].id
service_graph_template_name = try(contract.service_graph.template, template.name)
node_relationship = flatten([
for node in try(contract.service_graph.nodes, []) : {
key = try(node.index, 1)
provider_connector_bd_name = "${node.provider.bridge_domain}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
provider_connector_bd_schema_id = contains(local.managed_schemas, try(node.provider.schema, schema.name)) ? mso_schema.schema[try(node.provider.schema, schema.name)].id : local.schema_ids[node.provider.schema].id
provider_connector_bd_template_name = try(node.provider.template, template.name)
consumer_connector_bd_name = "${node.consumer.bridge_domain}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
consumer_connector_bd_schema_id = contains(local.managed_schemas, try(node.consumer.schema, schema.name)) ? mso_schema.schema[try(node.consumer.schema, schema.name)].id : local.schema_ids[node.consumer.schema].id
consumer_connector_bd_template_name = try(node.consumer.template, template.name)
}
])
} if try(contract.service_graph.name, null) != null
]
]
])
}
resource "mso_schema_template_contract_service_graph" "schema_template_contract_service_graph" {
for_each = { for sg in local.contracts_service_graphs : sg.key => sg if local.ndo_version == "3.7" || local.ndo_version >= 4.2 }
schema_id = each.value.schema_id
template_name = each.value.template_name
contract_name = each.value.contract_name
service_graph_name = each.value.service_graph_name
service_graph_schema_id = each.value.service_graph_schema_id
service_graph_template_name = each.value.service_graph_template_name
dynamic "node_relationship" {
for_each = { for node_relationship in try(each.value.node_relationship, []) : node_relationship.key => node_relationship }
content {
provider_connector_bd_name = node_relationship.value.provider_connector_bd_name
provider_connector_bd_schema_id = node_relationship.value.provider_connector_bd_schema_id
provider_connector_bd_template_name = node_relationship.value.provider_connector_bd_template_name
consumer_connector_bd_name = node_relationship.value.consumer_connector_bd_name
consumer_connector_bd_schema_id = node_relationship.value.consumer_connector_bd_schema_id
consumer_connector_bd_template_name = node_relationship.value.consumer_connector_bd_template_name
}
}
depends_on = [
mso_schema_template_contract.schema_template_contract,
mso_schema_site_contract_service_graph.schema_site_contract_service_graph,
mso_schema_template_anp_epg_contract.schema_template_anp_epg_contract,
mso_schema_template_external_epg_contract.schema_template_external_epg_contract,
mso_schema_template_vrf_contract.schema_template_vrf_contract,
]
}
locals {
contracts_service_graphs_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for contract in try(template.contracts, []) : [
for site_name in try(template.sites, []) : {
key = "${schema.name}/${template.name}/${contract.name}/${contract.service_graph.name}/${site_name}"
schema_id = mso_schema.schema[schema.name].id
site_id = var.manage_sites ? mso_site.site[site_name].id : data.mso_site.template_site[site_name].id
template_name = template.name
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
service_graph_name = "${contract.service_graph.name}${local.defaults.ndo.schemas.templates.service_graphs.name_suffix}"
service_graph_schema_id = contains(local.managed_schemas, try(contract.service_graph.schema, schema.name)) ? mso_schema.schema[try(contract.service_graph.schema, schema.name)].id : local.schema_ids[contract.service_graph.schema].id
service_graph_template_name = try(contract.service_graph.template, template.name)
node_relationship = flatten([
for node in try(contract.service_graph.nodes, []) : {
key = try(node.index, 1)
provider = flatten([
for site in try(node.provider.sites, []) : {
connector_cluster_interface = "${site.logical_interface}${local.defaults.ndo.schemas.templates.service_graphs.logical_interface_name_suffix}"
connector_redirect_policy_tenant = try(site.tenant, template.tenant)
connector_redirect_policy = try("${site.redirect_policy}${local.defaults.ndo.schemas.templates.service_graphs.redirect_policy_name_suffix}", null)
} if site.name == site_name
])
consumer = flatten([
for site in try(node.consumer.sites, []) : {
connector_cluster_interface = "${site.logical_interface}${local.defaults.ndo.schemas.templates.service_graphs.logical_interface_name_suffix}"
connector_redirect_policy_tenant = try(site.tenant, template.tenant)
connector_redirect_policy = try("${site.redirect_policy}${local.defaults.ndo.schemas.templates.service_graphs.redirect_policy_name_suffix}", null)
} if site.name == site_name
])
}
])
}
] if try(contract.service_graph.name, null) != null
]
]
])
}
resource "mso_schema_site_contract_service_graph" "schema_site_contract_service_graph" {
for_each = { for sg in local.contracts_service_graphs_sites : sg.key => sg if local.ndo_version == "3.7" || local.ndo_version >= 4.2 }
schema_id = each.value.schema_id
template_name = each.value.template_name
contract_name = each.value.contract_name
site_id = each.value.site_id
service_graph_name = each.value.service_graph_name
service_graph_schema_id = each.value.service_graph_schema_id
service_graph_template_name = each.value.service_graph_template_name
dynamic "node_relationship" {
for_each = { for node_relationship in try(each.value.node_relationship, []) : node_relationship.key => node_relationship }
content {
provider_connector_cluster_interface = node_relationship.value.provider[0].connector_cluster_interface
provider_connector_redirect_policy_tenant = node_relationship.value.provider[0].connector_redirect_policy != null ? node_relationship.value.provider[0].connector_redirect_policy_tenant : null
provider_connector_redirect_policy = node_relationship.value.provider[0].connector_redirect_policy
consumer_connector_cluster_interface = node_relationship.value.consumer[0].connector_cluster_interface
consumer_connector_redirect_policy_tenant = node_relationship.value.consumer[0].connector_redirect_policy != null ? node_relationship.value.consumer[0].connector_redirect_policy_tenant : null
consumer_connector_redirect_policy = node_relationship.value.consumer[0].connector_redirect_policy
}
}
depends_on = [
mso_schema_site.schema_site,
mso_rest.schema_site_contract,
mso_schema_template_service_graph.schema_template_service_graph,
mso_schema_site_service_graph.schema_site_service_graph,
mso_rest.schema_site_service_graph,
]
}
locals {
vrfs = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for vrf in try(template.vrfs, []) : {
key = "${schema.name}/${template.name}/${vrf.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
display_name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
layer3_multicast = try(vrf.l3_multicast, local.defaults.ndo.schemas.templates.vrfs.l3_multicast)
vzany = try(vrf.vzany, local.defaults.ndo.schemas.templates.vrfs.vzany)
ip_data_plane_learning = try(vrf.data_plane_learning, local.defaults.ndo.schemas.templates.vrfs.data_plane_learning) ? "enabled" : "disabled"
preferred_group = try(vrf.preferred_group, local.defaults.ndo.schemas.templates.vrfs.preferred_group)
site_aware_policy_enforcement = try(vrf.site_aware_policy_enforcement, null)
}
]
]
])
}
resource "mso_schema_template_vrf" "schema_template_vrf" {
for_each = { for vrf in local.vrfs : vrf.key => vrf }
schema_id = each.value.schema_id
template = each.value.template_name
name = each.value.name
display_name = each.value.display_name
layer3_multicast = each.value.layer3_multicast
vzany = each.value.vzany
ip_data_plane_learning = each.value.ip_data_plane_learning
preferred_group = each.value.preferred_group
site_aware_policy_enforcement = each.value.site_aware_policy_enforcement
}
locals {
vrfs_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for vrf in try(template.vrfs, []) : [
for site in try(vrf.sites, []) : {
key = "${schema.name}/${template.name}/${vrf.name}/${site.name}"
schema_id = mso_schema.schema[schema.name].id
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
template_name = template.name
vrf_name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
}
]
]
]
])
}
resource "mso_schema_site_vrf" "schema_site_vrf" {
for_each = { for site in local.vrfs_sites : site.key => site }
schema_id = each.value.schema_id
site_id = each.value.site_id
template_name = each.value.template_name
vrf_name = each.value.vrf_name
depends_on = [
mso_schema_site.schema_site,
mso_schema_template_vrf.schema_template_vrf,
]
}
locals {
vrfs_contracts = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for vrf in try(template.vrfs, []) : concat([
for contract in try(vrf.contracts.consumers, []) : {
key = "${schema.name}/${template.name}/${vrf.name}/${contract.name}/consumer"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
vrf_name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
contract_schema_id = contains(local.managed_schemas, try(contract.schema, schema.name)) ? mso_schema.schema[try(contract.schema, schema.name)].id : local.schema_ids[contract.schema].id
contract_template_name = try(contract.template, template.name)
relationship_type = "consumer"
}
],
[
for contract in try(vrf.contracts.providers, []) : {
key = "${schema.name}/${template.name}/${vrf.name}/${contract.name}/provider"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
vrf_name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
contract_schema_id = contains(local.managed_schemas, try(contract.schema, schema.name)) ? mso_schema.schema[try(contract.schema, schema.name)].id : local.schema_ids[contract.schema].id
contract_template_name = try(contract.template, template.name)
relationship_type = "provider"
}
])
]
]
])
}
resource "mso_schema_template_vrf_contract" "schema_template_vrf_contract" {
for_each = { for contract in local.vrfs_contracts : contract.key => contract }
schema_id = each.value.schema_id
template_name = each.value.template_name
vrf_name = each.value.vrf_name
contract_name = each.value.contract_name
contract_schema_id = each.value.contract_schema_id
contract_template_name = each.value.contract_template_name
relationship_type = each.value.relationship_type
depends_on = [
mso_schema_template_vrf.schema_template_vrf,
mso_schema_template_contract.schema_template_contract,
]
}
locals {
vrfs_sites_regions = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for vrf in try(template.vrfs, []) : [
for site in try(vrf.sites, []) : [
for region in try(site.regions, []) : {
key = "${schema.name}/${template.name}/${vrf.name}/${site.name}/${region.name}"
schema_id = mso_schema.schema[schema.name].id
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
template_name = template.name
vrf_name = "${vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
region_name = region.name
vpn_gateway = try(region.vpn_gateway, local.defaults.ndo.schemas.templates.vrfs.sites.regions.vpn_gateway)
hub_network_enable = try(region.hub_network, local.defaults.ndo.schemas.templates.vrfs.sites.regions.hub_network)
hub_network = try(region.hub_network, local.defaults.ndo.schemas.templates.vrfs.sites.regions.hub_network) ? {
name = region.hub_network_name
tenant_name = region.hub_network_tenant
} : null
cidr = [for cidr in try(region.cidrs, []) : {
cidr_ip = cidr.ip
primary = true
subnet = [for subnet in try(cidr.subnets, []) : {
ip = subnet.ip
zone = try(subnet.zone, null)
name = try(subnet.name, "")
}]
}]
}
]
]
]
]
])
}
resource "mso_schema_site_vrf_region" "schema_site_vrf_region" {
for_each = { for region in local.vrfs_sites_regions : region.key => region }
schema_id = each.value.schema_id
site_id = each.value.site_id
template_name = each.value.template_name
vrf_name = each.value.vrf_name
region_name = each.value.region_name
vpn_gateway = each.value.vpn_gateway
hub_network_enable = each.value.hub_network_enable
hub_network = each.value.hub_network
dynamic "cidr" {
for_each = { for cidr in try(each.value.cidr, []) : cidr.cidr_ip => cidr }
content {
cidr_ip = cidr.value.cidr_ip
primary = cidr.value.primary
dynamic "subnet" {
for_each = { for subnet in try(each.value.subnet, []) : subnet.ip => subnet }
content {
ip = subnet.value.ip
zone = subnet.value.zone
name = subnet.value.name
}
}
}
}
depends_on = [mso_schema_site_vrf.schema_site_vrf]
}
locals {
multi_destination_flooding_map = {
"bd-flood" : "flood_in_bd"
"encap-flood" : "flood_in_encap"
"drop" : "drop"
}
unknown_multicast_map = {
"flood" : "flood"
"opt-flood" : "optimized_flooding"
}
bridge_domains = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for bd in try(template.bridge_domains, []) : {
key = "${schema.name}/${template.name}/${bd.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
display_name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
description = try(bd.description, null)
vrf_name = "${bd.vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}"
vrf_schema_id = contains(local.managed_schemas, try(bd.vrf.schema, schema.name)) ? mso_schema.schema[try(bd.vrf.schema, schema.name)].id : local.schema_ids[bd.vrf.schema].id
vrf_template_name = try(bd.vrf.template, template.name)
layer2_unknown_unicast = try(bd.l2_unknown_unicast, local.defaults.ndo.schemas.templates.bridge_domains.l2_unknown_unicast, "proxy")
intersite_bum_traffic = try(bd.intersite_bum_traffic, local.defaults.ndo.schemas.templates.bridge_domains.intersite_bum_traffic)
optimize_wan_bandwidth = try(bd.optimize_wan_bandwidth, local.defaults.ndo.schemas.templates.bridge_domains.optimize_wan_bandwidth)
layer2_stretch = try(bd.l2_stretch, local.defaults.ndo.schemas.templates.bridge_domains.l2_stretch)
layer3_multicast = try(bd.l3_multicast, local.defaults.ndo.schemas.templates.bridge_domains.l3_multicast)
arp_flooding = try(bd.arp_flooding, local.defaults.ndo.schemas.templates.bridge_domains.arp_flooding)
virtual_mac_address = try(bd.virtual_mac, null)
unicast_routing = try(bd.unicast_routing, local.defaults.ndo.schemas.templates.bridge_domains.unicast_routing)
multi_destination_flooding = local.multi_destination_flooding_map[try(bd.multi_destination_flooding, local.defaults.ndo.schemas.templates.bridge_domains.multi_destination_flooding)]
unknown_multicast_flooding = local.unknown_multicast_map[try(bd.unknown_ipv4_multicast, local.defaults.ndo.schemas.templates.bridge_domains.unknown_ipv4_multicast)]
ipv6_unknown_multicast_flooding = local.unknown_multicast_map[try(bd.unknown_ipv6_multicast, local.defaults.ndo.schemas.templates.bridge_domains.unknown_ipv6_multicast)]
}
]
]
])
}
resource "mso_schema_template_bd" "schema_template_bd" {
for_each = { for bd in local.bridge_domains : bd.key => bd }
schema_id = each.value.schema_id
template_name = each.value.template_name
name = each.value.name
display_name = each.value.display_name
description = each.value.description
vrf_name = each.value.vrf_name
vrf_schema_id = each.value.vrf_schema_id
vrf_template_name = each.value.vrf_template_name
layer2_unknown_unicast = each.value.layer2_unknown_unicast
intersite_bum_traffic = each.value.intersite_bum_traffic
optimize_wan_bandwidth = each.value.optimize_wan_bandwidth
layer2_stretch = each.value.layer2_stretch
layer3_multicast = each.value.layer3_multicast
arp_flooding = each.value.arp_flooding
virtual_mac_address = each.value.virtual_mac_address
unicast_routing = each.value.unicast_routing
ipv6_unknown_multicast_flooding = each.value.ipv6_unknown_multicast_flooding
multi_destination_flooding = each.value.multi_destination_flooding
unknown_multicast_flooding = each.value.unknown_multicast_flooding
depends_on = [mso_schema_template_vrf.schema_template_vrf]
}
locals {
bridge_domains_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for bd in try(template.bridge_domains, []) : [
for site in try(bd.sites, []) : {
key = "${schema.name}/${template.name}/${bd.name}/${site.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
bd_name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
host_route = try(site.advertise_host_routes, local.defaults.ndo.schemas.templates.bridge_domains.sites.advertise_host_routes)
mac = try(site.mac, local.defaults.ndo.schemas.templates.bridge_domains.sites.mac, "00:22:BD:F8:19:FF")
}
]
]
]
])
}
resource "mso_schema_site_bd" "schema_site_bd" {
for_each = { for bd in local.bridge_domains_sites : bd.key => bd }
schema_id = each.value.schema_id
template_name = each.value.template_name
bd_name = each.value.bd_name
site_id = each.value.site_id
host_route = each.value.host_route
svi_mac = each.value.mac
depends_on = [
mso_schema_site.schema_site,
mso_schema_template_bd.schema_template_bd,
]
}
locals {
bridge_domains_subnets = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for bd in try(template.bridge_domains, []) : [
for subnet in try(bd.subnets, []) : {
key = "${schema.name}/${template.name}/${bd.name}/${subnet.ip}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
bd_name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
ip = subnet.ip
scope = try(subnet.scope, local.defaults.ndo.schemas.templates.bridge_domains.subnets.scope)
shared = try(subnet.shared, local.defaults.ndo.schemas.templates.bridge_domains.subnets.shared)
no_default_gateway = try(subnet.no_default_gateway, local.defaults.ndo.schemas.templates.bridge_domains.subnets.no_default_gateway)
querier = try(subnet.querier, local.defaults.ndo.schemas.templates.bridge_domains.subnets.querier)
primary = try(subnet.primary, local.defaults.ndo.schemas.templates.bridge_domains.subnets.primary)
}
]
]
]
])
}
resource "mso_schema_template_bd_subnet" "schema_template_bd_subnet" {
for_each = { for subnet in local.bridge_domains_subnets : subnet.key => subnet }
schema_id = each.value.schema_id
template_name = each.value.template_name
bd_name = each.value.bd_name
ip = each.value.ip
scope = each.value.scope
shared = each.value.shared
no_default_gateway = each.value.no_default_gateway
querier = each.value.querier
primary = each.value.primary
depends_on = [mso_schema_template_bd.schema_template_bd]
}
locals {
bridge_domains_sites_subnets = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for bd in try(template.bridge_domains, []) : [
for site in try(bd.sites, []) : [
for subnet in try(site.subnets, []) : {
key = "${schema.name}/${template.name}/${bd.name}/${site.name}/${subnet.ip}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
bd_name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
ip = subnet.ip
scope = try(subnet.scope, local.defaults.ndo.schemas.templates.bridge_domains.sites.subnets.scope)
shared = try(subnet.shared, local.defaults.ndo.schemas.templates.bridge_domains.sites.subnets.shared)
no_default_gateway = try(subnet.no_default_gateway, local.defaults.ndo.schemas.templates.bridge_domains.sites.subnets.no_default_gateway)
querier = try(subnet.querier, local.defaults.ndo.schemas.templates.bridge_domains.sites.subnets.querier)
primary = try(subnet.primary, local.defaults.ndo.schemas.templates.bridge_domains.sites.subnets.primary)
}
]
]
]
]
])
}
resource "mso_schema_site_bd_subnet" "schema_site_bd_subnet" {
for_each = { for subnet in local.bridge_domains_sites_subnets : subnet.key => subnet }
schema_id = each.value.schema_id
template_name = each.value.template_name
site_id = each.value.site_id
bd_name = each.value.bd_name
ip = each.value.ip
scope = each.value.scope
shared = each.value.shared
no_default_gateway = each.value.no_default_gateway
querier = each.value.querier
primary = each.value.primary
depends_on = [mso_schema_site_bd.schema_site_bd]
}
locals {
bridge_domains_sites_l3outs = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for bd in try(template.bridge_domains, []) : [
for site in try(bd.sites, []) : [
for l3out in try(site.l3outs, []) : {
key = "${schema.name}/${template.name}/${bd.name}/${site.name}/${l3out}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
bd_name = "${bd.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}"
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
l3out_name = "${l3out}${local.defaults.ndo.schemas.templates.l3outs.name_suffix}"
}
]
]
]
]
])
}
resource "mso_schema_site_bd_l3out" "schema_site_bd_l3out" {
for_each = { for l3out in local.bridge_domains_sites_l3outs : l3out.key => l3out }
schema_id = each.value.schema_id
template_name = each.value.template_name
site_id = each.value.site_id
bd_name = each.value.bd_name
l3out_name = each.value.l3out_name
depends_on = [mso_schema_site_bd.schema_site_bd]
}
locals {
application_profiles = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : {
key = "${schema.name}/${template.name}/${ap.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
display_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
}
]
]
])
}
resource "mso_schema_template_anp" "schema_template_anp" {
for_each = { for ap in local.application_profiles : ap.key => ap }
schema_id = each.value.schema_id
template = each.value.template_name
name = each.value.name
display_name = each.value.display_name
}
locals {
application_profiles_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : [
for site in distinct(flatten([for epg in try(ap.endpoint_groups, []) : [for site in try(epg.sites, []) : site.name]])) : {
key = "${schema.name}/${template.name}/${ap.name}/${site}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
site_id = var.manage_sites ? mso_site.site[site].id : data.mso_site.template_site[site].id
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
}
]
]
]
])
}
resource "mso_schema_site_anp" "schema_site_anp" {
for_each = { for ap in local.application_profiles_sites : ap.key => ap }
schema_id = each.value.schema_id
template_name = each.value.template_name
site_id = each.value.site_id
anp_name = each.value.anp_name
depends_on = [
mso_schema_site.schema_site,
mso_schema_template_anp.schema_template_anp,
]
}
locals {
endpoint_groups = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : [
for epg in try(ap.endpoint_groups, []) : {
key = "${schema.name}/${template.name}/${ap.name}/${epg.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
name = "${epg.name}${local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.name_suffix}"
description = try(epg.description, null)
bd_name = try(epg.bridge_domain.name, null) != null ? "${epg.bridge_domain.name}${local.defaults.ndo.schemas.templates.bridge_domains.name_suffix}" : null
bd_schema_id = contains(local.managed_schemas, try(epg.bridge_domain.schema, schema.name)) ? mso_schema.schema[try(epg.bridge_domain.schema, schema.name)].id : local.schema_ids[epg.bridge_domain.schema].id
bd_template_name = try(epg.bridge_domain.template, template.name)
vrf_name = try(epg.vrf.name, null) != null ? "${epg.vrf.name}${local.defaults.ndo.schemas.templates.vrfs.name_suffix}" : null
vrf_schema_id = try(epg.vrf.name, null) != null ? (contains(local.managed_schemas, try(epg.vrf.schema, schema.name)) ? mso_schema.schema[try(epg.vrf.schema, schema.name)].id : local.schema_ids[epg.vrf.schema].id) : null
vrf_template_name = try(epg.vrf.name, null) != null ? try(epg.vrf.template, template.name) : null
useg_epg = try(epg.useg, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.useg)
intra_epg = try(epg.intra_epg_isolation, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.intra_epg_isolation) ? "enforced" : "unenforced"
intersite_multicast_source = try(epg.intersite_multicast_source, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.intersite_multicast_source, false) # Not yet implemented in schema
proxy_arp = try(epg.proxy_arp, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.proxy_arp)
preferred_group = try(epg.preferred_group, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.preferred_group)
epg_type = try(epg.epg_type, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.epg_type, "application") # Not yet implemented in schema
access_type = try(epg.access_type, null) # Not yet implemented in schema
deployment_type = try(epg.deployment_type, null) # Not yet implemented in schema
service_type = try(epg.service_type, null) # Not yet implemented in schema
custom_service_type = try(epg.service_type, null) == "custom" ? epg.custom_service_type : null # Not yet implemented in schema
}
]
]
]
])
}
resource "mso_schema_template_anp_epg" "schema_template_anp_epg" {
for_each = { for epg in local.endpoint_groups : epg.key => epg }
schema_id = each.value.schema_id
template_name = each.value.template_name
anp_name = each.value.anp_name
name = each.value.name
display_name = each.value.name
description = each.value.description
bd_name = each.value.bd_name
bd_schema_id = each.value.bd_schema_id
bd_template_name = each.value.bd_template_name
vrf_name = each.value.vrf_name
vrf_schema_id = each.value.vrf_schema_id
vrf_template_name = each.value.vrf_template_name
useg_epg = each.value.useg_epg
intra_epg = each.value.intra_epg
intersite_multicast_source = each.value.intersite_multicast_source
proxy_arp = each.value.proxy_arp
preferred_group = each.value.preferred_group
epg_type = each.value.epg_type
access_type = each.value.access_type
deployment_type = each.value.deployment_type
service_type = each.value.service_type
custom_service_type = each.value.custom_service_type
depends_on = [
mso_schema_template_bd.schema_template_bd,
mso_schema_template_anp.schema_template_anp,
]
}
locals {
endpoint_groups_sites = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : [
for epg in try(ap.endpoint_groups, []) : [
for site in try(epg.sites, []) : {
key = "${schema.name}/${template.name}/${ap.name}/${epg.name}/${site.name}"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
site_id = var.manage_sites ? mso_site.site[site.name].id : data.mso_site.template_site[site.name].id
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
epg_name = "${epg.name}${local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.name_suffix}"
}
]
]
]
]
])
}
resource "mso_schema_site_anp_epg" "schema_site_anp_epg" {
for_each = { for epg in local.endpoint_groups_sites : epg.key => epg }
schema_id = each.value.schema_id
template_name = each.value.template_name
site_id = each.value.site_id
anp_name = each.value.anp_name
epg_name = each.value.epg_name
depends_on = [
mso_schema_site_anp.schema_site_anp,
mso_schema_template_anp_epg.schema_template_anp_epg,
]
}
locals {
endpoint_groups_contracts = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : [
for epg in try(ap.endpoint_groups, []) : concat([
for contract in try(epg.contracts.consumers, []) : {
key = "${schema.name}/${template.name}/${ap.name}/${epg.name}/${contract.name}/consumer"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
epg_name = "${epg.name}${local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.name_suffix}"
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
contract_schema_id = contains(local.managed_schemas, try(contract.schema, schema.name)) ? mso_schema.schema[try(contract.schema, schema.name)].id : local.schema_ids[contract.schema].id
contract_template_name = try(contract.template, template.name)
relationship_type = "consumer"
}
],
[
for contract in try(epg.contracts.providers, []) : {
key = "${schema.name}/${template.name}/${ap.name}/${epg.name}/${contract.name}/provider"
schema_id = mso_schema.schema[schema.name].id
template_name = template.name
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
epg_name = "${epg.name}${local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.name_suffix}"
contract_name = "${contract.name}${local.defaults.ndo.schemas.templates.contracts.name_suffix}"
contract_schema_id = contains(local.managed_schemas, try(contract.schema, schema.name)) ? mso_schema.schema[try(contract.schema, schema.name)].id : local.schema_ids[contract.schema].id
contract_template_name = try(contract.template, template.name)
relationship_type = "provider"
}
])
]
]
]
])
}
resource "mso_schema_template_anp_epg_contract" "schema_template_anp_epg_contract" {
for_each = { for contract in local.endpoint_groups_contracts : contract.key => contract }
schema_id = each.value.schema_id
template_name = each.value.template_name
anp_name = each.value.anp_name
epg_name = each.value.epg_name
contract_name = each.value.contract_name
contract_schema_id = each.value.contract_schema_id
contract_template_name = each.value.contract_template_name
relationship_type = each.value.relationship_type
depends_on = [
mso_schema_template_anp_epg.schema_template_anp_epg,
mso_schema_template_contract.schema_template_contract,
]
}
locals {
endpoint_groups_subnets = flatten([
for schema in local.schemas : [
for template in try(schema.templates, []) : [
for ap in try(template.application_profiles, []) : [
for epg in try(ap.endpoint_groups, []) : [
for subnet in try(epg.subnets, []) : {
key = "${schema.name}/${template.name}/${ap.name}/${epg.name}/${subnet.ip}"
schema_id = mso_schema.schema[schema.name].id
template = template.name
anp_name = "${ap.name}${local.defaults.ndo.schemas.templates.application_profiles.name_suffix}"
epg_name = "${epg.name}${local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.name_suffix}"
ip = subnet.ip
scope = try(subnet.scope, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.subnets.scope)
shared = try(subnet.shared, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.subnets.shared)
no_default_gateway = try(subnet.no_default_gateway, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.subnets.no_default_gateway)
primary = try(subnet.primary, local.defaults.ndo.schemas.templates.application_profiles.endpoint_groups.subnets.primary)
}
]
]
]
]
])
}
resource "mso_schema_template_anp_epg_subnet" "schema_template_anp_epg_subnet" {
for_each = { for subnet in local.endpoint_groups_subnets : subnet.key => subnet }
schema_id = each.value.schema_id
template = each.value.template
anp_name = each.value.anp_name
epg_name = each.value.epg_name
ip = each.value.ip
scope = each.value.scope
shared = each.value.shared
no_default_gateway = each.value.no_default_gateway
primary = each.value.primary
depends_on = [
mso_schema_template_anp_epg.schema_template_anp_epg,
]