-
Notifications
You must be signed in to change notification settings - Fork 0
/
chassis.tf
87 lines (83 loc) · 4.02 KB
/
chassis.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
#____________________________________________________________
#
# Intersight UCS Chassis Profile Resource
# GUI Location: Profiles > UCS Chassis Profile > Create
#____________________________________________________________
data "intersight_equipment_chassis" "chassis" {
for_each = { for v in local.chassis_serial_numbers : v => v }
serial = each.value
}
resource "intersight_chassis_profile" "map" {
depends_on = [
data.intersight_chassis_profile_template.map,
data.intersight_equipment_chassis.chassis,
data.intersight_search_search_item.policies,
data.intersight_search_search_item.pools,
intersight_chassis_profile_template.map,
intersight_fabric_switch_profile.deploy,
time_sleep.discovery,
time_sleep.domain
]
for_each = local.chassis
additional_properties = jsonencode({
SrcTemplate = each.value.attach_template == true && each.value.detach_template == false && length(regexall("UNUSED", each.value.ucs_chassis_profile_template)
) == 0 ? { Moid = local.ucs_templates.chassis[each.value.ucs_chassis_profile_template].moid, ObjectType = "chassis.ProfileTemplate" } : null
})
description = lookup(each.value, "description", "${each.value.name} Chassis Profile.")
name = each.value.name
target_platform = each.value.target_platform
type = "instance"
user_label = each.value.user_label
lifecycle {
ignore_changes = [action, additional_properties, config_context, mod_time, wait_for_completion]
}
organization { moid = var.orgs[each.value.org] }
dynamic "assigned_chassis" {
for_each = { for v in compact([each.value.serial_number]) : v => v if each.value.serial_number != "unknown" }
content { moid = data.intersight_equipment_chassis.chassis[assigned_chassis.value].results[0].moid }
}
dynamic "policy_bucket" {
for_each = { for v in each.value.policy_bucket : v.object_type => v if element(split("/", v.name), 1) != "UNUSED" }
content {
moid = contains(keys(lookup(local.policies, policy_bucket.value.policy, {})), policy_bucket.value.name
) == true ? local.policies[policy_bucket.value.policy][policy_bucket.value.name] : local.policies_data[policy_bucket.value.policy][policy_bucket.value.name].moid
object_type = policy_bucket.value.object_type
}
}
dynamic "tags" {
for_each = { for v in each.value.tags : v.key => v }
content {
key = tags.value.key
value = tags.value.value
}
}
}
#_________________________________________________________________________________________
#
# Sleep Timer between Creating the Chassis Profile and Waiting for Validation
#_________________________________________________________________________________________
resource "time_sleep" "chassis" {
depends_on = [intersight_chassis_profile.map]
for_each = { for v in ["wait_for_validation_2m"] : v => v if length(local.chassis) > 0 }
create_duration = length([for k, v in local.chassis : 1 if v.action == "Deploy"]) > 0 ? "2m" : "1s"
triggers = { always_run = length(local.wait_for_domain) > 0 ? timestamp() : 1 }
}
#_________________________________________________________________________________________
#
# Intersight: UCS Chassis Profiles
# GUI Location: Infrastructure Service > Configure > Profiles : UCS Chassis Profiles
#_________________________________________________________________________________________
resource "intersight_chassis_profile" "deploy" {
depends_on = [time_sleep.chassis]
for_each = local.chassis
action = length(regexall("^[A-Z]{3}[1-3][\\d]([0][1-9]|[1-4][0-9]|[5][0-3])[\\dA-Z]{4}$", each.value.serial_number)
) > 0 ? each.value.action : "No-op"
lifecycle { ignore_changes = [
action_params, ancestors, create_time, description, domain_group_moid, mod_time, owners, parent,
permission_resources, policy_bucket, running_workflows, shared_scope, src_template, tags, version_context
] }
name = each.value.name
target_platform = each.value.target_platform
user_label = each.value.user_label
organization { moid = var.orgs[each.value.org] }
}