Skip to content

Commit

Permalink
Add attributes to wireless ssid resource and add device unreachabilit…
Browse files Browse the repository at this point in the history
…y warning to fabric resources (#153)
  • Loading branch information
kuba-mazurkiewicz authored Dec 2, 2024
1 parent e6ae941 commit 5f35b19
Show file tree
Hide file tree
Showing 24 changed files with 189 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.17 (unreleased)

- Add device unreachability warning to `catalystcenter_anycast_gateway`, `catalystcenter_fabric_l2_handoff`, `catalystcenter_fabric_device`, `catalystcenter_fabric_port_assignment` and `catalystcenter_provision_device` resources
- Add `isAuthKeyPSK` and `isAuthKeyPSKPlusFT` attributes to `catalystcenter_wireless_ssid` resource

## 0.1.16

- Add device unreachability warning to `catalystcenter_fabric_l3_handoff_ip_transit` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/150)
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/wireless_ssid.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ data "catalystcenter_wireless_ssid" "example" {
- `auth_key_easy_psk` (Boolean) When set to true, the feature that enables the use of Easy Pre-shared Key (PSK) authentication is activated
- `auth_key_easy_psk_sha256` (Boolean) The feature that allows the use of Pre-shared Key (PSK) authentication with the SHA256 algorithm is enabled when it is set to true
- `auth_key_owe` (Boolean) When set to true, the Opportunistic Wireless Encryption (OWE) authentication key feature is turned on
- `auth_key_psk` (Boolean) When set to true, the Pre-shared Key (PSK) authentication feature is enabled
- `auth_key_psk_plus_ft` (Boolean) When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated
- `auth_key_sae` (Boolean) When set to true, the feature enabling the Simultaneous Authentication of Equals (SAE) authentication key is activated
- `auth_key_sae_ext` (Boolean) When set to true, the Simultaneous Authentication of Equals (SAE) Extended Authentication key feature is turned on
- `auth_key_sae_ext_plus_tf` (Boolean) When set to true, the Simultaneous Authentication of Equals (SAE) combined with Fast Transition (FT) Authentication Key feature is enabled
Expand Down
5 changes: 5 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ description: |-

# Changelog

## 0.1.17 (unreleased)

- Add device unreachability warning to `catalystcenter_anycast_gateway`, `catalystcenter_fabric_l2_handoff`, `catalystcenter_fabric_device`, `catalystcenter_fabric_port_assignment` and `catalystcenter_provision_device` resources
- Add `isAuthKeyPSK` and `isAuthKeyPSKPlusFT` attributes to `catalystcenter_wireless_ssid` resource

## 0.1.16

- Add device unreachability warning to `catalystcenter_fabric_l3_handoff_ip_transit` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/150)
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/wireless_ssid.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ resource "catalystcenter_wireless_ssid" "example" {
- `auth_key_easy_psk` (Boolean) When set to true, the feature that enables the use of Easy Pre-shared Key (PSK) authentication is activated
- `auth_key_easy_psk_sha256` (Boolean) The feature that allows the use of Pre-shared Key (PSK) authentication with the SHA256 algorithm is enabled when it is set to true
- `auth_key_owe` (Boolean) When set to true, the Opportunistic Wireless Encryption (OWE) authentication key feature is turned on
- `auth_key_psk` (Boolean) When set to true, the Pre-shared Key (PSK) authentication feature is enabled
- `auth_key_psk_plus_ft` (Boolean) When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated
- `auth_key_sae` (Boolean) When set to true, the feature enabling the Simultaneous Authentication of Equals (SAE) authentication key is activated
- `auth_key_sae_ext` (Boolean) When set to true, the Simultaneous Authentication of Equals (SAE) Extended Authentication key feature is turned on
- `auth_key_sae_ext_plus_tf` (Boolean) When set to true, the Simultaneous Authentication of Equals (SAE) combined with Fast Transition (FT) Authentication Key feature is enabled
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/anycast_gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data_source_no_id: true
skip_minimum_test: true
put_id_include_path: "0.id"
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
attributes:
- model_name: fabricId
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ put_id_include_path: 0.id
import_no_id: true
data_source_no_id: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_l2_handoff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ id_from_query_path_attribute: id
put_id_include_path: 0.id
get_from_all: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_l3_handoff_ip_transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ id_from_query_path_attribute: id
put_id_include_path: 0.id
get_from_all: true
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_port_assignment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data_source_no_id: true
id_from_attribute: true
root_list: true
skip_minimum_test: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/fabric_provision_device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import_no_id: true
data_source_no_id: true
put_id_include_path: "0.id"
put_no_id: true
device_unreachability_warning: true
doc_category: SDA
test_tags: [SDA]
attributes:
Expand Down
10 changes: 10 additions & 0 deletions gen/definitions/wireless_ssid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ attributes:
type: Bool
description: When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated
exclude_test: true
- model_name: isAuthKeyPSK
tf_name: auth_key_psk
type: Bool
description: When set to true, the Pre-shared Key (PSK) authentication feature is enabled
exclude_test: true
- model_name: isAuthKeyPSKPlusFT
tf_name: auth_key_psk_plus_ft
type: Bool
description: When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated
exclude_test: true
- model_name: isAuthKeyOWE
tf_name: auth_key_owe
type: Bool
Expand Down
85 changes: 43 additions & 42 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,49 @@ var templates = []t{
}

type YamlConfig struct {
Name string `yaml:"name"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
PutRestEndpoint string `yaml:"put_rest_endpoint"`
DeleteRestEndpoint string `yaml:"delete_rest_endpoint"`
GetNoId bool `yaml:"get_no_id"`
GetFromAll bool `yaml:"get_from_all"`
GetRequiresId bool `yaml:"get_requires_id"`
GetExtraQueryParams string `yaml:"get_extra_query_params"`
NoDelete bool `yaml:"no_delete"`
DataSourceNoId bool `yaml:"data_source_no_id"`
DeleteNoId bool `yaml:"delete_no_id"`
NoUpdate bool `yaml:"no_update"`
NoRead bool `yaml:"no_read"`
NoImport bool `yaml:"no_import"`
ImportNoId bool `yaml:"import_no_id"`
PostUpdate bool `yaml:"post_update"`
PutCreate bool `yaml:"put_create"`
RootList bool `yaml:"root_list"`
NoReadPrefix bool `yaml:"no_read_prefix"`
IdPath string `yaml:"id_path"`
IdFromQueryPath string `yaml:"id_from_query_path"`
IdFromQueryPathAttribute string `yaml:"id_from_query_path_attribute"`
IdQueryParam string `yaml:"id_query_param"`
IdFromAttribute bool `yaml:"id_from_attribute"`
PutIdIncludePath string `yaml:"put_id_include_path"`
PutIdQueryParam string `yaml:"put_id_query_param"`
PutNoId bool `yaml:"put_no_id"`
PutUpdateId bool `yaml:"put_update_id"`
DeleteIdQueryParam string `yaml:"delete_id_query_param"`
MinimumVersion string `yaml:"minimum_version"`
DsDescription string `yaml:"ds_description"`
ResDescription string `yaml:"res_description"`
DocCategory string `yaml:"doc_category"`
ExcludeTest bool `yaml:"exclude_test"`
SkipMinimumTest bool `yaml:"skip_minimum_test"`
Attributes []YamlConfigAttribute `yaml:"attributes"`
TestTags []string `yaml:"test_tags"`
TestPrerequisites string `yaml:"test_prerequisites"`
MaxAsyncWaitTime int64 `yaml:"max_async_wait_time"`
Name string `yaml:"name"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
PutRestEndpoint string `yaml:"put_rest_endpoint"`
DeleteRestEndpoint string `yaml:"delete_rest_endpoint"`
GetNoId bool `yaml:"get_no_id"`
GetFromAll bool `yaml:"get_from_all"`
GetRequiresId bool `yaml:"get_requires_id"`
GetExtraQueryParams string `yaml:"get_extra_query_params"`
NoDelete bool `yaml:"no_delete"`
DataSourceNoId bool `yaml:"data_source_no_id"`
DeleteNoId bool `yaml:"delete_no_id"`
NoUpdate bool `yaml:"no_update"`
NoRead bool `yaml:"no_read"`
NoImport bool `yaml:"no_import"`
ImportNoId bool `yaml:"import_no_id"`
PostUpdate bool `yaml:"post_update"`
PutCreate bool `yaml:"put_create"`
RootList bool `yaml:"root_list"`
NoReadPrefix bool `yaml:"no_read_prefix"`
IdPath string `yaml:"id_path"`
IdFromQueryPath string `yaml:"id_from_query_path"`
IdFromQueryPathAttribute string `yaml:"id_from_query_path_attribute"`
IdQueryParam string `yaml:"id_query_param"`
IdFromAttribute bool `yaml:"id_from_attribute"`
DeviceUnreachabilityWarning bool `yaml:"device_unreachability_warning"`
PutIdIncludePath string `yaml:"put_id_include_path"`
PutIdQueryParam string `yaml:"put_id_query_param"`
PutNoId bool `yaml:"put_no_id"`
PutUpdateId bool `yaml:"put_update_id"`
DeleteIdQueryParam string `yaml:"delete_id_query_param"`
MinimumVersion string `yaml:"minimum_version"`
DsDescription string `yaml:"ds_description"`
ResDescription string `yaml:"res_description"`
DocCategory string `yaml:"doc_category"`
ExcludeTest bool `yaml:"exclude_test"`
SkipMinimumTest bool `yaml:"skip_minimum_test"`
Attributes []YamlConfigAttribute `yaml:"attributes"`
TestTags []string `yaml:"test_tags"`
TestPrerequisites string `yaml:"test_prerequisites"`
MaxAsyncWaitTime int64 `yaml:"max_async_wait_time"`
}

type YamlConfigAttribute struct {
Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ id_from_query_path: str(required=False) # Specify path to ID container if ID is
id_from_query_path_attribute: str(required=False) # Specify attribute name of ID, only relevant if "id_from_query_path" option used, default is "id"
id_query_param: str(required=False) # Query parameter used to specify the ID
id_from_attribute: bool(required=False) # Set to true if the ID is derived from an attribute
device_unreachability_warning: bool(required=False) # Set to true if a warning should be displayed for device unreachability instead of error
put_id_include_path: str(required=False) # If PUT needs to have specific JSON path where ID should be inserted
put_id_query_param: str(required=False) # If PUT needs to have specific query parameter where ID should be inserted
put_no_id: bool(required=False) # Set to true if the PUT request does not require an ID
Expand Down
12 changes: 12 additions & 0 deletions gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,20 @@ func (r *{{camelCase .Name}}Resource) Create(ctx context.Context, req resource.C
res, err := r.client.Post(plan.getPath() + params, body {{- if .MaxAsyncWaitTime }}, func(r *cc.Req) { r.MaxAsyncWaitTime={{.MaxAsyncWaitTime}} }{{end}})
{{- end}}
if err != nil {
{{- if .DeviceUnreachabilityWarning}}
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
{{- else}}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", {{- if .PutCreate }} "PUT" {{- else }} "POST" {{- end }}, err, res.String()))
return
{{- end}}
}
{{- /* Check if id can be resolved directly from response */}}
{{- if .IdPath}}
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/data_source_catalystcenter_wireless_ssid.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func (d *WirelessSSIDDataSource) Schema(ctx context.Context, req datasource.Sche
MarkdownDescription: "When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated",
Computed: true,
},
"auth_key_psk": schema.BoolAttribute{
MarkdownDescription: "When set to true, the Pre-shared Key (PSK) authentication feature is enabled",
Computed: true,
},
"auth_key_psk_plus_ft": schema.BoolAttribute{
MarkdownDescription: "When set to true, the feature that enables the combination of Pre-shared Key (PSK) and Fast Transition (FT) authentication keys is activated",
Computed: true,
},
"auth_key_owe": schema.BoolAttribute{
MarkdownDescription: "When set to true, the Opportunistic Wireless Encryption (OWE) authentication key feature is turned on",
Computed: true,
Expand Down
34 changes: 34 additions & 0 deletions internal/provider/model_catalystcenter_wireless_ssid.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type WirelessSSID struct {
AuthKey8021xSha256 types.Bool `tfsdk:"auth_key8021x_sha256"`
AuthKeySae types.Bool `tfsdk:"auth_key_sae"`
AuthKeySaePlusFt types.Bool `tfsdk:"auth_key_sae_plus_ft"`
AuthKeyPsk types.Bool `tfsdk:"auth_key_psk"`
AuthKeyPskPlusFt types.Bool `tfsdk:"auth_key_psk_plus_ft"`
AuthKeyOwe types.Bool `tfsdk:"auth_key_owe"`
AuthKeyEasyPsk types.Bool `tfsdk:"auth_key_easy_psk"`
AuthKeyEasyPskSha256 types.Bool `tfsdk:"auth_key_easy_psk_sha256"`
Expand Down Expand Up @@ -245,6 +247,12 @@ func (data WirelessSSID) toBody(ctx context.Context, state WirelessSSID) string
if !data.AuthKeySaePlusFt.IsNull() {
body, _ = sjson.Set(body, "isAuthKeySaePlusFT", data.AuthKeySaePlusFt.ValueBool())
}
if !data.AuthKeyPsk.IsNull() {
body, _ = sjson.Set(body, "isAuthKeyPSK", data.AuthKeyPsk.ValueBool())
}
if !data.AuthKeyPskPlusFt.IsNull() {
body, _ = sjson.Set(body, "isAuthKeyPSKPlusFT", data.AuthKeyPskPlusFt.ValueBool())
}
if !data.AuthKeyOwe.IsNull() {
body, _ = sjson.Set(body, "isAuthKeyOWE", data.AuthKeyOwe.ValueBool())
}
Expand Down Expand Up @@ -529,6 +537,16 @@ func (data *WirelessSSID) fromBody(ctx context.Context, res gjson.Result) {
} else {
data.AuthKeySaePlusFt = types.BoolNull()
}
if value := res.Get("isAuthKeyPSK"); value.Exists() {
data.AuthKeyPsk = types.BoolValue(value.Bool())
} else {
data.AuthKeyPsk = types.BoolNull()
}
if value := res.Get("isAuthKeyPSKPlusFT"); value.Exists() {
data.AuthKeyPskPlusFt = types.BoolValue(value.Bool())
} else {
data.AuthKeyPskPlusFt = types.BoolNull()
}
if value := res.Get("isAuthKeyOWE"); value.Exists() {
data.AuthKeyOwe = types.BoolValue(value.Bool())
} else {
Expand Down Expand Up @@ -884,6 +902,16 @@ func (data *WirelessSSID) updateFromBody(ctx context.Context, res gjson.Result)
} else {
data.AuthKeySaePlusFt = types.BoolNull()
}
if value := res.Get("isAuthKeyPSK"); value.Exists() && !data.AuthKeyPsk.IsNull() {
data.AuthKeyPsk = types.BoolValue(value.Bool())
} else {
data.AuthKeyPsk = types.BoolNull()
}
if value := res.Get("isAuthKeyPSKPlusFT"); value.Exists() && !data.AuthKeyPskPlusFt.IsNull() {
data.AuthKeyPskPlusFt = types.BoolValue(value.Bool())
} else {
data.AuthKeyPskPlusFt = types.BoolNull()
}
if value := res.Get("isAuthKeyOWE"); value.Exists() && !data.AuthKeyOwe.IsNull() {
data.AuthKeyOwe = types.BoolValue(value.Bool())
} else {
Expand Down Expand Up @@ -1142,6 +1170,12 @@ func (data *WirelessSSID) isNull(ctx context.Context, res gjson.Result) bool {
if !data.AuthKeySaePlusFt.IsNull() {
return false
}
if !data.AuthKeyPsk.IsNull() {
return false
}
if !data.AuthKeyPskPlusFt.IsNull() {
return false
}
if !data.AuthKeyOwe.IsNull() {
return false
}
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_anycast_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ func (r *AnycastGatewayResource) Create(ctx context.Context, req resource.Create
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?fabricId=" + url.QueryEscape(plan.FabricId.ValueString()) + "&virtualNetworkName=" + url.QueryEscape(plan.VirtualNetworkName.ValueString()) + "&ipPoolName=" + url.QueryEscape(plan.IpPoolName.ValueString())
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_fabric_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ func (r *FabricDeviceResource) Create(ctx context.Context, req resource.CreateRe
params := ""
res, err := r.client.Post(plan.getPath()+params, body)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Device Unreachability Warning", fmt.Sprintf("Device unreachability detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (%s), got error: %s, %s", "POST", err, res.String()))
return
}
}
params = ""
params += "?networkDeviceId=" + url.QueryEscape(plan.NetworkDeviceId.ValueString()) + "&fabricId=" + url.QueryEscape(plan.FabricId.ValueString())
Expand Down
Loading

0 comments on commit 5f35b19

Please sign in to comment.