Skip to content

Commit 3f1f76a

Browse files
author
Marcin Parafiniuk
committed
review
1 parent 87a525f commit 3f1f76a

File tree

5 files changed

+38
-191
lines changed

5 files changed

+38
-191
lines changed

docs/data-sources/wireless_ssid.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@ data "meraki_wireless_ssid" "example" {
2424

2525
### Required
2626

27+
- `id` (String) The id of the object
2728
- `network_id` (String) Network ID
2829
- `number` (String) Wireless SSID number
2930

30-
### Optional
31-
32-
- `id` (String) The id of the object
33-
- `name` (String) The name of the SSID
34-
- `named_vlans_radius_guest_vlan_name` (String) RADIUS guest VLAN name.
35-
3631
### Read-Only
3732

3833
- `active_directory_credentials_logon_name` (String) The logon name of the Active Directory account.
@@ -74,7 +69,9 @@ data "meraki_wireless_ssid" "example" {
7469
- `local_radius_password_authentication_enabled` (Boolean) Whether or not to use EAP-TTLS/PAP or PEAP-GTC password-based authentication via LDAP lookup.
7570
- `mandatory_dhcp_enabled` (Boolean) If true, Mandatory DHCP will enforce that clients connecting to this SSID must use the IP address assigned by the DHCP server. Clients who use a static IP address won`t be able to associate.
7671
- `min_bitrate` (Number) The minimum bitrate in Mbps of this SSID in the default indoor RF profile. (`1`, `2`, `5.5`, `6`, `9`, `11`, `12`, `18`, `24`, `36`, `48` or `54`)
72+
- `name` (String) The name of the SSID
7773
- `named_vlans_radius_guest_vlan_enabled` (Boolean) Whether or not RADIUS guest named VLAN is enabled.
74+
- `named_vlans_radius_guest_vlan_name` (String) RADIUS guest VLAN name.
7875
- `named_vlans_tagging_by_ap_tags` (Attributes List) The list of AP tags and VLAN names used for named VLAN tagging. If an AP has a tag matching one in the list, then traffic on this SSID will be directed to use the VLAN name associated to the tag. (see [below for nested schema](#nestedatt--named_vlans_tagging_by_ap_tags))
7976
- `named_vlans_tagging_default_vlan_name` (String) The default VLAN name used to tag traffic in the absence of a matching AP tag.
8077
- `named_vlans_tagging_enabled` (Boolean) Whether or not traffic should be directed to use specific VLAN names.

gen/definitions/wireless_ssid.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Wireless SSID
22
rest_endpoint: /networks/%v/wireless/ssids
3-
data_source_name_query: true
43
doc_category: Wireless
54
id_name: number
65
attributes:
@@ -241,6 +240,7 @@ attributes:
241240
- model_name: host
242241
type: String
243242
mandatory: true
243+
id: true
244244
description: IP address (or FQDN) of your Active Directory server.
245245
example: 127.0.0.1
246246
- model_name: port
@@ -318,6 +318,7 @@ attributes:
318318
example: '-----BEGIN CERTIFICATE-----\nMIIEKjCCAxKgAwIBAgIRANb+lsED3eb4+6YKLFFYqEkwDQYJKoZIhvcNAQELBQAw\ngYcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMREwDwYDVQQHDAhT\nYW4gSm9zZTEcMBoGA1UECgwTQ2lzY28gU3lzdGVtcywgSW5jLjESMBAGA1UECwwJ\nRE5BU3BhY2VzMR4wHAYDVQQDDBVjaXNjby5vcGVucm9hbWluZy5vcmcwHhcNMjAx\nMTA1MjEzMzM1WhcNMjExMTA1MjIzMzM1WjCBpDEcMBoGCgmSJomT8ixkAQETDGRu\nYXNwYWNlczpVUzELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMQ4wDAYDVQQKEwVD\naXNjbzEcMBoGA1UECxMTV0JBOldSSVggRW5kLUVudGl0eTE8MDoGA1UEAxMzNjQ3\nMDcwNDM4NDQ5NjQxMjAwMDAuMTg4MzQuaHMuY2lzY28ub3BlbnJvYW1pbmcub3Jn\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoqjP9QgRGyUO3p7SH9QK\nuTq6UYK7nAyjImgS4yQxeBkyZ5f2EUkX8m/AOcewpPxxPBhjPKRwxGeX3S50ksiA\nayFomUeslR0S0Z7RN9rzJa+CFyi9MwWIHMbLgXpB8tsSpgTAqwrzoTzOGq9fgC6u\npZhdZrBkg3FeJgD88goCi9mZDsY2YAoeGRLFJ2fR8iICqIVQy+Htq9pE22WBLpnS\nKjL3+mR9FArHNFtWlhKF2YHMUqyHHrnZnF/Ns7QNoMMF7/CK18iAKgnb+2wuGKM2\naEMddOeOTtz+i/rgjkp/RGMt011EdCsso0/cTo9qqX/bxOOCE4/Mne/ChMkQPnNU\nCwIDAQABo3IwcDAJBgNVHRMEAjAAMB8GA1UdIwQYMBaAFIG+4l5yiB01gP0sw4ML\nUSopqYcuMB0GA1UdDgQWBBSby1T9leYVOVVdOZXiHCSaDDEMiDAOBgNVHQ8BAf8E\nBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwIwDQYJKoZIhvcNAQELBQADggEBAEyE\n1mjSUyY6uNp6W4l20w7SskALSJDRKkOeZxAgF3VMxlsCuEl70s9oEfntwIpyQtSa\njON/9yJHbwm/Az824bmk8Dc7AXIPhay+dftXb8j529gPuYB9AKoPNg0NctkyYCQh\na/3YQVdDWX7XgmEiXkL57M7G6+IdcPDONLArfjOcT9qHdkVVq1AIjlMSx3OQQmm/\nuoLb/G9q/97QA2/l8shG/Na8HjVqGLcl5TNZdbNhs2w9ogxr/GNzqdvym6RQ8vT/\nUR2n+uwH4n1MUxmHYYeyot5dnIV1IJ6hQ54JAncM9HvCLFk1WHz6RKshQUCuPBiJ\nwTw70BVktzJnb0VLeDg=\n-----END CERTIFICATE-----'
319319
- model_name: servers
320320
type: List
321+
ordered_list: true
321322
data_path: [ldap]
322323
exclude_test: true
323324
description: The LDAP servers to be used for authentication.
@@ -408,6 +409,7 @@ attributes:
408409
type: String
409410
description: VLAN name that will be used to tag traffic.
410411
example: My VLAN
412+
id: true
411413
- model_name: tags
412414
type: List
413415
element_type: String
@@ -446,6 +448,7 @@ attributes:
446448
example: tag1
447449
- model_name: radiusAccountingServers
448450
type: List
451+
ordered_list: true
449452
exclude_test: true
450453
description: The RADIUS accounting 802.1X servers to be used for authentication. This param is only valid if the authMode is `open-with-radius`, `8021x-radius` or `ipsk-with-radius` and radiusAccountingEnabled is `true`
451454
attributes:
@@ -473,6 +476,7 @@ attributes:
473476
- model_name: radiusServers
474477
type: List
475478
exclude_test: true
479+
ordered_list: true
476480
description: The RADIUS 802.1X servers to be used for authentication. This param is only valid if the authMode is `open-with-radius`, `8021x-radius` or `ipsk-with-radius`
477481
attributes:
478482
- model_name: caCertificate

internal/provider/data_source_meraki_wireless_ssid.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import (
2323
"fmt"
2424
"net/url"
2525

26-
"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
2726
"github.com/hashicorp/terraform-plugin-framework/datasource"
2827
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
29-
"github.com/hashicorp/terraform-plugin-framework/path"
3028
"github.com/hashicorp/terraform-plugin-framework/types"
3129
"github.com/hashicorp/terraform-plugin-log/tflog"
3230
"github.com/netascode/go-meraki"
@@ -63,8 +61,7 @@ func (d *WirelessSSIDDataSource) Schema(ctx context.Context, req datasource.Sche
6361
Attributes: map[string]schema.Attribute{
6462
"id": schema.StringAttribute{
6563
MarkdownDescription: "The id of the object",
66-
Optional: true,
67-
Computed: true,
64+
Required: true,
6865
},
6966
"network_id": schema.StringAttribute{
7067
MarkdownDescription: "Network ID",
@@ -132,7 +129,6 @@ func (d *WirelessSSIDDataSource) Schema(ctx context.Context, req datasource.Sche
132129
},
133130
"name": schema.StringAttribute{
134131
MarkdownDescription: "The name of the SSID",
135-
Optional: true,
136132
Computed: true,
137133
},
138134
"per_client_bandwidth_limit_down": schema.Int64Attribute{
@@ -370,7 +366,6 @@ func (d *WirelessSSIDDataSource) Schema(ctx context.Context, req datasource.Sche
370366
},
371367
"named_vlans_radius_guest_vlan_name": schema.StringAttribute{
372368
MarkdownDescription: "RADIUS guest VLAN name.",
373-
Optional: true,
374369
Computed: true,
375370
},
376371
"named_vlans_tagging_default_vlan_name": schema.StringAttribute{
@@ -502,14 +497,6 @@ func (d *WirelessSSIDDataSource) Schema(ctx context.Context, req datasource.Sche
502497
},
503498
}
504499
}
505-
func (d *WirelessSSIDDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator {
506-
return []datasource.ConfigValidator{
507-
datasourcevalidator.ExactlyOneOf(
508-
path.MatchRoot("id"),
509-
path.MatchRoot("name"),
510-
),
511-
}
512-
}
513500

514501
func (d *WirelessSSIDDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
515502
if req.ProviderData == nil {
@@ -537,29 +524,6 @@ func (d *WirelessSSIDDataSource) Read(ctx context.Context, req datasource.ReadRe
537524

538525
var res gjson.Result
539526
var err error
540-
if config.Id.IsNull() && !config.Name.IsNull() {
541-
res, err = d.client.Get(config.getPath())
542-
if err != nil {
543-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve objects, got error: %s", err))
544-
return
545-
}
546-
if len(res.Array()) > 0 {
547-
res.ForEach(func(k, v gjson.Result) bool {
548-
if config.Name.ValueString() == v.Get("name").String() {
549-
config.Id = types.StringValue(v.Get("number").String())
550-
tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String()))
551-
res = v
552-
return false
553-
}
554-
return true
555-
})
556-
}
557-
558-
if config.Id.IsNull() {
559-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to find object with name: %s", config.Name.ValueString()))
560-
return
561-
}
562-
}
563527

564528
if !res.Exists() {
565529
res, err = d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString()))

internal/provider/data_source_meraki_wireless_ssid_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ func TestAccDataSourceMerakiWirelessSSID(t *testing.T) {
6565
Config: testAccDataSourceMerakiWirelessSSIDPrerequisitesConfig + testAccDataSourceMerakiWirelessSSIDConfig(),
6666
Check: resource.ComposeTestCheckFunc(checks...),
6767
},
68-
{
69-
Config: testAccDataSourceMerakiWirelessSSIDPrerequisitesConfig + testAccNamedDataSourceMerakiWirelessSSIDConfig(),
70-
Check: resource.ComposeTestCheckFunc(checks...),
71-
},
7268
},
7369
})
7470
}
@@ -136,46 +132,4 @@ func testAccDataSourceMerakiWirelessSSIDConfig() string {
136132
return config
137133
}
138134

139-
func testAccNamedDataSourceMerakiWirelessSSIDConfig() string {
140-
config := `resource "meraki_wireless_ssid" "test" {` + "\n"
141-
config += ` network_id = meraki_network.test.id` + "\n"
142-
config += ` number = "0"` + "\n"
143-
config += ` auth_mode = "psk"` + "\n"
144-
config += ` available_on_all_aps = false` + "\n"
145-
config += ` band_selection = "5 GHz band only"` + "\n"
146-
config += ` enabled = false` + "\n"
147-
config += ` encryption_mode = "wpa"` + "\n"
148-
config += ` ip_assignment_mode = "Bridge mode"` + "\n"
149-
config += ` lan_isolation_enabled = false` + "\n"
150-
config += ` mandatory_dhcp_enabled = false` + "\n"
151-
config += ` min_bitrate = 5.5` + "\n"
152-
config += ` name = "My SSID"` + "\n"
153-
config += ` per_client_bandwidth_limit_down = 0` + "\n"
154-
config += ` per_client_bandwidth_limit_up = 0` + "\n"
155-
config += ` per_ssid_bandwidth_limit_down = 0` + "\n"
156-
config += ` per_ssid_bandwidth_limit_up = 0` + "\n"
157-
config += ` psk = "deadbeef"` + "\n"
158-
config += ` splash_page = "Click-through splash page"` + "\n"
159-
config += ` use_vlan_tagging = false` + "\n"
160-
config += ` visible = false` + "\n"
161-
config += ` walled_garden_enabled = false` + "\n"
162-
config += ` wpa_encryption_mode = "WPA2 only"` + "\n"
163-
config += ` dot11r_adaptive = false` + "\n"
164-
config += ` dot11r_enabled = false` + "\n"
165-
config += ` dot11w_enabled = false` + "\n"
166-
config += ` dot11w_required = false` + "\n"
167-
config += ` speed_burst_enabled = false` + "\n"
168-
config += ` availability_tags = ["tag1"]` + "\n"
169-
config += `}` + "\n"
170-
171-
config += `
172-
data "meraki_wireless_ssid" "test" {
173-
name = meraki_wireless_ssid.test.name
174-
network_id = meraki_network.test.id
175-
number = "0"
176-
}
177-
`
178-
return config
179-
}
180-
181135
// End of section. //template:end testAccDataSourceConfig

internal/provider/model_meraki_wireless_ssid.go

Lines changed: 29 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,8 @@ func (data *WirelessSSID) fromBodyPartial(ctx context.Context, res gjson.Result)
12591259
data.ActiveDirectoryCredentialsPassword = types.StringNull()
12601260
}
12611261
for i := 0; i < len(data.ActiveDirectoryServers); i++ {
1262-
keys := [...]string{"host", "port"}
1263-
keyValues := [...]string{data.ActiveDirectoryServers[i].Host.ValueString(), strconv.FormatInt(data.ActiveDirectoryServers[i].Port.ValueInt64(), 10)}
1262+
keys := [...]string{"host"}
1263+
keyValues := [...]string{data.ActiveDirectoryServers[i].Host.ValueString()}
12641264

12651265
parent := &data
12661266
data := (*parent).ActiveDirectoryServers[i]
@@ -1366,42 +1366,18 @@ func (data *WirelessSSID) fromBodyPartial(ctx context.Context, res gjson.Result)
13661366
} else {
13671367
data.LdapServerCaCertificateContents = types.StringNull()
13681368
}
1369-
for i := 0; i < len(data.LdapServers); i++ {
1370-
keys := [...]string{"host", "port"}
1371-
keyValues := [...]string{data.LdapServers[i].Host.ValueString(), strconv.FormatInt(data.LdapServers[i].Port.ValueInt64(), 10)}
1372-
1369+
{
1370+
l := len(res.Get("ldap.servers").Array())
1371+
tflog.Debug(ctx, fmt.Sprintf("ldap.servers array resizing from %d to %d", len(data.LdapServers), l))
1372+
if len(data.LdapServers) > l {
1373+
data.LdapServers = data.LdapServers[:l]
1374+
}
1375+
}
1376+
for i := range data.LdapServers {
13731377
parent := &data
13741378
data := (*parent).LdapServers[i]
13751379
parentRes := &res
1376-
var res gjson.Result
1377-
1378-
parentRes.Get("ldap.servers").ForEach(
1379-
func(_, v gjson.Result) bool {
1380-
found := false
1381-
for ik := range keys {
1382-
if v.Get(keys[ik]).String() != keyValues[ik] {
1383-
found = false
1384-
break
1385-
}
1386-
found = true
1387-
}
1388-
if found {
1389-
res = v
1390-
return false
1391-
}
1392-
return true
1393-
},
1394-
)
1395-
if !res.Exists() {
1396-
tflog.Debug(ctx, fmt.Sprintf("removing LdapServers[%d] = %+v",
1397-
i,
1398-
(*parent).LdapServers[i],
1399-
))
1400-
(*parent).LdapServers = slices.Delete((*parent).LdapServers, i, i+1)
1401-
i--
1402-
1403-
continue
1404-
}
1380+
res := parentRes.Get(fmt.Sprintf("ldap.servers.%d", i))
14051381
if value := res.Get("host"); value.Exists() && !data.Host.IsNull() {
14061382
data.Host = types.StringValue(value.String())
14071383
} else {
@@ -1580,42 +1556,18 @@ func (data *WirelessSSID) fromBodyPartial(ctx context.Context, res gjson.Result)
15801556
} else {
15811557
data.AvailabilityTags = types.ListNull(types.StringType)
15821558
}
1583-
for i := 0; i < len(data.RadiusAccountingServers); i++ {
1584-
keys := [...]string{"caCertificate", "host", "port", "radsecEnabled", "secret"}
1585-
keyValues := [...]string{data.RadiusAccountingServers[i].CaCertificate.ValueString(), data.RadiusAccountingServers[i].Host.ValueString(), strconv.FormatInt(data.RadiusAccountingServers[i].Port.ValueInt64(), 10), strconv.FormatBool(data.RadiusAccountingServers[i].RadsecEnabled.ValueBool()), data.RadiusAccountingServers[i].Secret.ValueString()}
1586-
1559+
{
1560+
l := len(res.Get("radiusAccountingServers").Array())
1561+
tflog.Debug(ctx, fmt.Sprintf("radiusAccountingServers array resizing from %d to %d", len(data.RadiusAccountingServers), l))
1562+
if len(data.RadiusAccountingServers) > l {
1563+
data.RadiusAccountingServers = data.RadiusAccountingServers[:l]
1564+
}
1565+
}
1566+
for i := range data.RadiusAccountingServers {
15871567
parent := &data
15881568
data := (*parent).RadiusAccountingServers[i]
15891569
parentRes := &res
1590-
var res gjson.Result
1591-
1592-
parentRes.Get("radiusAccountingServers").ForEach(
1593-
func(_, v gjson.Result) bool {
1594-
found := false
1595-
for ik := range keys {
1596-
if v.Get(keys[ik]).String() != keyValues[ik] {
1597-
found = false
1598-
break
1599-
}
1600-
found = true
1601-
}
1602-
if found {
1603-
res = v
1604-
return false
1605-
}
1606-
return true
1607-
},
1608-
)
1609-
if !res.Exists() {
1610-
tflog.Debug(ctx, fmt.Sprintf("removing RadiusAccountingServers[%d] = %+v",
1611-
i,
1612-
(*parent).RadiusAccountingServers[i],
1613-
))
1614-
(*parent).RadiusAccountingServers = slices.Delete((*parent).RadiusAccountingServers, i, i+1)
1615-
i--
1616-
1617-
continue
1618-
}
1570+
res := parentRes.Get(fmt.Sprintf("radiusAccountingServers.%d", i))
16191571
if value := res.Get("caCertificate"); value.Exists() && !data.CaCertificate.IsNull() {
16201572
data.CaCertificate = types.StringValue(value.String())
16211573
} else {
@@ -1643,42 +1595,18 @@ func (data *WirelessSSID) fromBodyPartial(ctx context.Context, res gjson.Result)
16431595
}
16441596
(*parent).RadiusAccountingServers[i] = data
16451597
}
1646-
for i := 0; i < len(data.RadiusServers); i++ {
1647-
keys := [...]string{"caCertificate", "host", "openRoamingCertificateId", "port", "radsecEnabled", "secret"}
1648-
keyValues := [...]string{data.RadiusServers[i].CaCertificate.ValueString(), data.RadiusServers[i].Host.ValueString(), strconv.FormatInt(data.RadiusServers[i].OpenRoamingCertificateId.ValueInt64(), 10), strconv.FormatInt(data.RadiusServers[i].Port.ValueInt64(), 10), strconv.FormatBool(data.RadiusServers[i].RadsecEnabled.ValueBool()), data.RadiusServers[i].Secret.ValueString()}
1649-
1598+
{
1599+
l := len(res.Get("radiusServers").Array())
1600+
tflog.Debug(ctx, fmt.Sprintf("radiusServers array resizing from %d to %d", len(data.RadiusServers), l))
1601+
if len(data.RadiusServers) > l {
1602+
data.RadiusServers = data.RadiusServers[:l]
1603+
}
1604+
}
1605+
for i := range data.RadiusServers {
16501606
parent := &data
16511607
data := (*parent).RadiusServers[i]
16521608
parentRes := &res
1653-
var res gjson.Result
1654-
1655-
parentRes.Get("radiusServers").ForEach(
1656-
func(_, v gjson.Result) bool {
1657-
found := false
1658-
for ik := range keys {
1659-
if v.Get(keys[ik]).String() != keyValues[ik] {
1660-
found = false
1661-
break
1662-
}
1663-
found = true
1664-
}
1665-
if found {
1666-
res = v
1667-
return false
1668-
}
1669-
return true
1670-
},
1671-
)
1672-
if !res.Exists() {
1673-
tflog.Debug(ctx, fmt.Sprintf("removing RadiusServers[%d] = %+v",
1674-
i,
1675-
(*parent).RadiusServers[i],
1676-
))
1677-
(*parent).RadiusServers = slices.Delete((*parent).RadiusServers, i, i+1)
1678-
i--
1679-
1680-
continue
1681-
}
1609+
res := parentRes.Get(fmt.Sprintf("radiusServers.%d", i))
16821610
if value := res.Get("caCertificate"); value.Exists() && !data.CaCertificate.IsNull() {
16831611
data.CaCertificate = types.StringValue(value.String())
16841612
} else {

0 commit comments

Comments
 (0)