Skip to content

Commit ae2d6bc

Browse files
committed
removing data resources
1 parent fce1a20 commit ae2d6bc

12 files changed

+124
-214
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ $RECYCLE.BIN/
393393
.terraform/
394394
.terraform.lock.hcl
395395
*.tfstate
396-
*.tfstate.backup
396+
*.tfstate.*
397397
*.tfplan
398398
*.plan
399399
hidden.tf

README.md

+3-14
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,32 @@ No modules.
3737

3838
| Name | Description |
3939
|------|-------------|
40+
| <a name="output_data_pools"></a> [data\_pools](#output\_data\_pools) | n/a |
41+
| <a name="output_reservations"></a> [reservations](#output\_reservations) | Moids of the Pool Reservations. |
4042
| <a name="output_ip"></a> [ip](#output\_ip) | Moids of the IP Pools. |
41-
| <a name="output_ip_reservations"></a> [ip\_reservations](#output\_ip\_reservations) | Moids of the IP Pool Reservations. |
4243
| <a name="output_iqn"></a> [iqn](#output\_iqn) | Moids of the IQN Pools. |
43-
| <a name="output_iqn_reservations"></a> [iqn\_reservations](#output\_iqn\_reservations) | Moids of the IQN Pool Reservations. |
44-
| <a name="output_locals"></a> [locals](#output\_locals) | n/a |
4544
| <a name="output_mac"></a> [mac](#output\_mac) | Moids of the MAC Pools. |
46-
| <a name="output_mac_reservations"></a> [mac\_reservations](#output\_mac\_reservations) | Moids of the MAC Pool Reservations. |
4745
| <a name="output_resource"></a> [resource](#output\_resource) | Moids of the Resource Pools. |
4846
| <a name="output_uuid"></a> [uuid](#output\_uuid) | Moids of the UUID Pools. |
49-
| <a name="output_uuid_reservations"></a> [uuid\_reservations](#output\_uuid\_reservations) | Moids of the UUID Pool Reservations. |
5047
| <a name="output_wwnn"></a> [wwnn](#output\_wwnn) | Moids of the WWNN Pools. |
51-
| <a name="output_wwnn_reservations"></a> [wwnn\_reservations](#output\_wwnn\_reservations) | Moids of the WWNN Pool Reservations. |
5248
| <a name="output_wwpn"></a> [wwpn](#output\_wwpn) | Moids of the WWPN Pools. |
53-
| <a name="output_wwpn_reservations"></a> [wwpn\_reservations](#output\_wwpn\_reservations) | Moids of the WWPN Pool Reservations. |
54-
| <a name="output_z_moids_of_pools_that_were_referenced_in_server_profile_reservations_but_not_already_created"></a> [z\_moids\_of\_pools\_that\_were\_referenced\_in\_server\_profile\_reservations\_but\_not\_already\_created](#output\_z\_moids\_of\_pools\_that\_were\_referenced\_in\_server\_profile\_reservations\_but\_not\_already\_created) | moids of Pools that were referenced in server profiles but not defined |
5549
## Resources
5650

5751
| Name | Type |
5852
|------|------|
5953
| [intersight_fcpool_pool.wwnn](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_pool) | resource |
60-
| [intersight_fcpool_pool.wwnn_data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_pool) | resource |
6154
| [intersight_fcpool_pool.wwpn](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_pool) | resource |
62-
| [intersight_fcpool_pool.wwpn_data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_pool) | resource |
6355
| [intersight_fcpool_reservation.wwnn](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_reservation) | resource |
6456
| [intersight_fcpool_reservation.wwpn](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/fcpool_reservation) | resource |
65-
| [intersight_ippool_pool.data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/ippool_pool) | resource |
6657
| [intersight_ippool_pool.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/ippool_pool) | resource |
6758
| [intersight_ippool_reservation.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/ippool_reservation) | resource |
68-
| [intersight_iqnpool_pool.data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/iqnpool_pool) | resource |
6959
| [intersight_iqnpool_pool.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/iqnpool_pool) | resource |
7060
| [intersight_iqnpool_reservation.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/iqnpool_reservation) | resource |
71-
| [intersight_macpool_pool.data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/macpool_pool) | resource |
7261
| [intersight_macpool_pool.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/macpool_pool) | resource |
7362
| [intersight_macpool_reservation.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/macpool_reservation) | resource |
7463
| [intersight_resourcepool_pool.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/resourcepool_pool) | resource |
75-
| [intersight_uuidpool_pool.data](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/uuidpool_pool) | resource |
7664
| [intersight_uuidpool_pool.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/uuidpool_pool) | resource |
7765
| [intersight_uuidpool_reservation.map](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/resources/uuidpool_reservation) | resource |
7866
| [intersight_compute_physical_summary.servers](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/data-sources/compute_physical_summary) | data source |
67+
| [intersight_search_search_item.pools](https://registry.terraform.io/providers/CiscoDevNet/intersight/latest/docs/data-sources/search_search_item) | data source |
7968
<!-- END_TF_DOCS -->

data.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#__________________________________________________________________
2+
#
3+
# Data Objects - Pools
4+
#__________________________________________________________________
5+
6+
data "intersight_search_search_item" "pools" {
7+
for_each = { for v in local.pool_types : v => v if length(local.data_pools[v]) > 0 }
8+
additional_properties = length(regexall("wwnn|wwpn", each.key)
9+
) > 0 ? jsonencode({ "ClassId" = "${local.pools[each.key].object}' and Name in ('${trim(join("', '", local.data_pools[each.key]), ", '")}') and PoolPurpose eq '${upper(each.key)}" }
10+
) : jsonencode({ "ClassId" = "${local.pools[each.key].object}' and Name in ('${trim(join("', '", local.data_pools[each.key]), ", '")}') and ObjectType eq '${local.pools[each.key].object}" })
11+
}

ip.tf

+8-23
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ resource "intersight_ippool_pool" "map" {
4444
}
4545
}
4646
organization {
47-
moid = local.orgs[each.value.organization]
47+
moid = var.orgs[each.value.organization]
4848
object_type = "organization.Organization"
4949
}
5050
dynamic "tags" {
@@ -56,38 +56,23 @@ resource "intersight_ippool_pool" "map" {
5656
}
5757
}
5858

59-
resource "intersight_ippool_pool" "data" {
60-
depends_on = [intersight_ippool_pool.map]
61-
for_each = { for v in local.reservation_ip_pools : v => v if lookup(local.ip, v, "#NOEXIST") == "#NOEXIST" }
62-
name = element(split("/", each.value), 1)
63-
organization {
64-
moid = local.orgs[element(split("/", each.value), 0)]
65-
}
66-
lifecycle {
67-
ignore_changes = [
68-
account_moid, additional_properties, ancestors, assigned, assignment_order, create_time, description, domain_group_moid,
69-
ip_v4_blocks, ip_v4_config, ip_v6_blocks, ip_v6_config, mod_time, owners, parent, permission_resources, reservations, reserved,
70-
shadow_pools, shared_scope, size, tags, v4_assigned, v4_size, v6_assigned, v6_size, version_context
71-
]
72-
prevent_destroy = true
73-
}
74-
}
75-
7659
resource "intersight_ippool_reservation" "map" {
77-
depends_on = [intersight_ippool_pool.data]
60+
depends_on = [intersight_ippool_pool.map]
7861
for_each = { for v in local.reservations : "${v.combined}/${v.identity}" => v if v.identity_type == "ip" }
7962
allocation_type = each.value.allocation_type # dynamic|static
8063
identity = each.value.identity
8164
ip_type = each.value.ip_type
8265
organization {
83-
moid = local.orgs[each.value.organization]
66+
moid = var.orgs[each.value.organization]
8467
object_type = "organization.Organization"
8568
}
8669
dynamic "pool" {
87-
for_each = { for v in [each.value.pool_name] : v => v if each.value.allocation_type == "dynamic" }
70+
for_each = { for v in [each.value.combined] : v => v if each.value.allocation_type == "dynamic" }
8871
content {
89-
moid = lookup(local.ip, each.value.combined, "#NOEXIST") != "#NOEXIST" ? intersight_ippool_pool.map[each.value.combined
90-
].moid : intersight_ippool_pool.data[each.value.combined].moid
72+
moid = contains(local.pools.ip.moids, each.value.combined) ? intersight_ippool_pool.map[each.value.combined
73+
].moid : [for i in data.intersight_search_search_item.pools["ip"
74+
].results : i.moid if jsondecode(i.additional_properties).Name == each.value.pool && jsondecode(i.additional_properties
75+
).Organization.Moid == var.orgs[each.value.org]][0]
9176
}
9277
}
9378
}

iqn.tf

+8-22
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "intersight_iqnpool_pool" "map" {
2020
}
2121
}
2222
organization {
23-
moid = local.orgs[each.value.organization]
23+
moid = var.orgs[each.value.organization]
2424
object_type = "organization.Organization"
2525
}
2626
dynamic "tags" {
@@ -32,36 +32,22 @@ resource "intersight_iqnpool_pool" "map" {
3232
}
3333
}
3434

35-
resource "intersight_iqnpool_pool" "data" {
36-
depends_on = [intersight_iqnpool_pool.map]
37-
for_each = { for v in local.reservation_iqn_pools : v => v if lookup(local.iqn, v, "#NOEXIST") == "#NOEXIST" }
38-
name = element(split("/", each.value), 1)
39-
organization {
40-
moid = local.orgs[element(split("/", each.value), 0)]
41-
}
42-
lifecycle {
43-
ignore_changes = [
44-
account_moid, additional_properties, ancestors, assigned, assignment_order, block_heads, create_time, description, domain_group_moid,
45-
iqn_suffix_blocks, mod_time, owners, parent, permission_resources, prefix, reservations, reserved, shared_scope, size, tags, version_context
46-
]
47-
prevent_destroy = true
48-
}
49-
}
50-
5135
resource "intersight_iqnpool_reservation" "map" {
52-
depends_on = [intersight_iqnpool_pool.data]
36+
depends_on = [intersight_iqnpool_pool.map]
5337
for_each = { for v in local.reservations : "${v.combined}/${v.identity}" => v if v.identity_type == "iqn" }
5438
allocation_type = each.value.allocation_type # dynamic|static
5539
identity = each.value.identity
5640
organization {
57-
moid = local.orgs[each.value.organization]
41+
moid = var.orgs[each.value.organization]
5842
object_type = "organization.Organization"
5943
}
6044
dynamic "pool" {
61-
for_each = { for v in [each.value.pool_name] : v => v if each.value.allocation_type == "dynamic" }
45+
for_each = { for v in [each.value.combined] : v => v if each.value.allocation_type == "dynamic" }
6246
content {
63-
moid = lookup(local.iqn, each.value.combined, "#NOEXIST") != "#NOEXIST" ? intersight_iqnpool_pool.map[each.value.combined
64-
].moid : intersight_iqnpool_pool.data[each.value.combined].moid
47+
moid = contains(local.pools.iqn.moids, each.value.combined) ? intersight_iqnpool_pool.map[each.value.combined
48+
].moid : [for i in data.intersight_search_search_item.pools["iqn"
49+
].results : i.moid if jsondecode(i.additional_properties).Name == each.value.pool && jsondecode(i.additional_properties
50+
).Organization.Moid == var.orgs[each.value.org]][0]
6551
}
6652
}
6753
}

locals.tf

+33-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ locals {
2424
wwpn = v.wwpn != "" ? v.wwpn : v.default
2525
}
2626
]]) : i.org => i }
27-
orgs = var.orgs
27+
org_moids = { for k, v in var.orgs : v => k }
2828

2929
#____________________________________________________________
3030
#
@@ -81,19 +81,41 @@ locals {
8181
# Intersight Pool - Reservations
8282
#____________________________________________________________
8383
reservations = flatten([for org in sort(keys(var.model)) : [
84-
for r in flatten([for v in flatten([for e in lookup(lookup(var.model[org], "profiles", {}), "server", []) : e.targets if lookup(e, "ignore_reservations", true) == false]) : lookup(v, "reservations", [])]
84+
for r in flatten([for v in flatten([for e in lookup(lookup(var.model[org], "profiles", {}), "server", []
85+
) : e.targets if lookup(e, "ignore_reservations", true) == false]) : lookup(v, "reservations", [])]
8586
) : merge(local.defaults.reservations, r, {
86-
combined = length(regexall("/", r.pool_name)) > 0 ? r.pool_name : "${org}/${r.pool_name}"
87-
organization = length(regexall("/", r.pool_name)) > 0 ? element(split("/", r.pool_name), 0) : org
88-
pool_name = length(regexall("/", r.pool_name)) > 0 ? element(split("/", r.pool_name), 1) : r.pool_name
87+
combined = length(regexall("/", r.pool_name)) > 0 ? r.pool_name : "${org}/${r.pool_name}"
88+
org = length(regexall("/", r.pool_name)) > 0 ? element(split("/", r.pool_name), 0) : org
89+
pool = length(regexall("/", r.pool_name)) > 0 ? element(split("/", r.pool_name), 1) : r.pool_name
8990
})
9091
]])
91-
reservation_ip_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "ip"]))
92-
reservation_iqn_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "iqn"]))
93-
reservation_mac_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "mac"]))
94-
reservation_uuid_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "uuid"]))
95-
reservation_wwnn_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "wwnn"]))
96-
reservation_wwpn_pools = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "wwpn"]))
92+
reservation = {
93+
ip = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "ip"]))
94+
iqn = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "iqn"]))
95+
mac = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "mac"]))
96+
uuid = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "uuid"]))
97+
wwnn = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "wwnn"]))
98+
wwpn = distinct(compact([for v in local.reservations : "${v.organization}/${v.pool_name}" if v.identity_type == "wwpn"]))
99+
}
100+
pools = {
101+
ip = { moids = keys(local.ip), object = "ippool.Pool" }
102+
iqn = { moids = keys(local.iqn), object = "iqnpool.Pool" }
103+
mac = { moids = keys(local.mac), object = "macpool.Pool" }
104+
uuid = { moids = keys(local.uuid), object = "uuidpool.Pool" }
105+
wwnn = { moids = keys(local.wwnn), object = "fcpool.Pool" }
106+
wwpn = { moids = keys(local.wwpn), object = "fcpool.Pool" }
107+
}
108+
pool_types = ["ip", "iqn", "mac", "uuid", "wwnn", "wwpn"]
109+
data_pools = { for e in local.pool_types : e => [for v in local.reservation[e] : element(split("/", v), 1
110+
) if contains(local.pools[e].moids, v) == false] }
111+
reservation_results = {
112+
ip = { for v in sort(keys(intersight_ippool_reservation.map)) : v => intersight_ippool_reservation.map[v].moid }
113+
iqn = { for v in sort(keys(intersight_iqnpool_reservation.map)) : v => intersight_iqnpool_reservation.map[v].moid }
114+
mac = { for v in sort(keys(intersight_macpool_reservation.map)) : v => intersight_macpool_reservation.map[v].moid }
115+
uuid = { for v in sort(keys(intersight_uuidpool_reservation.map)) : v => intersight_uuidpool_reservation.map[v].moid }
116+
wwnn = { for v in sort(keys(intersight_fcpool_reservation.wwnn)) : v => intersight_fcpool_reservation.wwnn[v].moid }
117+
wwpn = { for v in sort(keys(intersight_fcpool_reservation.wwpn)) : v => intersight_fcpool_reservation.wwpn[v].moid }
118+
}
97119

98120
#____________________________________________________________
99121
#

mac.tf

+8-22
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resource "intersight_macpool_pool" "map" {
1919
}
2020
}
2121
organization {
22-
moid = local.orgs[each.value.organization]
22+
moid = var.orgs[each.value.organization]
2323
object_type = "organization.Organization"
2424
}
2525
dynamic "tags" {
@@ -31,36 +31,22 @@ resource "intersight_macpool_pool" "map" {
3131
}
3232
}
3333

34-
resource "intersight_macpool_pool" "data" {
35-
depends_on = [intersight_macpool_pool.map]
36-
for_each = { for v in local.reservation_mac_pools : v => v if lookup(local.mac, v, "#NOEXIST") == "#NOEXIST" }
37-
name = element(split("/", each.value), 1)
38-
organization {
39-
moid = local.orgs[element(split("/", each.value), 0)]
40-
}
41-
lifecycle {
42-
ignore_changes = [
43-
account_moid, additional_properties, ancestors, assigned, assignment_order, block_heads, create_time, description, domain_group_moid,
44-
mac_blocks, mod_time, owners, parent, permission_resources, reservations, reserved, shared_scope, size, tags, version_context
45-
]
46-
prevent_destroy = true
47-
}
48-
}
49-
5034
resource "intersight_macpool_reservation" "map" {
51-
depends_on = [intersight_macpool_pool.data]
35+
depends_on = [intersight_macpool_pool.map]
5236
for_each = { for v in local.reservations : "${v.combined}/${v.identity}" => v if v.identity_type == "mac" }
5337
allocation_type = each.value.allocation_type # dynamic|static
5438
identity = each.value.identity
5539
organization {
56-
moid = local.orgs[each.value.organization]
40+
moid = var.orgs[each.value.organization]
5741
object_type = "organization.Organization"
5842
}
5943
dynamic "pool" {
60-
for_each = { for v in [each.value.pool_name] : v => v if each.value.allocation_type == "dynamic" }
44+
for_each = { for v in [each.value.combined] : v => v if each.value.allocation_type == "dynamic" }
6145
content {
62-
moid = lookup(local.mac, each.value.combined, "#NOEXIST") != "#NOEXIST" ? intersight_macpool_pool.map[each.value.combined
63-
].moid : intersight_macpool_pool.data[each.value.combined].moid
46+
moid = contains(local.pools.mac.moids, each.value.combined) ? intersight_macpool_pool.map[each.value.combined
47+
].moid : [for i in data.intersight_search_search_item.pools["mac"
48+
].results : i.moid if jsondecode(i.additional_properties).Name == each.value.pool && jsondecode(i.additional_properties
49+
).Organization.Moid == var.orgs[each.value.org]][0]
6450
}
6551
}
6652
}

0 commit comments

Comments
 (0)