Skip to content

Commit fb9345b

Browse files
authored
fix ap provisioning without ip address (#98)
1 parent 89a789d commit fb9345b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

cc_device_provision.tf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ locals {
9595
d.site => {
9696
name = d.name
9797
fqdn_name = d.fqdn_name
98-
device_ip = d.device_ip
98+
device_ip = try(d.device_ip, null)
9999
}... if d.state == "ASSIGN" && contains(local.sites, try(d.site, "NONE")) && try(d.type, null) != "AccessPoint"
100100
&& (
101101
lookup(local.device_name_to_id, d.name, null) != null ||
102102
lookup(local.device_name_to_id, try(d.fqdn_name, ""), null) != null ||
103-
lookup(local.device_ip_to_id, d.device_ip, null) != null
103+
lookup(local.device_ip_to_id, try(d.device_ip, ""), null) != null
104104
)
105105
}
106106

@@ -109,12 +109,12 @@ locals {
109109
d.site => {
110110
name = d.name
111111
fqdn_name = d.fqdn_name
112-
device_ip = d.device_ip
112+
device_ip = try(d.device_ip, null)
113113
}... if(strcontains(d.state, "PROVISION") || d.state == "ASSIGN" || d.state == "MARK_FOR_REPLACEMENT") && contains(local.sites, try(d.site, "NONE")) && try(d.type, null) == "AccessPoint"
114114
&& (
115115
lookup(local.device_name_to_id, d.name, null) != null ||
116116
lookup(local.device_name_to_id, try(d.fqdn_name, ""), null) != null ||
117-
lookup(local.device_ip_to_id, d.device_ip, null) != null
117+
lookup(local.device_ip_to_id, try(d.device_ip, ""), null) != null
118118
)
119119
}
120120

@@ -123,12 +123,12 @@ locals {
123123
d.site => {
124124
name = d.name
125125
fqdn_name = d.fqdn_name
126-
device_ip = d.device_ip
126+
device_ip = try(d.device_ip, null)
127127
}... if(strcontains(d.state, "PROVISION") || d.state == "MARK_FOR_REPLACEMENT") && try(d.primary_managed_ap_locations, null) != null && !contains(try(d.fabric_roles, []), "EMBEDDED_WIRELESS_CONTROLLER_NODE") && contains(local.sites, try(d.site, "NONE"))
128128
&& (
129129
lookup(local.device_name_to_id, d.name, null) != null ||
130130
lookup(local.device_name_to_id, try(d.fqdn_name, ""), null) != null ||
131-
lookup(local.device_ip_to_id, d.device_ip, null) != null
131+
lookup(local.device_ip_to_id, try(d.device_ip, ""), null) != null
132132
)
133133
}
134134
}
@@ -144,10 +144,10 @@ locals {
144144
&& try(device.type, null) != "AccessPoint"
145145
&& lookup(local.device_name_to_id, device.name, null) == null
146146
&& lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) == null
147-
&& lookup(local.device_ip_to_id, device.device_ip, null) == null
147+
&& lookup(local.device_ip_to_id, try(device.device_ip, ""), null) == null
148148
]
149149

150-
missing_devices_error = length(local.missing_devices) > 0 ? "❌ The following devices are not found in Catalyst Center inventory:\n\n${join("\n", [for d in local.missing_devices : "${d.name} (IP: ${d.device_ip}, FQDN: ${try(d.fqdn_name, "N/A")}, Site: ${d.site})"])}\n\nAction required: Ensure all devices are discovered in Catalyst Center before running Terraform." : ""
150+
missing_devices_error = length(local.missing_devices) > 0 ? "❌ The following devices are not found in Catalyst Center inventory:\n\n${join("\n", [for d in local.missing_devices : "${d.name} (IP: ${try(d.device_ip, "N/A")}, FQDN: ${try(d.fqdn_name, "N/A")}, Site: ${d.site})"])}\n\nAction required: Ensure all devices are discovered in Catalyst Center before running Terraform." : ""
151151
}
152152

153153
check "device_discovery_validation" {
@@ -192,7 +192,7 @@ resource "catalystcenter_update_device_management_address" "management_ip" {
192192
try(lookup(local.device_name_to_id, each.value.name, null), null),
193193
try(lookup(local.device_name_to_id, each.value.fqdn_name, null), null)
194194
)
195-
new_ip = each.value.device_ip
195+
new_ip = try(each.value.device_ip, null)
196196
}
197197

198198
resource "catalystcenter_assign_device_to_site" "devices_to_site" {
@@ -204,7 +204,7 @@ resource "catalystcenter_assign_device_to_site" "devices_to_site" {
204204
if(
205205
lookup(local.device_name_to_id, device.name, null) != null ||
206206
lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) != null ||
207-
lookup(local.device_ip_to_id, device.device_ip, null) != null
207+
lookup(local.device_ip_to_id, try(device.device_ip, ""), null) != null
208208
)
209209
]
210210
site_id = var.use_bulk_api ? coalesce(local.site_id_list_bulk[each.key], local.data_source_created_sites_list[each.key]) : local.site_id_list[each.key]
@@ -219,7 +219,7 @@ resource "catalystcenter_assign_device_to_site" "access_points_to_site" {
219219
if(
220220
lookup(local.device_name_to_id, device.name, null) != null ||
221221
lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) != null ||
222-
lookup(local.device_ip_to_id, device.device_ip, null) != null
222+
lookup(local.device_ip_to_id, try(device.device_ip, ""), null) != null
223223
)
224224
]
225225
site_id = var.use_bulk_api ? coalesce(local.site_id_list_bulk[each.key], local.data_source_created_sites_list[each.key]) : local.site_id_list[each.key]
@@ -235,7 +235,7 @@ resource "catalystcenter_device_role" "role" {
235235
&& (
236236
lookup(local.device_name_to_id, device.name, null) != null ||
237237
lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) != null ||
238-
lookup(local.device_ip_to_id, device.device_ip, null) != null
238+
lookup(local.device_ip_to_id, try(device.device_ip, ""), null) != null
239239
)
240240
}
241241

@@ -278,7 +278,7 @@ resource "catalystcenter_provision_devices" "provision_devices" {
278278
if(
279279
lookup(local.device_name_to_id, device.name, null) != null ||
280280
lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) != null ||
281-
lookup(local.device_ip_to_id, device.device_ip, null) != null
281+
lookup(local.device_ip_to_id, try(device.device_ip, ""), null) != null
282282
)
283283
]
284284

@@ -294,7 +294,7 @@ resource "catalystcenter_assign_device_to_site" "wireless_devices_to_site" {
294294
if(
295295
lookup(local.device_name_to_id, device.name, null) != null ||
296296
lookup(local.device_name_to_id, try(device.fqdn_name, ""), null) != null ||
297-
lookup(local.device_ip_to_id, device.device_ip, null) != null
297+
lookup(local.device_ip_to_id, try(device.device_ip, ""), null) != null
298298
)
299299
]
300300

cc_templates.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ locals {
115115
for tag in try(device.tags, []) : {
116116
"tag_name" = tag,
117117
"device_name" = device.name
118-
"device_ip" = device.device_ip
118+
"device_ip" = try(device.device_ip, null)
119119
"fqdn_name" = device.fqdn_name
120120
}
121121
] if try(device.tags, null) != null && (strcontains(device.state, "PROVISION") || device.state == "ASSIGN" || device.state == "MARK_FOR_REPLACEMENT")

0 commit comments

Comments
 (0)