diff --git a/pagerduty/config.go b/pagerduty/config.go index f81473c6e..e3bb261b2 100644 --- a/pagerduty/config.go +++ b/pagerduty/config.go @@ -50,8 +50,7 @@ const invalidCreds = ` No valid credentials found for PagerDuty provider. Please see https://www.terraform.io/docs/providers/pagerduty/index.html -for more information on providing credentials for this provider. -` +for more information on providing credentials for this provider` // Client returns a PagerDuty client, initializing when necessary. func (c *Config) Client() (*pagerduty.Client, error) { @@ -68,8 +67,7 @@ func (c *Config) Client() (*pagerduty.Client, error) { return nil, fmt.Errorf(invalidCreds) } - var httpClient *http.Client - httpClient = http.DefaultClient + httpClient := http.DefaultClient httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport) var apiUrl = c.ApiUrl @@ -121,8 +119,7 @@ func (c *Config) SlackClient() (*pagerduty.Client, error) { return nil, fmt.Errorf(invalidCreds) } - var httpClient *http.Client - httpClient = http.DefaultClient + httpClient := http.DefaultClient httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport) config := &pagerduty.Config{ diff --git a/pagerduty/data_source_pagerduty_business_service.go b/pagerduty/data_source_pagerduty_business_service.go index 66a5059ab..4c35bed2f 100644 --- a/pagerduty/data_source_pagerduty_business_service.go +++ b/pagerduty/data_source_pagerduty_business_service.go @@ -58,7 +58,7 @@ func dataSourcePagerDutyBusinessServiceRead(ctx context.Context, d *schema.Resou if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any business service with the name: %s", searchName), + fmt.Errorf("unable to locate any business service with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_escalation_policy.go b/pagerduty/data_source_pagerduty_escalation_policy.go index 7ee5dae9c..71b5cd5ed 100644 --- a/pagerduty/data_source_pagerduty_escalation_policy.go +++ b/pagerduty/data_source_pagerduty_escalation_policy.go @@ -58,7 +58,7 @@ func dataSourcePagerDutyEscalationPolicyRead(ctx context.Context, d *schema.Reso if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any escalation policy with the name: %s", searchName), + fmt.Errorf("unable to locate any escalation policy with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_event_orchestration.go b/pagerduty/data_source_pagerduty_event_orchestration.go index f7788fa9f..549d576d2 100644 --- a/pagerduty/data_source_pagerduty_event_orchestration.go +++ b/pagerduty/data_source_pagerduty_event_orchestration.go @@ -1,10 +1,12 @@ package pagerduty import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nordcloud/go-pagerduty/pagerduty" @@ -12,7 +14,7 @@ import ( func dataSourcePagerDutyEventOrchestration() *schema.Resource { return &schema.Resource{ - Read: dataSourcePagerDutyEventOrchestrationRead, + ReadContext: dataSourcePagerDutyEventOrchestrationRead, Schema: map[string]*schema.Schema{ "name": { @@ -56,20 +58,20 @@ func dataSourcePagerDutyEventOrchestration() *schema.Resource { } } -func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta interface{}) error { +func dataSourcePagerDutyEventOrchestrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).Client() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Reading PagerDuty Event Orchestration") searchName := d.Get("name").(string) - return resource.Retry(5*time.Minute, func() *resource.RetryError { + return diag.FromErr(resource.RetryContext(ctx, 10*time.Minute, func() *resource.RetryError { resp, _, err := client.EventOrchestrations.List() - if err != nil { - return resource.RetryableError(err) + if checkErr := handleGenericErrors(err, d); checkErr.ShouldReturn { + return checkErr.ReturnVal } var found *pagerduty.EventOrchestration @@ -83,7 +85,7 @@ func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta inte if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any Event Orchestration with the name: %s", searchName), + fmt.Errorf("unable to locate any Event Orchestration with the name: %s", searchName), ) } @@ -102,5 +104,5 @@ func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta inte } return nil - }) + })) } diff --git a/pagerduty/data_source_pagerduty_event_orchestration_integration.go b/pagerduty/data_source_pagerduty_event_orchestration_integration.go index 5a8b1577e..41aa6ddc6 100644 --- a/pagerduty/data_source_pagerduty_event_orchestration_integration.go +++ b/pagerduty/data_source_pagerduty_event_orchestration_integration.go @@ -56,7 +56,7 @@ func dataSourcePagerDutyEventOrchestrationIntegrationRead(ctx context.Context, d lbl := d.Get("label").(string) if id == "" && lbl == "" { - return diag.FromErr(fmt.Errorf("Invalid Event Orchestration Integration data source configuration: ID and label cannot both be null")) + return diag.FromErr(fmt.Errorf("invalid Event Orchestration Integration data source configuration: ID and label cannot both be null")) } oid := d.Get("event_orchestration").(string) @@ -142,13 +142,13 @@ func getEventOrchestrationIntegrationByLabel(ctx context.Context, d *schema.Reso if count == 0 { return resource.NonRetryableError( - fmt.Errorf("Unable to find an Integration on Event Orchestration '%s' with label '%s'", oid, lbl), + fmt.Errorf("unable to find an Integration on Event Orchestration '%s' with label '%s'", oid, lbl), ) } if count > 1 { return resource.NonRetryableError( - fmt.Errorf("Ambiguous Integration label: '%s'. Found %v Integrations with this label on Event Orchestration '%s'. Please use the Integration ID instead or make Integration labels unique within Event Orchestration.", lbl, count, oid), + fmt.Errorf("ambiguous Integration label: '%s'. Found %v Integrations with this label on Event Orchestration '%s'. Please use the Integration ID instead or make Integration labels unique within Event Orchestration", lbl, count, oid), ) } diff --git a/pagerduty/data_source_pagerduty_event_orchestrations.go b/pagerduty/data_source_pagerduty_event_orchestrations.go index 4151affd0..b78d725ce 100644 --- a/pagerduty/data_source_pagerduty_event_orchestrations.go +++ b/pagerduty/data_source_pagerduty_event_orchestrations.go @@ -104,7 +104,7 @@ func dataSourcePagerDutyEventOrchestrationsRead(d *schema.ResourceData, meta int } } if len(eoList) == 0 { - return resource.NonRetryableError(fmt.Errorf("Unable to locate any Event Orchestration matching the expression: %s", nameFilter)) + return resource.NonRetryableError(fmt.Errorf("unable to locate any Event Orchestration matching the expression: %s", nameFilter)) } return nil diff --git a/pagerduty/data_source_pagerduty_event_orchestrations_test.go b/pagerduty/data_source_pagerduty_event_orchestrations_test.go index 3d4e9215c..70c51dd9f 100644 --- a/pagerduty/data_source_pagerduty_event_orchestrations_test.go +++ b/pagerduty/data_source_pagerduty_event_orchestrations_test.go @@ -124,9 +124,9 @@ data "pagerduty_event_orchestrations" "not_found" { } func testAccDataSourcePagerDutyEventOrchestrationsInvalidRegexConfig() string { - return fmt.Sprintf(` + return ` data "pagerduty_event_orchestrations" "invalid_regex" { name_filter = ")" } -`) +` } diff --git a/pagerduty/data_source_pagerduty_extension_schema.go b/pagerduty/data_source_pagerduty_extension_schema.go index de8829cfb..2103f7d36 100644 --- a/pagerduty/data_source_pagerduty_extension_schema.go +++ b/pagerduty/data_source_pagerduty_extension_schema.go @@ -59,7 +59,7 @@ func dataSourcePagerDutyExtensionSchemaRead(ctx context.Context, d *schema.Resou if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any extension schema with the name: %s", searchName), + fmt.Errorf("unable to locate any extension schema with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_license.go b/pagerduty/data_source_pagerduty_license.go index 5c0a69fd3..f9fd23c17 100644 --- a/pagerduty/data_source_pagerduty_license.go +++ b/pagerduty/data_source_pagerduty_license.go @@ -1,12 +1,13 @@ package pagerduty import ( + "context" "fmt" "log" - "net/http" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nordcloud/go-pagerduty/pagerduty" @@ -75,30 +76,23 @@ var licenseSchema = map[string]*schema.Schema{ func dataSourcePagerDutyLicense() *schema.Resource { return &schema.Resource{ - Read: dataSourcePagerDutyLicenseRead, - Schema: licenseSchema, + ReadContext: dataSourcePagerDutyLicenseRead, + Schema: licenseSchema, } } -func dataSourcePagerDutyLicenseRead(d *schema.ResourceData, meta interface{}) error { +func dataSourcePagerDutyLicenseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).Client() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Fetching PagerDuty Licenses") - return resource.Retry(5*time.Minute, func() *resource.RetryError { + return diag.FromErr(resource.RetryContext(ctx, 10*time.Minute, func() *resource.RetryError { licenses, _, err := client.Licenses.List() - if err != nil { - if isErrCode(err, http.StatusBadRequest) { - return resource.NonRetryableError(err) - } - - // Delaying retry by 30s as recommended by PagerDuty - // https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit - time.Sleep(30 * time.Second) - return resource.RetryableError(err) + if checkErr := handleGenericErrors(err, d); checkErr.ShouldReturn { + return checkErr.ReturnVal } id, name, description := d.Get("id").(string), d.Get("name").(string), d.Get("description").(string) @@ -107,7 +101,7 @@ func dataSourcePagerDutyLicenseRead(d *schema.ResourceData, meta interface{}) er if found == nil { ids := licensesToStringOfIds(licenses) return resource.NonRetryableError( - fmt.Errorf("Unable to locate any license with ids in [%s] with the configured id: '%s', name: '%s' or description: '%s'", ids, id, name, description)) + fmt.Errorf("unable to locate any license with ids in [%s] with the configured id: '%s', name: '%s' or description: '%s'", ids, id, name, description)) } d.SetId(found.ID) @@ -123,7 +117,7 @@ func dataSourcePagerDutyLicenseRead(d *schema.ResourceData, meta interface{}) er d.Set("html_url", found.HTMLURL) return nil - }) + })) } func licensesToStringOfIds(licenses []*pagerduty.License) string { diff --git a/pagerduty/data_source_pagerduty_priority.go b/pagerduty/data_source_pagerduty_priority.go index c7aa262d7..452e4906e 100644 --- a/pagerduty/data_source_pagerduty_priority.go +++ b/pagerduty/data_source_pagerduty_priority.go @@ -60,7 +60,7 @@ func dataSourcePagerDutyPriorityRead(ctx context.Context, d *schema.ResourceData if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any priority with name: %s", searchTeam), + fmt.Errorf("unable to locate any priority with name: %s", searchTeam), ) } diff --git a/pagerduty/data_source_pagerduty_ruleset.go b/pagerduty/data_source_pagerduty_ruleset.go index f81addac1..18c6dc5bc 100644 --- a/pagerduty/data_source_pagerduty_ruleset.go +++ b/pagerduty/data_source_pagerduty_ruleset.go @@ -61,7 +61,7 @@ func dataSourcePagerDutyRulesetRead(ctx context.Context, d *schema.ResourceData, if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any ruleset with the name: %s", searchName), + fmt.Errorf("unable to locate any ruleset with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index 5ed8991ea..8c1f44c4a 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -58,7 +58,7 @@ func dataSourcePagerDutyScheduleRead(ctx context.Context, d *schema.ResourceData if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any schedule with the name: %s", searchName), + fmt.Errorf("unable to locate any schedule with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_service.go b/pagerduty/data_source_pagerduty_service.go index b6329ad18..947d21f04 100644 --- a/pagerduty/data_source_pagerduty_service.go +++ b/pagerduty/data_source_pagerduty_service.go @@ -99,7 +99,7 @@ func dataSourcePagerDutyServiceRead(ctx context.Context, d *schema.ResourceData, if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any service with the name: %s", searchName), + fmt.Errorf("unable to locate any service with the name: %s", searchName), ) } diff --git a/pagerduty/data_source_pagerduty_tag.go b/pagerduty/data_source_pagerduty_tag.go index 1258c64fc..f752d76d6 100644 --- a/pagerduty/data_source_pagerduty_tag.go +++ b/pagerduty/data_source_pagerduty_tag.go @@ -59,7 +59,7 @@ func dataSourcePagerDutyTagRead(ctx context.Context, d *schema.ResourceData, met if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any tag with label: %s", searchTag), + fmt.Errorf("unable to locate any tag with label: %s", searchTag), ) } diff --git a/pagerduty/data_source_pagerduty_team.go b/pagerduty/data_source_pagerduty_team.go index 546528e37..abfb0d389 100644 --- a/pagerduty/data_source_pagerduty_team.go +++ b/pagerduty/data_source_pagerduty_team.go @@ -71,7 +71,7 @@ func dataSourcePagerDutyTeamRead(ctx context.Context, d *schema.ResourceData, me if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any team with name: %s", searchTeam), + fmt.Errorf("unable to locate any team with name: %s", searchTeam), ) } diff --git a/pagerduty/data_source_pagerduty_user.go b/pagerduty/data_source_pagerduty_user.go index d39c9dcea..f440a013c 100644 --- a/pagerduty/data_source_pagerduty_user.go +++ b/pagerduty/data_source_pagerduty_user.go @@ -62,7 +62,7 @@ func dataSourcePagerDutyUserRead(ctx context.Context, d *schema.ResourceData, me if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any user with the email: %s", searchEmail), + fmt.Errorf("unable to locate any user with the email: %s", searchEmail), ) } diff --git a/pagerduty/data_source_pagerduty_user_contact_method.go b/pagerduty/data_source_pagerduty_user_contact_method.go index b804bcb4e..e59f324e9 100644 --- a/pagerduty/data_source_pagerduty_user_contact_method.go +++ b/pagerduty/data_source_pagerduty_user_contact_method.go @@ -91,7 +91,7 @@ func dataSourcePagerDutyUserContactMethodRead(ctx context.Context, d *schema.Res } if found == nil { - return resource.NonRetryableError(fmt.Errorf("Unable to locate any contact methods with the label: %s", searchLabel)) + return resource.NonRetryableError(fmt.Errorf("unable to locate any contact methods with the label: %s", searchLabel)) } d.SetId(found.ID) diff --git a/pagerduty/data_source_pagerduty_users.go b/pagerduty/data_source_pagerduty_users.go index 7a2fc41b5..2a7fd7161 100644 --- a/pagerduty/data_source_pagerduty_users.go +++ b/pagerduty/data_source_pagerduty_users.go @@ -1,10 +1,12 @@ package pagerduty import ( + "context" "log" "strconv" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nordcloud/go-pagerduty/pagerduty" @@ -12,7 +14,7 @@ import ( func dataSourcePagerDutyUsers() *schema.Resource { return &schema.Resource{ - Read: dataSourcePagerDutyUsersRead, + ReadContext: dataSourcePagerDutyUsersRead, Schema: map[string]*schema.Schema{ "team_ids": { @@ -47,10 +49,10 @@ func dataSourcePagerDutyUsers() *schema.Resource { } } -func dataSourcePagerDutyUsersRead(d *schema.ResourceData, meta interface{}) error { +func dataSourcePagerDutyUsersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).Client() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Reading PagerDuty users") @@ -65,13 +67,10 @@ func dataSourcePagerDutyUsersRead(d *schema.ResourceData, meta interface{}) erro TeamIDs: teamIds, } - return resource.Retry(5*time.Minute, func() *resource.RetryError { + return diag.FromErr(resource.RetryContext(ctx, 10*time.Minute, func() *resource.RetryError { resp, err := client.Users.ListAll(o) - if err != nil { - // Delaying retry by 30s as recommended by PagerDuty - // https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit - time.Sleep(30 * time.Second) - return resource.RetryableError(err) + if checkErr := handleGenericErrors(err, d); checkErr.ShouldReturn { + return checkErr.ReturnVal } var users []map[string]interface{} @@ -89,5 +88,5 @@ func dataSourcePagerDutyUsersRead(d *schema.ResourceData, meta interface{}) erro d.Set("users", users) return nil - }) + })) } diff --git a/pagerduty/data_source_pagerduty_vendor.go b/pagerduty/data_source_pagerduty_vendor.go index 8a5a87bd8..3738f33da 100644 --- a/pagerduty/data_source_pagerduty_vendor.go +++ b/pagerduty/data_source_pagerduty_vendor.go @@ -74,7 +74,7 @@ func dataSourcePagerDutyVendorRead(ctx context.Context, d *schema.ResourceData, if found == nil { return resource.NonRetryableError( - fmt.Errorf("Unable to locate any vendor with the name: %s", searchName), + fmt.Errorf("unable to locate any vendor with the name: %s", searchName), ) } diff --git a/pagerduty/event_orchestration_path_util.go b/pagerduty/event_orchestration_path_util.go index 487c66bec..fa9fc21bb 100644 --- a/pagerduty/event_orchestration_path_util.go +++ b/pagerduty/event_orchestration_path_util.go @@ -158,15 +158,15 @@ func checkExtractionAttributes(diff *schema.ResourceDiff, loc string) error { t := diff.Get(fmt.Sprintf("%s.template", prefix)).(string) if r == "" && t == "" { - return fmt.Errorf("Invalid configuration in %s: regex and template cannot both be null", prefix) + return fmt.Errorf("invalid configuration in %s: regex and template cannot both be null", prefix) } if r != "" && t != "" { - return fmt.Errorf("Invalid configuration in %s: regex and template cannot both have values", prefix) + return fmt.Errorf("invalid configuration in %s: regex and template cannot both have values", prefix) } s := diff.Get(fmt.Sprintf("%s.source", prefix)).(string) if r != "" && s == "" { - return fmt.Errorf("Invalid configuration in %s: source can't be blank", prefix) + return fmt.Errorf("invalid configuration in %s: source can't be blank", prefix) } } return nil diff --git a/pagerduty/provider.go b/pagerduty/provider.go index 4d57c7123..659a2fde7 100644 --- a/pagerduty/provider.go +++ b/pagerduty/provider.go @@ -293,7 +293,7 @@ func providerConfigureContextFunc(ctx context.Context, data *schema.ResourceData if err := validateAuthMethodConfig(data); err != nil { diag := diag.Diagnostic{ Severity: diag.Warning, - Summary: fmt.Sprint("`token` and `use_app_oauth_scoped_token` are both configured at the same time"), + Summary: "`token` and `use_app_oauth_scoped_token` are both configured at the same time", Detail: err.Error(), } diags = append(diags, diag) diff --git a/pagerduty/resource_pagerduty_event_orchestration_integration.go b/pagerduty/resource_pagerduty_event_orchestration_integration.go index b8d58afc3..8a7b4b457 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_integration.go +++ b/pagerduty/resource_pagerduty_event_orchestration_integration.go @@ -93,7 +93,7 @@ func fetchPagerDutyEventOrchestrationIntegration(ctx context.Context, d *schema. } else if integration != nil { lbl := d.Get("label").(string) if compareLabels && strings.Compare(integration.Label, lbl) != 0 { - return integration, fmt.Errorf("Integration '%s' for PagerDuty Event Orchestration '%s' error - stored label '%s' doesn't match resource label '%s'.", id, oid, integration.Label, lbl) + return integration, fmt.Errorf("integration '%s' for PagerDuty Event Orchestration '%s' error - stored label '%s' doesn't match resource label '%s'", id, oid, integration.Label, lbl) } else { d.SetId(id) d.Set("event_orchestration", oid) @@ -102,7 +102,7 @@ func fetchPagerDutyEventOrchestrationIntegration(ctx context.Context, d *schema. } } - return nil, fmt.Errorf("Reading Integration '%s' for PagerDuty Event Orchestration '%s' returned `nil`.", id, oid) + return nil, fmt.Errorf("reading Integration '%s' for PagerDuty Event Orchestration '%s' returned `nil`", id, oid) } func resourcePagerDutyEventOrchestrationIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -200,7 +200,7 @@ func resourcePagerDutyEventOrchestrationIntegrationUpdate(ctx context.Context, d // retry migration if the integration still exists on the source: if readSrcErr == nil && srcInt != nil { log.Printf("[WARN] Integration '%s' still exists on the source PagerDuty Event Orchestration '%s'. Retrying migration....", id, sourceOrchId) - return resource.RetryableError(fmt.Errorf("Integration '%s' still exists on the source PagerDuty Event Orchestration '%s'.", id, sourceOrchId)) + return resource.RetryableError(fmt.Errorf("integration '%s' still exists on the source PagerDuty Event Orchestration '%s'", id, sourceOrchId)) } } return nil @@ -264,7 +264,7 @@ func resourcePagerDutyEventOrchestrationIntegrationDelete(ctx context.Context, d // Try reading an integration after deletion, retry if still found: if integr, _, readErr := client.EventOrchestrationIntegrations.GetContext(ctx, oid, id); readErr == nil && integr != nil { log.Printf("[WARN] Integration '%s' still exists on PagerDuty Event Orchestration '%s'. Retrying deletion...", id, oid) - return resource.RetryableError(fmt.Errorf("Integration '%s' still exists on PagerDuty Event Orchestration '%s'.", id, oid)) + return resource.RetryableError(fmt.Errorf("integration '%s' still exists on PagerDuty Event Orchestration '%s'", id, oid)) } } return nil @@ -287,7 +287,7 @@ func resourcePagerDutyEventOrchestrationIntegrationImport(ctx context.Context, d } if oid == "" || id == "" { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_event_orchestration_integration. Expected import ID format: :") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_event_orchestration_integration. Expected import ID format: :") } retryErr := resource.RetryContext(ctx, 2*time.Minute, func() *resource.RetryError { diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_router.go b/pagerduty/resource_pagerduty_event_orchestration_path_router.go index 7af715920..49462906c 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_router.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_router.go @@ -212,7 +212,7 @@ func resourcePagerDutyEventOrchestrationPathRouterUpdate(ctx context.Context, d return resource.RetryableError(err) } if response == nil { - return resource.NonRetryableError(fmt.Errorf("No Event Orchestration Router found.")) + return resource.NonRetryableError(fmt.Errorf("no Event Orchestration Router found")) } d.SetId(routerPath.Parent.ID) d.Set("event_orchestration", routerPath.Parent.ID) diff --git a/pagerduty/resource_pagerduty_incident_workflow.go b/pagerduty/resource_pagerduty_incident_workflow.go index 2fb68a406..a10121165 100644 --- a/pagerduty/resource_pagerduty_incident_workflow.go +++ b/pagerduty/resource_pagerduty_incident_workflow.go @@ -287,9 +287,7 @@ func customizeIncidentWorkflowDiff() schema.CustomizeDiffFunc { // 6. Any remaining new inputs that were not already matched to old inputs should now be added to the result. // This lets new inputs that do not have default values (which are already cached as generated=true) maintain // their state in the diff, while not disrupting ordering of unchanged inputs. - for _, newInput := range newInputs { - result = append(result, newInput) - } + result = append(result, newInputs...) return result } diff --git a/pagerduty/resource_pagerduty_response_play.go b/pagerduty/resource_pagerduty_response_play.go index 526c0f171..10b68f31b 100644 --- a/pagerduty/resource_pagerduty_response_play.go +++ b/pagerduty/resource_pagerduty_response_play.go @@ -500,7 +500,7 @@ func resourcePagerDutyResponsePlayImport(ctx context.Context, d *schema.Resource ids := strings.SplitN(d.Id(), ".", 2) if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_response_play. Expecting an importation ID formed as '.'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_response_play. Expecting an importation ID formed as '.'") } rid, from := ids[0], ids[1] log.Printf("[INFO] Importing PagerDuty response play: %s (From: %s)", rid, from) diff --git a/pagerduty/resource_pagerduty_ruleset_rule.go b/pagerduty/resource_pagerduty_ruleset_rule.go index f80f88ec5..f38c1e4f5 100644 --- a/pagerduty/resource_pagerduty_ruleset_rule.go +++ b/pagerduty/resource_pagerduty_ruleset_rule.go @@ -881,9 +881,9 @@ func performRulesetRuleUpdate(ctx context.Context, rulesetID string, id string, } return resource.RetryableError(err) - } else if rule.Position != nil && *updatedRule.Position != *rule.Position && rule.CatchAll != true { + } else if rule.Position != nil && *updatedRule.Position != *rule.Position && !rule.CatchAll { log.Printf("[INFO] PagerDuty ruleset rule %s position %d needs to be %d", updatedRule.ID, *updatedRule.Position, *rule.Position) - return resource.RetryableError(fmt.Errorf("Error updating ruleset rule %s position %d needs to be %d", updatedRule.ID, *updatedRule.Position, *rule.Position)) + return resource.RetryableError(fmt.Errorf("error updating ruleset rule %s position %d needs to be %d", updatedRule.ID, *updatedRule.Position, *rule.Position)) } return nil }) @@ -963,7 +963,7 @@ func resourcePagerDutyRulesetRuleImport(ctx context.Context, d *schema.ResourceD ids := strings.Split(d.Id(), ".") if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_ruleset_rule. Expecting an importation ID formed as '.'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_ruleset_rule. Expecting an importation ID formed as '.'") } rulesetID, ruleID := ids[0], ids[1] diff --git a/pagerduty/resource_pagerduty_schedule.go b/pagerduty/resource_pagerduty_schedule.go index 1f3aa9eb4..ce49a3773 100644 --- a/pagerduty/resource_pagerduty_schedule.go +++ b/pagerduty/resource_pagerduty_schedule.go @@ -447,7 +447,7 @@ func resourcePagerDutyScheduleDelete(ctx context.Context, d *schema.ResourceData for _, incident := range linksToIncidentsOpen { urlLinksMessage = fmt.Sprintf("%s\n%s", urlLinksMessage, incident) } - return resource.NonRetryableError(fmt.Errorf("Before destroying Schedule %q You must first resolve or reassign the following incidents related with Escalation Policies using this Schedule... %s", scheduleId, urlLinksMessage)) + return resource.NonRetryableError(fmt.Errorf("before destroying Schedule %q You must first resolve or reassign the following incidents related with Escalation Policies using this Schedule... %s", scheduleId, urlLinksMessage)) } // Returning at this point because the open incident (s) blocking the @@ -826,18 +826,18 @@ func detectUseOfScheduleByEPsWithOneLayer(scheduleId string, eps []*pagerduty.Es // To cover the case when the Schedule is used by an Escalation Policy which // is not being managed by the same TF config which is managing this Schedule. if epState == nil { - return fmt.Errorf("It is not possible to continue with the destruction of the Schedule %q, because it is being used by Escalation Policy %q which has only one layer configured. Nevertheless, the mentioned Escalation Policy is not managed by this Terraform configuration. So in order to unblock this resource destruction, We suggest you to first make the appropiate changes on the Escalation Policy %s and come back for retrying.", scheduleId, ep.ID, ep.HTMLURL) + return fmt.Errorf("it is not possible to continue with the destruction of the Schedule %q, because it is being used by Escalation Policy %q which has only one layer configured. Nevertheless, the mentioned Escalation Policy is not managed by this Terraform configuration. So in order to unblock this resource destruction, We suggest you to first make the appropiate changes on the Escalation Policy %s and come back for retrying", scheduleId, ep.ID, ep.HTMLURL) } epsNames = append(epsNames, epState.Name) } - displayError := fmt.Errorf(`It is not possible to continue with the destruction of the Schedule %q, because it is being used by the Escalation Policy %[2]q which has only one layer configured. Therefore in order to unblock this resource destruction, We suggest you to first execute "terraform apply (or destroy, please act accordingly) -target=pagerduty_escalation_policy.%[2]s"`, scheduleId, epsNames[0]) + displayError := fmt.Errorf(`it is not possible to continue with the destruction of the Schedule %q, because it is being used by the Escalation Policy %[2]q which has only one layer configured. Therefore in order to unblock this resource destruction, We suggest you to first execute "terraform apply (or destroy, please act accordingly) -target=pagerduty_escalation_policy.%[2]s"`, scheduleId, epsNames[0]) if len(epsNames) > 1 { var epsListMessage string for _, ep := range epsNames { epsListMessage = fmt.Sprintf("%s\n%s", epsListMessage, ep) } - displayError = fmt.Errorf(`It is not possible to continue with the destruction of the Schedule %q, because it is being used by multiple Escalation Policies which have only one layer configured. Therefore in order to unblock this resource destruction, We suggest you to first execute "terraform apply (or destroy, please act accordingly) -target=pagerduty_escalation_policy.". e.g: "terraform apply -target=pagerduty_escalation_policy.example". Replacing the example name with the following Escalation Policies which are blocking the deletion of the Schedule...%s`, scheduleId, epsListMessage) + displayError = fmt.Errorf(`it is not possible to continue with the destruction of the Schedule %q, because it is being used by multiple Escalation Policies which have only one layer configured. Therefore in order to unblock this resource destruction, We suggest you to first execute "terraform apply (or destroy, please act accordingly) -target=pagerduty_escalation_policy.". e.g: "terraform apply -target=pagerduty_escalation_policy.example". Replacing the example name with the following Escalation Policies which are blocking the deletion of the Schedule...%s`, scheduleId, epsListMessage) } return displayError diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index f77017b29..63e1e151e 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -343,16 +343,16 @@ func customizePagerDutyServiceDiff(context context.Context, diff *schema.Resourc hasChangeAgpType := diff.HasChange("alert_grouping_parameters") if agpType == "content_based" && (aggregateVal == "" || len(fieldsVal) == 0) { - return fmt.Errorf("When using Alert grouping parameters configuration of type \"content_based\" is in use, attributes \"aggregate\" and \"fields\" are required") + return fmt.Errorf("when using Alert grouping parameters configuration of type \"content_based\" is in use, attributes \"aggregate\" and \"fields\" are required") } if (aggregateVal != "" || len(fieldsVal) > 0) && (agpType != "" && hasChangeAgpType && agpType != "content_based") { - return fmt.Errorf("Alert grouping parameters configuration attributes \"aggregate\" and \"fields\" are only supported by \"content_based\" type Alert Grouping") + return fmt.Errorf("alert grouping parameters configuration attributes \"aggregate\" and \"fields\" are only supported by \"content_based\" type Alert Grouping") } if timeoutVal > 0 && (agpType != "" && hasChangeAgpType && agpType != "time") { - return fmt.Errorf("Alert grouping parameters configuration attribute \"timeout\" is only supported by \"time\" type Alert Grouping") + return fmt.Errorf("alert grouping parameters configuration attribute \"timeout\" is only supported by \"time\" type Alert Grouping") } if (timeWindowVal > 300) && (agpType != "" && hasChangeAgpType && agpType != "intelligent") { - return fmt.Errorf("Alert grouping parameters configuration attribute \"time_window\" is only supported by \"intelligent\" type Alert Grouping") + return fmt.Errorf("alert grouping parameters configuration attribute \"time_window\" is only supported by \"intelligent\" type Alert Grouping") } } diff --git a/pagerduty/resource_pagerduty_service_dependency.go b/pagerduty/resource_pagerduty_service_dependency.go index 7ffc19629..6bbdf229e 100644 --- a/pagerduty/resource_pagerduty_service_dependency.go +++ b/pagerduty/resource_pagerduty_service_dependency.go @@ -117,8 +117,7 @@ func buildServiceDependencyStruct(d *schema.ResourceData) (*pagerduty.ServiceDep } func expandService(v interface{}) *pagerduty.ServiceObj { - var so *pagerduty.ServiceObj - so = new(pagerduty.ServiceObj) + so := new(pagerduty.ServiceObj) for _, s := range v.([]interface{}) { sm := s.(map[string]interface{}) @@ -356,7 +355,7 @@ func resourcePagerDutyServiceDependencyImport(ctx context.Context, d *schema.Res ids := strings.Split(d.Id(), ".") if len(ids) != 3 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_service_dependency. Expecting an importation ID formed as '..'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_service_dependency. Expecting an importation ID formed as '..'") } sid, st, id := ids[0], ids[1], ids[2] diff --git a/pagerduty/resource_pagerduty_service_event_rule.go b/pagerduty/resource_pagerduty_service_event_rule.go index 5311c0e39..5b1247e2e 100644 --- a/pagerduty/resource_pagerduty_service_event_rule.go +++ b/pagerduty/resource_pagerduty_service_event_rule.go @@ -426,7 +426,7 @@ func resourcePagerDutyServiceEventRuleUpdate(ctx context.Context, d *schema.Reso return resource.RetryableError(err) } else if rule.Position != nil && *updatedRule.Position != *rule.Position { log.Printf("[INFO] Service Event Rule %s position %v needs to be %v", updatedRule.ID, *updatedRule.Position, *rule.Position) - return resource.RetryableError(fmt.Errorf("Error updating service event rule %s position %d needs to be %d", updatedRule.ID, *updatedRule.Position, *rule.Position)) + return resource.RetryableError(fmt.Errorf("error updating service event rule %s position %d needs to be %d", updatedRule.ID, *updatedRule.Position, *rule.Position)) } return nil @@ -475,7 +475,7 @@ func resourcePagerDutyServiceEventRuleImport(ctx context.Context, d *schema.Reso ids := strings.Split(d.Id(), ".") if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_service_event_rule. Expecting an importation ID formed as '.'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_service_event_rule. Expecting an importation ID formed as '.'") } serviceID, ruleID := ids[0], ids[1] diff --git a/pagerduty/resource_pagerduty_service_integration.go b/pagerduty/resource_pagerduty_service_integration.go index e912601fa..cef77a784 100644 --- a/pagerduty/resource_pagerduty_service_integration.go +++ b/pagerduty/resource_pagerduty_service_integration.go @@ -800,7 +800,7 @@ func resourcePagerDutyServiceIntegrationImport(ctx context.Context, d *schema.Re ids := strings.Split(d.Id(), ".") if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_service_integration. Expecting an importation ID formed as '.'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_service_integration. Expecting an importation ID formed as '.'") } sid, id := ids[0], ids[1] diff --git a/pagerduty/resource_pagerduty_slack_connection.go b/pagerduty/resource_pagerduty_slack_connection.go index 20e5ff621..cdf1d64d1 100644 --- a/pagerduty/resource_pagerduty_slack_connection.go +++ b/pagerduty/resource_pagerduty_slack_connection.go @@ -219,9 +219,7 @@ func resourcePagerDutySlackConnectionDelete(ctx context.Context, d *schema.Resou func expandConnectionConfig(v interface{}) pagerduty.ConnectionConfig { c := v.([]interface{})[0].(map[string]interface{}) - var config pagerduty.ConnectionConfig - - config = pagerduty.ConnectionConfig{ + config := pagerduty.ConnectionConfig{ Events: expandConfigList(c["events"].([]interface{})), Priorities: expandStarWildcardConfig(expandConfigList(c["priorities"].([]interface{}))), Urgency: nil, @@ -298,7 +296,7 @@ func resourcePagerDutySlackConnectionImport(ctx context.Context, d *schema.Resou ids := strings.Split(d.Id(), ".") if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_slack_connection. Expecting an importation ID formed as '.'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_slack_connection. Expecting an importation ID formed as '.'") } workspaceID, connectionID := ids[0], ids[1] diff --git a/pagerduty/resource_pagerduty_tag_assignment.go b/pagerduty/resource_pagerduty_tag_assignment.go index e8508a5ce..960a1240c 100644 --- a/pagerduty/resource_pagerduty_tag_assignment.go +++ b/pagerduty/resource_pagerduty_tag_assignment.go @@ -180,7 +180,7 @@ func resourcePagerDutyTagAssignmentDelete(ctx context.Context, d *schema.Resourc func resourcePagerDutyTagAssignmentImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { ids := strings.Split(d.Id(), ".") if len(ids) != 3 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_tag_assignment. Expecting an importation ID formed as '..'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_tag_assignment. Expecting an importation ID formed as '..'") } entityType, entityID, tagID := ids[0], ids[1], ids[2] diff --git a/pagerduty/resource_pagerduty_user_contact_method.go b/pagerduty/resource_pagerduty_user_contact_method.go index ed6420676..d80ec39d5 100644 --- a/pagerduty/resource_pagerduty_user_contact_method.go +++ b/pagerduty/resource_pagerduty_user_contact_method.go @@ -97,7 +97,7 @@ func customizeDiffResourceUserContactMethod(context context.Context, diff *schem isMexicoNumber := c == 52 if t == "sms_contact_method" && isMexicoNumber && strings.HasPrefix(a, "1") { - return fmt.Errorf("Mexico-based SMS numbers should be free of area code prefixes, so please remove the leading 1 in the number %q", a) + return fmt.Errorf("mexico-based SMS numbers should be free of area code prefixes, so please remove the leading 1 in the number %q", a) } isTrunkPrefixNotSupported := map[int]string{ @@ -112,7 +112,7 @@ func customizeDiffResourceUserContactMethod(context context.Context, diff *schem 1: "1", // North America (1-1) } if prefix, ok := isTrunkPrefixNotSupported[c]; ok && strings.HasPrefix(a, prefix) { - return fmt.Errorf("Trunk prefixes are not supported for following countries and regions: France, Romania, UK, Denmark, Germany, Australia, Thailand, India and North America, so must be formatted for international use without the leading %s", prefix) + return fmt.Errorf("trunk prefixes are not supported for following countries and regions: France, Romania, UK, Denmark, Germany, Australia, Thailand, India and North America, so must be formatted for international use without the leading %s", prefix) } } return nil @@ -241,7 +241,7 @@ func resourcePagerDutyUserContactMethodImport(ctx context.Context, d *schema.Res ids := strings.Split(d.Id(), ":") if len(ids) != 2 { - return []*schema.ResourceData{}, fmt.Errorf("Error importing pagerduty_user_contact_method. Expecting an ID formed as ':'") + return []*schema.ResourceData{}, fmt.Errorf("error importing pagerduty_user_contact_method. Expecting an ID formed as ':'") } uid, id := ids[0], ids[1] diff --git a/pagerduty/resource_pagerduty_webhook_subscription.go b/pagerduty/resource_pagerduty_webhook_subscription.go index 458a2180b..3f3132ad9 100644 --- a/pagerduty/resource_pagerduty_webhook_subscription.go +++ b/pagerduty/resource_pagerduty_webhook_subscription.go @@ -61,10 +61,7 @@ func resourcePagerDutyWebhookSubscription() *schema.Resource { ForceNew: true, // Suppress the diff shown if the base_image name are equal when both compared in lower case. DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - if old == "-- redacted --" { - return true - } - return false + return old == "-- redacted --" }, }, }, @@ -255,9 +252,7 @@ func expandDeliveryMethod(v interface{}) pagerduty.DeliveryMethod { func expandFilter(v interface{}) pagerduty.Filter { filterMap := v.([]interface{})[0].(map[string]interface{}) - var filter pagerduty.Filter - - filter = pagerduty.Filter{ + filter := pagerduty.Filter{ ID: filterMap["id"].(string), Type: filterMap["type"].(string), } diff --git a/pagerduty/util.go b/pagerduty/util.go index 4668ec01f..e0f0a0b22 100644 --- a/pagerduty/util.go +++ b/pagerduty/util.go @@ -45,7 +45,7 @@ func genErrorTimeFormatRFC339(value, k string) error { func suppressRFC3339Diff(k, oldTime, newTime string, d *schema.ResourceData) bool { oldT, newT, err := parseRFC3339Time(k, oldTime, newTime) if err != nil { - log.Printf(err.Error()) + log.Println(err.Error()) return false } @@ -59,7 +59,7 @@ func suppressRFC3339Diff(k, oldTime, newTime string, d *schema.ResourceData) boo func suppressScheduleLayerStartDiff(k, oldTime, newTime string, d *schema.ResourceData) bool { oldT, newT, err := parseRFC3339Time(k, oldTime, newTime) if err != nil { - log.Printf(err.Error()) + log.Println(err.Error()) return false }