Skip to content

Commit

Permalink
Add empty input warning to catalystcenter_*_settings resources (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-mazurkiewicz authored Feb 27, 2025
1 parent f26fab2 commit 0fde79d
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 45 deletions.
1 change: 1 addition & 0 deletions gen/definitions/banner_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ delete_no_id: true
get_extra_query_params: "?_inherited=true"
put_create: true
put_delete: true
skip_minimum_test: true
doc_category: Network Settings
attributes:
- model_name: siteId
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/dhcp_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ delete_no_id: true
get_extra_query_params: "?_inherited=true"
put_create: true
put_delete: true
skip_minimum_test: true
doc_category: Network Settings
attributes:
- model_name: siteId
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/dns_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ delete_no_id: true
get_extra_query_params: "?_inherited=true"
put_create: true
put_delete: true
skip_minimum_test: true
doc_category: Network Settings
attributes:
- model_name: siteId
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/ntp_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ delete_no_id: true
get_extra_query_params: "?_inherited=true"
put_create: true
put_delete: true
skip_minimum_test: true
doc_category: Network Settings
attributes:
- model_name: siteId
Expand Down
4 changes: 2 additions & 2 deletions gen/definitions/timezone_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ put_no_id: true
get_no_id: true
data_source_no_id: true
import_no_id: true
no_delete: true #Internal error 500 on delete
delete_no_id: true
get_extra_query_params: "?_inherited=true"
put_create: true
put_delete: true
no_delete: true
skip_minimum_test: true
doc_category: Network Settings
attributes:
- model_name: siteId
Expand Down
14 changes: 13 additions & 1 deletion gen/templates/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,20 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D
res, err := r.client.Put({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + "/" + url.QueryEscape(state.Id.ValueString()), "{}")
{{- end}}
if err != nil {
{{- if .PutDelete}}
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
{{- else}}
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
{{- end}}
}
{{- else}}
{{- if .DeleteNoId}}
Expand All @@ -708,7 +720,7 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D
res, err := r.client.Delete({{if .DeleteRestEndpoint}}state.getPathDelete(){{else}}state.getPath(){{end}} + "/" + url.QueryEscape(state.Id.ValueString()))
{{- end}}
if err != nil {
{{- if .DeviceUnreachabilityWarning}}
{{- if .DeviceUnreachabilityWarning}}
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCDP10000" {
// Log a warning and continue execution when device is unreachable
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_aaa_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,15 @@ func (r *AAASettingsResource) Delete(ctx context.Context, req resource.DeleteReq
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_banner_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,15 @@ func (r *BannerSettingsResource) Delete(ctx context.Context, req resource.Delete
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -34,11 +33,6 @@ func TestAccCcBannerSettings(t *testing.T) {
checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_banner_settings.test", "message", "Banner message"))

var steps []resource.TestStep
if os.Getenv("SKIP_MINIMUM_TEST") == "" {
steps = append(steps, resource.TestStep{
Config: testAccCcBannerSettingsPrerequisitesConfig + testAccCcBannerSettingsConfig_minimum(),
})
}
steps = append(steps, resource.TestStep{
Config: testAccCcBannerSettingsPrerequisitesConfig + testAccCcBannerSettingsConfig_all(),
Check: resource.ComposeTestCheckFunc(checks...),
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_dhcp_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,15 @@ func (r *DHCPSettingsResource) Delete(ctx context.Context, req resource.DeleteRe
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -32,11 +31,6 @@ func TestAccCcDHCPSettings(t *testing.T) {
var checks []resource.TestCheckFunc

var steps []resource.TestStep
if os.Getenv("SKIP_MINIMUM_TEST") == "" {
steps = append(steps, resource.TestStep{
Config: testAccCcDHCPSettingsPrerequisitesConfig + testAccCcDHCPSettingsConfig_minimum(),
})
}
steps = append(steps, resource.TestStep{
Config: testAccCcDHCPSettingsPrerequisitesConfig + testAccCcDHCPSettingsConfig_all(),
Check: resource.ComposeTestCheckFunc(checks...),
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_dns_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,15 @@ func (r *DNSSettingsResource) Delete(ctx context.Context, req resource.DeleteReq
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -33,11 +32,6 @@ func TestAccCcDNSSettings(t *testing.T) {
checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_dns_settings.test", "domain_name", "myCompany.com"))

var steps []resource.TestStep
if os.Getenv("SKIP_MINIMUM_TEST") == "" {
steps = append(steps, resource.TestStep{
Config: testAccCcDNSSettingsPrerequisitesConfig + testAccCcDNSSettingsConfig_minimum(),
})
}
steps = append(steps, resource.TestStep{
Config: testAccCcDNSSettingsPrerequisitesConfig + testAccCcDNSSettingsConfig_all(),
Check: resource.ComposeTestCheckFunc(checks...),
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_ntp_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,15 @@ func (r *NTPSettingsResource) Delete(ctx context.Context, req resource.DeleteReq
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -32,11 +31,6 @@ func TestAccCcNTPSettings(t *testing.T) {
var checks []resource.TestCheckFunc

var steps []resource.TestStep
if os.Getenv("SKIP_MINIMUM_TEST") == "" {
steps = append(steps, resource.TestStep{
Config: testAccCcNTPSettingsPrerequisitesConfig + testAccCcNTPSettingsConfig_minimum(),
})
}
steps = append(steps, resource.TestStep{
Config: testAccCcNTPSettingsPrerequisitesConfig + testAccCcNTPSettingsConfig_all(),
Check: resource.ComposeTestCheckFunc(checks...),
Expand Down
11 changes: 9 additions & 2 deletions internal/provider/resource_catalystcenter_telemetry_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,15 @@ func (r *TelemetrySettingsResource) Delete(ctx context.Context, req resource.Del
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString()))
res, err := r.client.Put(state.getPath(), "{}")
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (PUT), got error: %s, %s", err, res.String()))
return
errorCode := res.Get("response.errorCode").String()
if errorCode == "NCND01090" {
// Log a warning and continue execution when Empty input - the groupUuid is null or empty
failureReason := res.Get("response.failureReason").String()
resp.Diagnostics.AddWarning("Empty input Warning", fmt.Sprintf("Empty input detected (error code: %s, reason %s).", errorCode, failureReason))
} else {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (%s), got error: %s, %s", "PUT", err, res.String()))
return
}
}

tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -33,11 +32,6 @@ func TestAccCcTimeZoneSettings(t *testing.T) {
checks = append(checks, resource.TestCheckResourceAttr("catalystcenter_timezone_settings.test", "identifier", "GMT"))

var steps []resource.TestStep
if os.Getenv("SKIP_MINIMUM_TEST") == "" {
steps = append(steps, resource.TestStep{
Config: testAccCcTimeZoneSettingsPrerequisitesConfig + testAccCcTimeZoneSettingsConfig_minimum(),
})
}
steps = append(steps, resource.TestStep{
Config: testAccCcTimeZoneSettingsPrerequisitesConfig + testAccCcTimeZoneSettingsConfig_all(),
Check: resource.ComposeTestCheckFunc(checks...),
Expand Down

0 comments on commit 0fde79d

Please sign in to comment.