-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
executable file
·122 lines (102 loc) · 3.16 KB
/
main.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
terraform {
required_providers {
aci = {
source = "CiscoDevNet/aci"
version = ">=2.0.0"
}
}
experiments = [module_variable_optional_attrs]
}
### Locals ###
locals {
### Set Defaults ###
tenant = defaults(var.tenant, {
use_existing = false
})
### internal_consumed_contracts ###
internal_testing = {
for key, ap in local.tenant.aps :
key => {
ap_name = ap.ap_name
internal_testing = module.aps[key].internal_testing
}
}
### EPG Lookup Map ###
ap_epg_map = {
for key, ap in local.tenant.aps :
key => {
ap_name = ap.ap_name
epg_map = module.aps[key].epg_map
}
}
}
### Load Existing Tenant ###
data "aci_tenant" "tenant" {
count = var.tenant.use_existing == true ? 1 : 0
name = var.tenant.name
}
### Build New Tenant ###
resource "aci_tenant" "tenant" {
count = var.tenant.use_existing == false ? 1 : 0
name = var.tenant.name
description = var.tenant.description
annotation = "orchestrator:Terraform"
}
### Networking Section Module ###
module "networking" {
source = "./modules/networking"
### Variables ###
networking = var.tenant.networking
tenant = {
name = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].name : aci_tenant.tenant[0].name
id = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].id : aci_tenant.tenant[0].id
}
contract_map = module.contracts.contract_map
}
### Application Profile Section Module ###
module "aps" {
for_each = local.tenant.aps
source = "./modules/aps"
### Variables ###
ap = each.value
tenant = {
name = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].name : aci_tenant.tenant[0].name
id = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].id : aci_tenant.tenant[0].id
}
vrf_map = module.networking.vrf_map
bd_map = module.networking.bd_map
contract_map = module.contracts.contract_map
}
### Contracts & Filters Section Module ###
module "contracts" {
source = "./modules/contracts"
### Variables ###
contracts = var.tenant.contracts
tenant = {
name = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].name : aci_tenant.tenant[0].name
id = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].id : aci_tenant.tenant[0].id
}
sgt_map = module.services.sgt_map
device_map = module.services.device_map
srp_map = module.policies.srp_map
}
### Policies Section Module ###
module "policies" {
source = "./modules/policies"
### Variables ###
tenant = {
name = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].name : aci_tenant.tenant[0].name
id = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].id : aci_tenant.tenant[0].id
}
policies = var.tenant.policies
}
### Services Section Module ###
module "services" {
source = "./modules/services"
### Variables ###
tenant = {
name = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].name : aci_tenant.tenant[0].name
id = local.tenant.use_existing == true ? data.aci_tenant.tenant[0].id : aci_tenant.tenant[0].id
}
services = var.tenant.services
}