diff --git a/pagerduty/config.go b/pagerduty/config.go index c908ad5a3..eab36d82e 100644 --- a/pagerduty/config.go +++ b/pagerduty/config.go @@ -11,9 +11,18 @@ import ( // Config defines the configuration options for the PagerDuty client type Config struct { + // The PagerDuty API URL + ApiUrl string + + // The PagerDuty APP URL + AppUrl string + // The PagerDuty API V2 token Token string + // The PagerDuty User level token for Slack + UserToken string + // Skip validation of the token against the PagerDuty API SkipCredsValidation bool @@ -40,6 +49,7 @@ func (c *Config) Client() (*pagerduty.Client, error) { httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport) config := &pagerduty.Config{ + BaseURL: c.ApiUrl, Debug: logging.IsDebugOrHigher(), HTTPClient: httpClient, Token: c.Token, @@ -63,3 +73,31 @@ func (c *Config) Client() (*pagerduty.Client, error) { return client, nil } + +func (c *Config) SlackClient() (*pagerduty.Client, error) { + // Validate that the user level PagerDuty token is set + if c.UserToken == "" { + return nil, fmt.Errorf(invalidCreds) + } + + var httpClient *http.Client + httpClient = http.DefaultClient + httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport) + + config := &pagerduty.Config{ + BaseURL: c.AppUrl, + Debug: logging.IsDebugOrHigher(), + HTTPClient: httpClient, + Token: c.UserToken, + UserAgent: c.UserAgent, + } + + client, err := pagerduty.NewClient(config) + if err != nil { + return nil, err + } + + log.Printf("[INFO] PagerDuty client configured for slack") + + return client, nil +} diff --git a/pagerduty/config_test.go b/pagerduty/config_test.go index 4f43d736c..ec3456b4b 100644 --- a/pagerduty/config_test.go +++ b/pagerduty/config_test.go @@ -26,3 +26,29 @@ func TestConfigSkipCredsValidation(t *testing.T) { t.Fatalf("error: expected the client to not fail: %v", err) } } + +// Test config with a custom ApiUrl +func TestConfigCustomApiUrl(t *testing.T) { + config := Config{ + Token: "foo", + ApiUrl: "https://api.domain.tld", + SkipCredsValidation: true, + } + + if _, err := config.Client(); err != nil { + t.Fatalf("error: expected the client to not fail: %v", err) + } +} + +// Test config with a custom AppUrl +func TestConfigCustomAppUrl(t *testing.T) { + config := Config{ + Token: "foo", + AppUrl: "https://app.domain.tld", + SkipCredsValidation: true, + } + + if _, err := config.Client(); err != nil { + t.Fatalf("error: expected the client to not fail: %v", err) + } +} diff --git a/pagerduty/data_source_pagerduty_business_service.go b/pagerduty/data_source_pagerduty_business_service.go index e5a856837..3c6ff0879 100644 --- a/pagerduty/data_source_pagerduty_business_service.go +++ b/pagerduty/data_source_pagerduty_business_service.go @@ -24,7 +24,7 @@ func dataSourcePagerDutyBusinessService() *schema.Resource { } func dataSourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty business service") diff --git a/pagerduty/data_source_pagerduty_escalation_policy.go b/pagerduty/data_source_pagerduty_escalation_policy.go index 773668c2f..273b2b02d 100644 --- a/pagerduty/data_source_pagerduty_escalation_policy.go +++ b/pagerduty/data_source_pagerduty_escalation_policy.go @@ -24,7 +24,7 @@ func dataSourcePagerDutyEscalationPolicy() *schema.Resource { } func dataSourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty escalation policy") diff --git a/pagerduty/data_source_pagerduty_extension_schema.go b/pagerduty/data_source_pagerduty_extension_schema.go index b58e32e54..4c2ed379a 100644 --- a/pagerduty/data_source_pagerduty_extension_schema.go +++ b/pagerduty/data_source_pagerduty_extension_schema.go @@ -29,7 +29,7 @@ func dataSourcePagerDutyExtensionSchema() *schema.Resource { } func dataSourcePagerDutyExtensionSchemaRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty Extension Schema") diff --git a/pagerduty/data_source_pagerduty_priority.go b/pagerduty/data_source_pagerduty_priority.go index db1a0ed52..36d3066b0 100644 --- a/pagerduty/data_source_pagerduty_priority.go +++ b/pagerduty/data_source_pagerduty_priority.go @@ -30,7 +30,7 @@ func dataSourcePagerDutyPriority() *schema.Resource { } func dataSourcePagerDutyPriorityRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty priority") diff --git a/pagerduty/data_source_pagerduty_ruleset.go b/pagerduty/data_source_pagerduty_ruleset.go index 6f41cf7b1..6396e1a91 100644 --- a/pagerduty/data_source_pagerduty_ruleset.go +++ b/pagerduty/data_source_pagerduty_ruleset.go @@ -31,7 +31,7 @@ func dataSourcePagerDutyRuleset() *schema.Resource { } func dataSourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty ruleset") diff --git a/pagerduty/data_source_pagerduty_schedule.go b/pagerduty/data_source_pagerduty_schedule.go index d7b846107..d4ead0151 100644 --- a/pagerduty/data_source_pagerduty_schedule.go +++ b/pagerduty/data_source_pagerduty_schedule.go @@ -24,7 +24,7 @@ func dataSourcePagerDutySchedule() *schema.Resource { } func dataSourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty schedule") diff --git a/pagerduty/data_source_pagerduty_service.go b/pagerduty/data_source_pagerduty_service.go index bbec99f99..98fc46265 100644 --- a/pagerduty/data_source_pagerduty_service.go +++ b/pagerduty/data_source_pagerduty_service.go @@ -24,7 +24,7 @@ func dataSourcePagerDutyService() *schema.Resource { } func dataSourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty service") diff --git a/pagerduty/data_source_pagerduty_service_integration.go b/pagerduty/data_source_pagerduty_service_integration.go index 11a4e29f2..c1634ce5d 100644 --- a/pagerduty/data_source_pagerduty_service_integration.go +++ b/pagerduty/data_source_pagerduty_service_integration.go @@ -36,7 +36,7 @@ func dataSourcePagerDutyServiceIntegration() *schema.Resource { } func dataSourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty service") diff --git a/pagerduty/data_source_pagerduty_tag.go b/pagerduty/data_source_pagerduty_tag.go index 7a9b31bc2..d0affd0ba 100644 --- a/pagerduty/data_source_pagerduty_tag.go +++ b/pagerduty/data_source_pagerduty_tag.go @@ -25,7 +25,7 @@ func dataSourcePagerDutyTag() *schema.Resource { } func dataSourcePagerDutyTagRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty tag") diff --git a/pagerduty/data_source_pagerduty_team.go b/pagerduty/data_source_pagerduty_team.go index 4bed84df0..d55f023b8 100644 --- a/pagerduty/data_source_pagerduty_team.go +++ b/pagerduty/data_source_pagerduty_team.go @@ -33,7 +33,7 @@ func dataSourcePagerDutyTeam() *schema.Resource { } func dataSourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty team") diff --git a/pagerduty/data_source_pagerduty_user.go b/pagerduty/data_source_pagerduty_user.go index 6780b1809..8e6649539 100644 --- a/pagerduty/data_source_pagerduty_user.go +++ b/pagerduty/data_source_pagerduty_user.go @@ -28,7 +28,7 @@ func dataSourcePagerDutyUser() *schema.Resource { } func dataSourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty user") diff --git a/pagerduty/data_source_pagerduty_user_contact_method.go b/pagerduty/data_source_pagerduty_user_contact_method.go index c40579d6e..ba0a3a764 100644 --- a/pagerduty/data_source_pagerduty_user_contact_method.go +++ b/pagerduty/data_source_pagerduty_user_contact_method.go @@ -59,7 +59,7 @@ func dataSourcePagerDutyUserContactMethod() *schema.Resource { } func dataSourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty user's contact method") diff --git a/pagerduty/data_source_pagerduty_vendor.go b/pagerduty/data_source_pagerduty_vendor.go index 9a9e0f3b5..a77dc835e 100644 --- a/pagerduty/data_source_pagerduty_vendor.go +++ b/pagerduty/data_source_pagerduty_vendor.go @@ -30,7 +30,7 @@ func dataSourcePagerDutyVendor() *schema.Resource { } func dataSourcePagerDutyVendorRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty vendor") diff --git a/pagerduty/provider.go b/pagerduty/provider.go index 5f9f8cd07..43c996f30 100644 --- a/pagerduty/provider.go +++ b/pagerduty/provider.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "runtime" + "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/heimweh/go-pagerduty/pagerduty" @@ -24,6 +25,18 @@ func Provider() *schema.Provider { Required: true, DefaultFunc: schema.EnvDefaultFunc("PAGERDUTY_TOKEN", nil), }, + + "user_token": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("PAGERDUTY_USER_TOKEN", nil), + }, + + "service_region": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, }, DataSourcesMap: map[string]*schema.Resource{ @@ -101,12 +114,23 @@ func handleNotFoundError(err error, d *schema.ResourceData) error { } func providerConfigure(data *schema.ResourceData, terraformVersion string) (interface{}, error) { + var ServiceRegion = strings.ToLower(data.Get("service_region").(string)) + + if ServiceRegion == "us" || ServiceRegion == "" { + ServiceRegion = "" + } else { + ServiceRegion = ServiceRegion + "." + } + config := Config{ + ApiUrl: "https://api." + ServiceRegion + "pagerduty.com", + AppUrl: "https://app." + ServiceRegion + "pagerduty.com", SkipCredsValidation: data.Get("skip_credentials_validation").(bool), Token: data.Get("token").(string), + UserToken: data.Get("user_token").(string), UserAgent: fmt.Sprintf("(%s %s) Terraform/%s", runtime.GOOS, runtime.GOARCH, terraformVersion), } log.Println("[INFO] Initializing PagerDuty client") - return config.Client() + return &config, nil } diff --git a/pagerduty/provider_test.go b/pagerduty/provider_test.go index 21f4d34f5..eea93e062 100644 --- a/pagerduty/provider_test.go +++ b/pagerduty/provider_test.go @@ -37,6 +37,10 @@ func testAccPreCheck(t *testing.T) { if v := os.Getenv("PAGERDUTY_TOKEN"); v == "" { t.Fatal("PAGERDUTY_TOKEN must be set for acceptance tests") } + + if v := os.Getenv("PAGERDUTY_USER_TOKEN"); v == "" { + t.Fatal("PAGERDUTY_USER_TOKEN must be set for acceptance tests") + } } // timeNowInLoc returns the current time in the given location. @@ -68,9 +72,13 @@ func testAccPreCheckPagerDutyAbility(t *testing.T, ability string) { if v := os.Getenv("PAGERDUTY_TOKEN"); v == "" { t.Fatal("PAGERDUTY_TOKEN must be set for acceptance tests") } + if v := os.Getenv("PAGERDUTY_USER_TOKEN"); v == "" { + t.Fatal("PAGERDUTY_USER_TOKEN must be set for acceptance tests") + } config := &Config{ - Token: os.Getenv("PAGERDUTY_TOKEN"), + Token: os.Getenv("PAGERDUTY_TOKEN"), + UserToken: os.Getenv("PAGERDUTY_USER_TOKEN"), } client, err := config.Client() diff --git a/pagerduty/resource_pagerduty_addon.go b/pagerduty/resource_pagerduty_addon.go index 05c4580a1..9ae0e0225 100644 --- a/pagerduty/resource_pagerduty_addon.go +++ b/pagerduty/resource_pagerduty_addon.go @@ -42,7 +42,7 @@ func buildAddonStruct(d *schema.ResourceData) *pagerduty.Addon { } func resourcePagerDutyAddonCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() addon := buildAddonStruct(d) @@ -59,7 +59,7 @@ func resourcePagerDutyAddonCreate(d *schema.ResourceData, meta interface{}) erro } func resourcePagerDutyAddonRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty add-on %s", d.Id()) @@ -83,7 +83,7 @@ func resourcePagerDutyAddonRead(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyAddonUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() addon := buildAddonStruct(d) @@ -97,7 +97,7 @@ func resourcePagerDutyAddonUpdate(d *schema.ResourceData, meta interface{}) erro } func resourcePagerDutyAddonDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty add-on %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_addon_test.go b/pagerduty/resource_pagerduty_addon_test.go index 2f91c9bc7..e8c76a49a 100644 --- a/pagerduty/resource_pagerduty_addon_test.go +++ b/pagerduty/resource_pagerduty_addon_test.go @@ -81,7 +81,7 @@ func TestAccPagerDutyAddon_Basic(t *testing.T) { } func testAccCheckPagerDutyAddonDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_addon" { continue @@ -106,7 +106,7 @@ func testAccCheckPagerDutyAddonExists(n string) resource.TestCheckFunc { return fmt.Errorf("No add-on ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Addons.Get(rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_business_service.go b/pagerduty/resource_pagerduty_business_service.go index 68750daa7..6a46e909b 100644 --- a/pagerduty/resource_pagerduty_business_service.go +++ b/pagerduty/resource_pagerduty_business_service.go @@ -93,7 +93,7 @@ func buildBusinessServiceStruct(d *schema.ResourceData) (*pagerduty.BusinessServ } func resourcePagerDutyBusinessServiceCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() retryErr := resource.Retry(2*time.Minute, func() *resource.RetryError { @@ -118,7 +118,7 @@ func resourcePagerDutyBusinessServiceCreate(d *schema.ResourceData, meta interfa } func resourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty business service %s", d.Id()) @@ -149,7 +149,7 @@ func resourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interface } func resourcePagerDutyBusinessServiceUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() businessService, err := buildBusinessServiceStruct(d) if err != nil { @@ -168,7 +168,7 @@ func resourcePagerDutyBusinessServiceUpdate(d *schema.ResourceData, meta interfa } func resourcePagerDutyBusinessServiceDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty business service %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_business_service_test.go b/pagerduty/resource_pagerduty_business_service_test.go index 899c9c0e0..3d1121d66 100644 --- a/pagerduty/resource_pagerduty_business_service_test.go +++ b/pagerduty/resource_pagerduty_business_service_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func init() { @@ -132,7 +131,7 @@ func testAccCheckPagerDutyBusinessServiceExists(n string) resource.TestCheckFunc return fmt.Errorf("No Business Service ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.BusinessServices.Get(rs.Primary.ID) if err != nil { @@ -148,7 +147,7 @@ func testAccCheckPagerDutyBusinessServiceExists(n string) resource.TestCheckFunc } func testAccCheckPagerDutyBusinessServiceDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_business_service" { continue diff --git a/pagerduty/resource_pagerduty_escalation_policy.go b/pagerduty/resource_pagerduty_escalation_policy.go index 605ba8b03..9e1e7ceef 100644 --- a/pagerduty/resource_pagerduty_escalation_policy.go +++ b/pagerduty/resource_pagerduty_escalation_policy.go @@ -102,7 +102,7 @@ func buildEscalationPolicyStruct(d *schema.ResourceData) *pagerduty.EscalationPo } func resourcePagerDutyEscalationPolicyCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() escalationPolicy := buildEscalationPolicyStruct(d) @@ -119,7 +119,7 @@ func resourcePagerDutyEscalationPolicyCreate(d *schema.ResourceData, meta interf } func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty escalation policy: %s", d.Id()) @@ -149,7 +149,7 @@ func resourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interfac } func resourcePagerDutyEscalationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() escalationPolicy := buildEscalationPolicyStruct(d) @@ -170,7 +170,7 @@ func resourcePagerDutyEscalationPolicyUpdate(d *schema.ResourceData, meta interf } func resourcePagerDutyEscalationPolicyDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty escalation policy: %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_escalation_policy_test.go b/pagerduty/resource_pagerduty_escalation_policy_test.go index c5b6a9e35..a1de0b0c2 100644 --- a/pagerduty/resource_pagerduty_escalation_policy_test.go +++ b/pagerduty/resource_pagerduty_escalation_policy_test.go @@ -155,7 +155,7 @@ func TestAccPagerDutyEscalationPolicyWithTeams_Basic(t *testing.T) { } func testAccCheckPagerDutyEscalationPolicyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_escalation_policy" { continue @@ -179,7 +179,7 @@ func testAccCheckPagerDutyEscalationPolicyExists(n string) resource.TestCheckFun return fmt.Errorf("No Escalation Policy ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.EscalationPolicies.Get(rs.Primary.ID, &pagerduty.GetEscalationPolicyOptions{}) if err != nil { diff --git a/pagerduty/resource_pagerduty_event_rule.go b/pagerduty/resource_pagerduty_event_rule.go index cd91a76f6..146fab889 100644 --- a/pagerduty/resource_pagerduty_event_rule.go +++ b/pagerduty/resource_pagerduty_event_rule.go @@ -57,7 +57,7 @@ func buildEventRuleStruct(d *schema.ResourceData) *pagerduty.EventRule { } func resourcePagerDutyEventRuleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() eventRule := buildEventRuleStruct(d) @@ -79,7 +79,7 @@ func resourcePagerDutyEventRuleCreate(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyEventRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty event rule: %s", d.Id()) @@ -114,7 +114,7 @@ func resourcePagerDutyEventRuleRead(d *schema.ResourceData, meta interface{}) er }) } func resourcePagerDutyEventRuleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() eventRule := buildEventRuleStruct(d) @@ -128,7 +128,7 @@ func resourcePagerDutyEventRuleUpdate(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyEventRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty event rule: %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_event_rule_test.go b/pagerduty/resource_pagerduty_event_rule_test.go index ea804d619..013c10d8c 100644 --- a/pagerduty/resource_pagerduty_event_rule_test.go +++ b/pagerduty/resource_pagerduty_event_rule_test.go @@ -75,7 +75,7 @@ func TestAccPagerDutyEventRule_Basic(t *testing.T) { } func testAccCheckPagerDutyEventRuleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_event_rule" { continue @@ -104,7 +104,7 @@ func testAccCheckPagerDutyEventRuleExists(n string) resource.TestCheckFunc { return fmt.Errorf("No Event Rule ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() resp, _, err := client.EventRules.List() if err != nil { return err diff --git a/pagerduty/resource_pagerduty_extension.go b/pagerduty/resource_pagerduty_extension.go index b9529589b..77935772c 100644 --- a/pagerduty/resource_pagerduty_extension.go +++ b/pagerduty/resource_pagerduty_extension.go @@ -87,7 +87,7 @@ func buildExtensionStruct(d *schema.ResourceData) *pagerduty.Extension { } func resourcePagerDutyExtensionCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension := buildExtensionStruct(d) @@ -104,7 +104,7 @@ func resourcePagerDutyExtensionCreate(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyExtensionRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty extension %s", d.Id()) @@ -138,7 +138,7 @@ func resourcePagerDutyExtensionRead(d *schema.ResourceData, meta interface{}) er } func resourcePagerDutyExtensionUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension := buildExtensionStruct(d) @@ -152,7 +152,7 @@ func resourcePagerDutyExtensionUpdate(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyExtensionDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty extension %s", d.Id()) @@ -170,7 +170,7 @@ func resourcePagerDutyExtensionDelete(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyExtensionImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension, _, err := client.Extensions.Get(d.Id()) diff --git a/pagerduty/resource_pagerduty_extension_servicenow.go b/pagerduty/resource_pagerduty_extension_servicenow.go index b166f7579..9dec22b61 100644 --- a/pagerduty/resource_pagerduty_extension_servicenow.go +++ b/pagerduty/resource_pagerduty_extension_servicenow.go @@ -122,7 +122,7 @@ func buildExtensionServiceNowStruct(d *schema.ResourceData) *pagerduty.Extension } func resourcePagerDutyExtensionServiceNowCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension := buildExtensionServiceNowStruct(d) @@ -139,7 +139,7 @@ func resourcePagerDutyExtensionServiceNowCreate(d *schema.ResourceData, meta int } func resourcePagerDutyExtensionServiceNowRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty extension %s", d.Id()) @@ -179,7 +179,7 @@ func resourcePagerDutyExtensionServiceNowRead(d *schema.ResourceData, meta inter } func resourcePagerDutyExtensionServiceNowUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension := buildExtensionServiceNowStruct(d) @@ -193,7 +193,7 @@ func resourcePagerDutyExtensionServiceNowUpdate(d *schema.ResourceData, meta int } func resourcePagerDutyExtensionServiceNowDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty extension %s", d.Id()) @@ -211,7 +211,7 @@ func resourcePagerDutyExtensionServiceNowDelete(d *schema.ResourceData, meta int } func resourcePagerDutyExtensionServiceNowImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() extension, _, err := client.Extensions.Get(d.Id()) diff --git a/pagerduty/resource_pagerduty_extension_servicenow_test.go b/pagerduty/resource_pagerduty_extension_servicenow_test.go index e466aa33a..54d0af74e 100644 --- a/pagerduty/resource_pagerduty_extension_servicenow_test.go +++ b/pagerduty/resource_pagerduty_extension_servicenow_test.go @@ -115,7 +115,7 @@ func TestAccPagerDutyExtensionServiceNow_Basic(t *testing.T) { } func testAccCheckPagerDutyExtensionServiceNowDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_extension_servicenow" { continue @@ -140,7 +140,7 @@ func testAccCheckPagerDutyExtensionServiceNowExists(n string) resource.TestCheck return fmt.Errorf("No extension ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Extensions.Get(rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_extension_test.go b/pagerduty/resource_pagerduty_extension_test.go index 79899e709..cb6442a5a 100644 --- a/pagerduty/resource_pagerduty_extension_test.go +++ b/pagerduty/resource_pagerduty_extension_test.go @@ -93,7 +93,7 @@ func TestAccPagerDutyExtension_Basic(t *testing.T) { } func testAccCheckPagerDutyExtensionDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_extension" { continue @@ -118,7 +118,7 @@ func testAccCheckPagerDutyExtensionExists(n string) resource.TestCheckFunc { return fmt.Errorf("No extension ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Extensions.Get(rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_maintenance_window.go b/pagerduty/resource_pagerduty_maintenance_window.go index 175e9266f..43d468f91 100644 --- a/pagerduty/resource_pagerduty_maintenance_window.go +++ b/pagerduty/resource_pagerduty_maintenance_window.go @@ -63,7 +63,7 @@ func buildMaintenanceWindowStruct(d *schema.ResourceData) *pagerduty.Maintenance } func resourcePagerDutyMaintenanceWindowCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() window := buildMaintenanceWindowStruct(d) @@ -80,7 +80,7 @@ func resourcePagerDutyMaintenanceWindowCreate(d *schema.ResourceData, meta inter } func resourcePagerDutyMaintenanceWindowRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty maintenance window %s", d.Id()) @@ -109,7 +109,7 @@ func resourcePagerDutyMaintenanceWindowRead(d *schema.ResourceData, meta interfa } func resourcePagerDutyMaintenanceWindowUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() window := buildMaintenanceWindowStruct(d) @@ -123,7 +123,7 @@ func resourcePagerDutyMaintenanceWindowUpdate(d *schema.ResourceData, meta inter } func resourcePagerDutyMaintenanceWindowDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty maintenance window %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_maintenance_window_test.go b/pagerduty/resource_pagerduty_maintenance_window_test.go index 6c17976ad..79e3d23b0 100644 --- a/pagerduty/resource_pagerduty_maintenance_window_test.go +++ b/pagerduty/resource_pagerduty_maintenance_window_test.go @@ -71,7 +71,7 @@ func TestAccPagerDutyMaintenanceWindow_Basic(t *testing.T) { } func testAccCheckPagerDutyMaintenanceWindowDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_maintenance_window" { continue @@ -96,7 +96,7 @@ func testAccCheckPagerDutyMaintenanceWindowExists(n string) resource.TestCheckFu return fmt.Errorf("No maintenance window ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.MaintenanceWindows.Get(rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_response_play.go b/pagerduty/resource_pagerduty_response_play.go index 27c1430b1..af6296538 100644 --- a/pagerduty/resource_pagerduty_response_play.go +++ b/pagerduty/resource_pagerduty_response_play.go @@ -227,7 +227,7 @@ func buildResponsePlayStruct(d *schema.ResourceData) *pagerduty.ResponsePlay { } func resourcePagerDutyResponsePlayCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() responsePlay := buildResponsePlayStruct(d) @@ -251,7 +251,7 @@ func resourcePagerDutyResponsePlayCreate(d *schema.ResourceData, meta interface{ } func resourcePagerDutyResponsePlayRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() from := d.Get("from").(string) log.Printf("[INFO] Reading PagerDuty response play: %s (from: %s)", d.Id(), from) @@ -288,7 +288,7 @@ func resourcePagerDutyResponsePlayRead(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyResponsePlayUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() responsePlay := buildResponsePlayStruct(d) @@ -308,7 +308,7 @@ func resourcePagerDutyResponsePlayUpdate(d *schema.ResourceData, meta interface{ } func resourcePagerDutyResponsePlayDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty response play: %s", d.Id()) from := d.Get("from").(string) @@ -461,7 +461,7 @@ func flattenRSTeams(teams []*pagerduty.TeamReference) []interface{} { } func resourcePagerDutyResponsePlayImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.SplitN(d.Id(), ".", 2) diff --git a/pagerduty/resource_pagerduty_response_play_test.go b/pagerduty/resource_pagerduty_response_play_test.go index 3e064d52a..003a32c77 100644 --- a/pagerduty/resource_pagerduty_response_play_test.go +++ b/pagerduty/resource_pagerduty_response_play_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyResponsePlay_Basic(t *testing.T) { @@ -49,7 +48,7 @@ func TestAccPagerDutyResponsePlay_Basic(t *testing.T) { } func testAccCheckPagerDutyResponsePlayDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_response_play" { continue @@ -78,7 +77,7 @@ func testAccCheckPagerDutyResponsePlayExists(n string) resource.TestCheckFunc { u, _ := s.RootModule().Resources["pagerduty_user.foo"] ua := u.Primary.Attributes - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.ResponsePlays.Get(rs.Primary.ID, ua["email"]) if err != nil { diff --git a/pagerduty/resource_pagerduty_ruleset.go b/pagerduty/resource_pagerduty_ruleset.go index b126d3281..55fdc1f36 100644 --- a/pagerduty/resource_pagerduty_ruleset.go +++ b/pagerduty/resource_pagerduty_ruleset.go @@ -100,7 +100,7 @@ func flattenTeam(v *pagerduty.RulesetObject) []interface{} { return []interface{}{team} } func resourcePagerDutyRulesetCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ruleset := buildRulesetStruct(d) @@ -127,7 +127,7 @@ func resourcePagerDutyRulesetCreate(d *schema.ResourceData, meta interface{}) er } func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty ruleset: %s", d.Id()) @@ -155,7 +155,7 @@ func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) erro }) } func resourcePagerDutyRulesetUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ruleset := buildRulesetStruct(d) @@ -169,7 +169,7 @@ func resourcePagerDutyRulesetUpdate(d *schema.ResourceData, meta interface{}) er } func resourcePagerDutyRulesetDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty ruleset: %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_ruleset_rule.go b/pagerduty/resource_pagerduty_ruleset_rule.go index 0c341f6dc..74ceccdb3 100644 --- a/pagerduty/resource_pagerduty_ruleset_rule.go +++ b/pagerduty/resource_pagerduty_ruleset_rule.go @@ -729,7 +729,7 @@ func flattenActiveBetween(ab *pagerduty.ActiveBetween) []interface{} { } func resourcePagerDutyRulesetRuleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() rule := buildRulesetRuleStruct(d) @@ -758,7 +758,7 @@ func resourcePagerDutyRulesetRuleCreate(d *schema.ResourceData, meta interface{} } func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty ruleset rule: %s", d.Id()) rulesetID := d.Get("ruleset").(string) @@ -789,7 +789,7 @@ func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) } func resourcePagerDutyRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() rule := buildRulesetRuleStruct(d) @@ -813,7 +813,7 @@ func resourcePagerDutyRulesetRuleUpdate(d *schema.ResourceData, meta interface{} } func resourcePagerDutyRulesetRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty ruleset rule: %s", d.Id()) rulesetID := d.Get("ruleset").(string) @@ -834,7 +834,7 @@ func resourcePagerDutyRulesetRuleDelete(d *schema.ResourceData, meta interface{} } func resourcePagerDutyRulesetRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.Split(d.Id(), ".") diff --git a/pagerduty/resource_pagerduty_ruleset_rule_test.go b/pagerduty/resource_pagerduty_ruleset_rule_test.go index 051e9007a..5b13ce290 100644 --- a/pagerduty/resource_pagerduty_ruleset_rule_test.go +++ b/pagerduty/resource_pagerduty_ruleset_rule_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyRulesetRule_Basic(t *testing.T) { @@ -120,7 +119,7 @@ func TestAccPagerDutyRulesetRule_MultipleRules(t *testing.T) { }) } func testAccCheckPagerDutyRulesetRuleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_ruleset_rule" { continue @@ -147,7 +146,7 @@ func testAccCheckPagerDutyRulesetRuleExists(n string) resource.TestCheckFunc { ruleset, _ := s.RootModule().Resources["pagerduty_ruleset.foo"] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Rulesets.GetRule(ruleset.Primary.ID, rs.Primary.ID) if err != nil { return fmt.Errorf("Ruleset Rule not found: %v", rs.Primary.ID) diff --git a/pagerduty/resource_pagerduty_ruleset_test.go b/pagerduty/resource_pagerduty_ruleset_test.go index d599f5336..3b6df783a 100644 --- a/pagerduty/resource_pagerduty_ruleset_test.go +++ b/pagerduty/resource_pagerduty_ruleset_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func init() { @@ -87,7 +86,7 @@ func TestAccPagerDutyRuleset_Basic(t *testing.T) { } func testAccCheckPagerDutyRulesetDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_ruleset" { continue @@ -109,7 +108,7 @@ func testAccCheckPagerDutyRulesetExists(n string) resource.TestCheckFunc { return fmt.Errorf("No Ruleset ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Rulesets.Get(rs.Primary.ID) if err != nil { return err diff --git a/pagerduty/resource_pagerduty_schedule.go b/pagerduty/resource_pagerduty_schedule.go index 713d41d24..fecb0bafb 100644 --- a/pagerduty/resource_pagerduty_schedule.go +++ b/pagerduty/resource_pagerduty_schedule.go @@ -180,7 +180,7 @@ func buildScheduleStruct(d *schema.ResourceData) (*pagerduty.Schedule, error) { } func resourcePagerDutyScheduleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() schedule, err := buildScheduleStruct(d) if err != nil { @@ -206,7 +206,7 @@ func resourcePagerDutyScheduleCreate(d *schema.ResourceData, meta interface{}) e } func resourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty schedule: %s", d.Id()) @@ -244,7 +244,7 @@ func resourcePagerDutyScheduleRead(d *schema.ResourceData, meta interface{}) err } func resourcePagerDutyScheduleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() schedule, err := buildScheduleStruct(d) if err != nil { @@ -313,7 +313,7 @@ func resourcePagerDutyScheduleUpdate(d *schema.ResourceData, meta interface{}) e } func resourcePagerDutyScheduleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty schedule: %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_schedule_test.go b/pagerduty/resource_pagerduty_schedule_test.go index d4240b058..4ed90a954 100644 --- a/pagerduty/resource_pagerduty_schedule_test.go +++ b/pagerduty/resource_pagerduty_schedule_test.go @@ -370,7 +370,7 @@ func TestAccPagerDutySchedule_Multi(t *testing.T) { } func testAccCheckPagerDutyScheduleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_schedule" { continue @@ -394,7 +394,7 @@ func testAccCheckPagerDutyScheduleExists(n string) resource.TestCheckFunc { return fmt.Errorf("No Schedule ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Schedules.Get(rs.Primary.ID, &pagerduty.GetScheduleOptions{}) if err != nil { diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 3c565c1a5..bbadbbb14 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -351,7 +351,7 @@ func buildServiceStruct(d *schema.ResourceData) (*pagerduty.Service, error) { } func resourcePagerDutyServiceCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() service, err := buildServiceStruct(d) if err != nil { @@ -371,7 +371,7 @@ func resourcePagerDutyServiceCreate(d *schema.ResourceData, meta interface{}) er } func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty service %s", d.Id()) @@ -396,7 +396,7 @@ func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) erro } func resourcePagerDutyServiceUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() service, err := buildServiceStruct(d) if err != nil { @@ -414,7 +414,7 @@ func resourcePagerDutyServiceUpdate(d *schema.ResourceData, meta interface{}) er } func resourcePagerDutyServiceDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty service %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_service_dependency.go b/pagerduty/resource_pagerduty_service_dependency.go index 5b65168b6..15d59e8b8 100644 --- a/pagerduty/resource_pagerduty_service_dependency.go +++ b/pagerduty/resource_pagerduty_service_dependency.go @@ -112,7 +112,7 @@ func expandService(v interface{}) *pagerduty.ServiceObj { return so } func resourcePagerDutyServiceDependencyAssociate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() serviceDependency, err := buildServiceDependencyStruct(d) if err != nil { @@ -151,7 +151,7 @@ func resourcePagerDutyServiceDependencyAssociate(d *schema.ResourceData, meta in } func resourcePagerDutyServiceDependencyDisassociate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() dependency, err := buildServiceDependencyStruct(d) if err != nil { @@ -260,7 +260,7 @@ func convertType(s string) string { } func findDependencySetState(depID, serviceID, serviceType string, d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() // Pausing to let the PD API sync. time.Sleep(1 * time.Second) diff --git a/pagerduty/resource_pagerduty_service_dependency_test.go b/pagerduty/resource_pagerduty_service_dependency_test.go index 99e182630..ae5e6b69c 100644 --- a/pagerduty/resource_pagerduty_service_dependency_test.go +++ b/pagerduty/resource_pagerduty_service_dependency_test.go @@ -50,7 +50,7 @@ func testAccCheckPagerDutyBusinessServiceDependencyExists(n string) resource.Tes } businessService, _ := s.RootModule().Resources["pagerduty_business_service.foo"] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() depResp, _, err := client.ServiceDependencies.GetServiceDependenciesForType(businessService.Primary.ID, "business_service") if err != nil { @@ -74,7 +74,7 @@ func testAccCheckPagerDutyBusinessServiceDependencyExists(n string) resource.Tes } func testAccCheckPagerDutyBusinessServiceDependencyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_service_dependency" { continue @@ -187,7 +187,7 @@ func testAccCheckPagerDutyTechnicalServiceDependencyExists(n string) resource.Te } supportService, _ := s.RootModule().Resources["pagerduty_service.supportBar"] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() depResp, _, err := client.ServiceDependencies.GetServiceDependenciesForType(supportService.Primary.ID, "service") if err != nil { @@ -211,7 +211,7 @@ func testAccCheckPagerDutyTechnicalServiceDependencyExists(n string) resource.Te } func testAccCheckPagerDutyTechnicalServiceDependencyDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_service_dependency" { continue diff --git a/pagerduty/resource_pagerduty_service_event_rule.go b/pagerduty/resource_pagerduty_service_event_rule.go index 5a385a17d..02183a6f6 100644 --- a/pagerduty/resource_pagerduty_service_event_rule.go +++ b/pagerduty/resource_pagerduty_service_event_rule.go @@ -323,7 +323,7 @@ func buildServiceEventRuleStruct(d *schema.ResourceData) *pagerduty.ServiceEvent return rule } func resourcePagerDutyServiceEventRuleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() rule := buildServiceEventRuleStruct(d) @@ -352,7 +352,7 @@ func resourcePagerDutyServiceEventRuleCreate(d *schema.ResourceData, meta interf } func resourcePagerDutyServiceEventRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty service event rule: %s", d.Id()) serviceID := d.Get("service").(string) @@ -383,7 +383,7 @@ func resourcePagerDutyServiceEventRuleRead(d *schema.ResourceData, meta interfac } func resourcePagerDutyServiceEventRuleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() rule := buildServiceEventRuleStruct(d) @@ -408,7 +408,7 @@ func resourcePagerDutyServiceEventRuleUpdate(d *schema.ResourceData, meta interf } func resourcePagerDutyServiceEventRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty service event rule: %s", d.Id()) serviceID := d.Get("service").(string) @@ -429,7 +429,7 @@ func resourcePagerDutyServiceEventRuleDelete(d *schema.ResourceData, meta interf } func resourcePagerDutyServiceEventRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.Split(d.Id(), ".") diff --git a/pagerduty/resource_pagerduty_service_event_rule_test.go b/pagerduty/resource_pagerduty_service_event_rule_test.go index a9cfea357..6e7afa5ad 100644 --- a/pagerduty/resource_pagerduty_service_event_rule_test.go +++ b/pagerduty/resource_pagerduty_service_event_rule_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyServiceEventRule_Basic(t *testing.T) { @@ -123,7 +122,7 @@ func TestAccPagerDutyServiceEventRule_MultipleRules(t *testing.T) { } func testAccCheckPagerDutyServiceEventRuleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_service_event_rule" { continue @@ -150,7 +149,7 @@ func testAccCheckPagerDutyServiceEventRuleExists(n string) resource.TestCheckFun service, _ := s.RootModule().Resources["pagerduty_service.foo"] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Services.GetEventRule(service.Primary.ID, rs.Primary.ID) if err != nil { return fmt.Errorf("ServiceEvent Rule not found: %v", rs.Primary.ID) diff --git a/pagerduty/resource_pagerduty_service_integration.go b/pagerduty/resource_pagerduty_service_integration.go index 07947b45a..bce14f5e0 100644 --- a/pagerduty/resource_pagerduty_service_integration.go +++ b/pagerduty/resource_pagerduty_service_integration.go @@ -115,7 +115,7 @@ func buildServiceIntegrationStruct(d *schema.ResourceData) *pagerduty.Integratio } func resourcePagerDutyServiceIntegrationCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() serviceIntegration := buildServiceIntegrationStruct(d) @@ -145,7 +145,7 @@ func resourcePagerDutyServiceIntegrationCreate(d *schema.ResourceData, meta inte } func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty service integration %s", d.Id()) @@ -194,7 +194,7 @@ func resourcePagerDutyServiceIntegrationRead(d *schema.ResourceData, meta interf } func resourcePagerDutyServiceIntegrationUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() serviceIntegration := buildServiceIntegrationStruct(d) @@ -210,7 +210,7 @@ func resourcePagerDutyServiceIntegrationUpdate(d *schema.ResourceData, meta inte } func resourcePagerDutyServiceIntegrationDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() service := d.Get("service").(string) @@ -226,7 +226,7 @@ func resourcePagerDutyServiceIntegrationDelete(d *schema.ResourceData, meta inte } func resourcePagerDutyServiceIntegrationImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.Split(d.Id(), ".") diff --git a/pagerduty/resource_pagerduty_service_integration_test.go b/pagerduty/resource_pagerduty_service_integration_test.go index 213f25394..7cd9387c1 100644 --- a/pagerduty/resource_pagerduty_service_integration_test.go +++ b/pagerduty/resource_pagerduty_service_integration_test.go @@ -106,7 +106,7 @@ func TestAccPagerDutyServiceIntegrationGeneric_Basic(t *testing.T) { } func testAccCheckPagerDutyServiceIntegrationDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_service_integration" { continue @@ -135,7 +135,7 @@ func testAccCheckPagerDutyServiceIntegrationExists(n string) resource.TestCheckF service, _ := s.RootModule().Resources["pagerduty_service.foo"] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Services.GetIntegration(service.Primary.ID, rs.Primary.ID, &pagerduty.GetIntegrationOptions{}) if err != nil { diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go index e17ff892a..7da81fcaf 100644 --- a/pagerduty/resource_pagerduty_service_test.go +++ b/pagerduty/resource_pagerduty_service_test.go @@ -596,7 +596,7 @@ func testAccCheckPagerDutyServiceSaveServiceId(p *string, n string) resource.Tes return fmt.Errorf("No Service ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Services.Get(rs.Primary.ID, &pagerduty.GetServiceOptions{}) if err != nil { @@ -614,7 +614,7 @@ func testAccCheckPagerDutyServiceSaveServiceId(p *string, n string) resource.Tes } func testAccCheckPagerDutyServiceDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_service" { continue @@ -639,7 +639,7 @@ func testAccCheckPagerDutyServiceExists(n string) resource.TestCheckFunc { return fmt.Errorf("No Service ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Services.Get(rs.Primary.ID, &pagerduty.GetServiceOptions{}) if err != nil { diff --git a/pagerduty/resource_pagerduty_slack_connection.go b/pagerduty/resource_pagerduty_slack_connection.go index 7e06ed067..58165934c 100644 --- a/pagerduty/resource_pagerduty_slack_connection.go +++ b/pagerduty/resource_pagerduty_slack_connection.go @@ -3,7 +3,6 @@ package pagerduty import ( "fmt" "log" - "os" "strings" "time" @@ -110,8 +109,7 @@ func buildSlackConnectionStruct(d *schema.ResourceData) (*pagerduty.SlackConnect } func resourcePagerDutySlackConnectionCreate(d *schema.ResourceData, meta interface{}) error { - config := setClientConfig() - client, err := pagerduty.NewClient(config) + client, err := meta.(*Config).SlackClient() if err != nil { return err } @@ -140,8 +138,7 @@ func resourcePagerDutySlackConnectionCreate(d *schema.ResourceData, meta interfa } func resourcePagerDutySlackConnectionRead(d *schema.ResourceData, meta interface{}) error { - config := setClientConfig() - client, err := pagerduty.NewClient(config) + client, err := meta.(*Config).SlackClient() if err != nil { return err } @@ -175,11 +172,7 @@ func resourcePagerDutySlackConnectionRead(d *schema.ResourceData, meta interface } func resourcePagerDutySlackConnectionUpdate(d *schema.ResourceData, meta interface{}) error { - config := &pagerduty.Config{ - Token: os.Getenv("PAGERDUTY_USER_TOKEN"), - BaseURL: AppBaseUrl, - } - client, err := pagerduty.NewClient(config) + client, err := meta.(*Config).SlackClient() if err != nil { return err } @@ -198,8 +191,7 @@ func resourcePagerDutySlackConnectionUpdate(d *schema.ResourceData, meta interfa } func resourcePagerDutySlackConnectionDelete(d *schema.ResourceData, meta interface{}) error { - config := setClientConfig() - client, err := pagerduty.NewClient(config) + client, err := meta.(*Config).SlackClient() if err != nil { return err } @@ -266,16 +258,8 @@ func flattenConfigList(list []string) interface{} { return items } -func setClientConfig() *pagerduty.Config { - return &pagerduty.Config{ - Token: os.Getenv("PAGERDUTY_USER_TOKEN"), - BaseURL: AppBaseUrl, - } -} - func resourcePagerDutySlackConnectionImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - config := setClientConfig() - client, err := pagerduty.NewClient(config) + client, err := meta.(*Config).SlackClient() if err != nil { return nil, err } diff --git a/pagerduty/resource_pagerduty_slack_connection_test.go b/pagerduty/resource_pagerduty_slack_connection_test.go index 2169a130f..af9133252 100644 --- a/pagerduty/resource_pagerduty_slack_connection_test.go +++ b/pagerduty/resource_pagerduty_slack_connection_test.go @@ -120,7 +120,7 @@ func testAccCheckPagerDutySlackConnectionDestroy(s *terraform.State) error { scatts := r.Primary.Attributes if _, _, err := client.SlackConnections.Get(scatts["workspace_id"], r.Primary.ID); err == nil { - return fmt.Errorf("response play still exists") + return fmt.Errorf("slack connection still exists") } } diff --git a/pagerduty/resource_pagerduty_tag.go b/pagerduty/resource_pagerduty_tag.go index 423af8ca5..900dfe729 100644 --- a/pagerduty/resource_pagerduty_tag.go +++ b/pagerduty/resource_pagerduty_tag.go @@ -49,7 +49,7 @@ func buildTagStruct(d *schema.ResourceData) *pagerduty.Tag { } func resourcePagerDutyTagCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() tag := buildTagStruct(d) @@ -77,7 +77,7 @@ func resourcePagerDutyTagCreate(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyTagRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty tag %s", d.Id()) @@ -96,7 +96,7 @@ func resourcePagerDutyTagRead(d *schema.ResourceData, meta interface{}) error { } func resourcePagerDutyTagDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty tag %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_tag_assignment.go b/pagerduty/resource_pagerduty_tag_assignment.go index 21e434701..66958baaa 100644 --- a/pagerduty/resource_pagerduty_tag_assignment.go +++ b/pagerduty/resource_pagerduty_tag_assignment.go @@ -60,7 +60,7 @@ func buildTagAssignmentStruct(d *schema.ResourceData) *pagerduty.TagAssignment { } func resourcePagerDutyTagAssignmentCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() assignment := buildTagAssignmentStruct(d) assignments := &pagerduty.TagAssignments{ @@ -94,7 +94,7 @@ func resourcePagerDutyTagAssignmentCreate(d *schema.ResourceData, meta interface } func resourcePagerDutyTagAssignmentRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() assignment := buildTagAssignmentStruct(d) @@ -124,7 +124,7 @@ func resourcePagerDutyTagAssignmentRead(d *schema.ResourceData, meta interface{} } func resourcePagerDutyTagAssignmentDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() assignment := buildTagAssignmentStruct(d) assignments := &pagerduty.TagAssignments{ @@ -158,7 +158,7 @@ func resourcePagerDutyTagAssignmentImport(d *schema.ResourceData, meta interface 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] - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() // give PagerDuty 2 seconds to save the assignment correctly time.Sleep(2 * time.Second) tagResponse, _, err := client.Tags.ListTagsForEntity(entityType, entityID) diff --git a/pagerduty/resource_pagerduty_tag_assignment_test.go b/pagerduty/resource_pagerduty_tag_assignment_test.go index cb21a5fff..893463dc4 100644 --- a/pagerduty/resource_pagerduty_tag_assignment_test.go +++ b/pagerduty/resource_pagerduty_tag_assignment_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyTagAssignment_User(t *testing.T) { @@ -84,7 +83,7 @@ func TestAccPagerDutyTagAssignment_EP(t *testing.T) { } func testAccCheckPagerDutyTagAssignmentDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_tag_assignment" { continue @@ -122,7 +121,7 @@ func testAccCheckPagerDutyTagAssignmentExists(n, entityType string) resource.Tes entityID, tagID := ids[0], ids[1] - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() response, _, err := client.Tags.ListTagsForEntity(entityType, entityID) if err != nil { return err diff --git a/pagerduty/resource_pagerduty_tag_test.go b/pagerduty/resource_pagerduty_tag_test.go index 374678e9f..23e396a46 100644 --- a/pagerduty/resource_pagerduty_tag_test.go +++ b/pagerduty/resource_pagerduty_tag_test.go @@ -68,7 +68,7 @@ func TestAccPagerDutyTag_Basic(t *testing.T) { } func testAccCheckPagerDutyTagDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_tag" { continue @@ -90,7 +90,7 @@ func testAccCheckPagerDutyTagExists(n string) resource.TestCheckFunc { return fmt.Errorf("No Tag ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Tags.Get(rs.Primary.ID) if err != nil { return err diff --git a/pagerduty/resource_pagerduty_team.go b/pagerduty/resource_pagerduty_team.go index 751f32d7a..3daf535b1 100644 --- a/pagerduty/resource_pagerduty_team.go +++ b/pagerduty/resource_pagerduty_team.go @@ -58,7 +58,7 @@ func buildTeamStruct(d *schema.ResourceData) *pagerduty.Team { } func resourcePagerDutyTeamCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() team := buildTeamStruct(d) @@ -82,7 +82,7 @@ func resourcePagerDutyTeamCreate(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Reading PagerDuty team %s", d.Id()) @@ -100,7 +100,7 @@ func resourcePagerDutyTeamRead(d *schema.ResourceData, meta interface{}) error { } func resourcePagerDutyTeamUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() team := buildTeamStruct(d) @@ -120,7 +120,7 @@ func resourcePagerDutyTeamUpdate(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyTeamDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty team %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_team_membership.go b/pagerduty/resource_pagerduty_team_membership.go index 9e45094c6..aaa0f42c7 100644 --- a/pagerduty/resource_pagerduty_team_membership.go +++ b/pagerduty/resource_pagerduty_team_membership.go @@ -45,7 +45,7 @@ func resourcePagerDutyTeamMembership() *schema.Resource { } } func resourcePagerDutyTeamMembershipCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) teamID := d.Get("team_id").(string) @@ -74,7 +74,7 @@ func resourcePagerDutyTeamMembershipCreate(d *schema.ResourceData, meta interfac } func resourcePagerDutyTeamMembershipRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID, teamID := resourcePagerDutyTeamMembershipParseID(d.Id()) @@ -110,7 +110,7 @@ func resourcePagerDutyTeamMembershipRead(d *schema.ResourceData, meta interface{ } func resourcePagerDutyTeamMembershipUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) teamID := d.Get("team_id").(string) @@ -140,7 +140,7 @@ func resourcePagerDutyTeamMembershipUpdate(d *schema.ResourceData, meta interfac } func resourcePagerDutyTeamMembershipDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID, teamID := resourcePagerDutyTeamMembershipParseID(d.Id()) diff --git a/pagerduty/resource_pagerduty_team_membership_test.go b/pagerduty/resource_pagerduty_team_membership_test.go index b075976bc..ffcc6cff2 100644 --- a/pagerduty/resource_pagerduty_team_membership_test.go +++ b/pagerduty/resource_pagerduty_team_membership_test.go @@ -50,7 +50,7 @@ func TestAccPagerDutyTeamMembership_WithRole(t *testing.T) { } func testAccCheckPagerDutyTeamMembershipDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_team_membership" { continue @@ -69,7 +69,7 @@ func testAccCheckPagerDutyTeamMembershipDestroy(s *terraform.State) error { func testAccCheckPagerDutyTeamMembershipExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() rs, ok := s.RootModule().Resources[n] if !ok { diff --git a/pagerduty/resource_pagerduty_team_test.go b/pagerduty/resource_pagerduty_team_test.go index 05bb847f2..9de51be9b 100644 --- a/pagerduty/resource_pagerduty_team_test.go +++ b/pagerduty/resource_pagerduty_team_test.go @@ -118,7 +118,7 @@ func TestAccPagerDutyTeam_Parent(t *testing.T) { } func testAccCheckPagerDutyTeamDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_team" { continue @@ -134,7 +134,7 @@ func testAccCheckPagerDutyTeamDestroy(s *terraform.State) error { func testAccCheckPagerDutyTeamExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if _, _, err := client.Teams.Get(r.Primary.ID); err != nil { return fmt.Errorf("Received an error retrieving team %s ID: %s", err, r.Primary.ID) diff --git a/pagerduty/resource_pagerduty_user.go b/pagerduty/resource_pagerduty_user.go index b064433bf..a00adaa25 100644 --- a/pagerduty/resource_pagerduty_user.go +++ b/pagerduty/resource_pagerduty_user.go @@ -132,7 +132,7 @@ func buildUserStruct(d *schema.ResourceData) *pagerduty.User { } func resourcePagerDutyUserCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() user := buildUserStruct(d) @@ -149,7 +149,7 @@ func resourcePagerDutyUserCreate(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] pooh Reading PagerDuty user %s", d.Id()) @@ -188,7 +188,7 @@ func resourcePagerDutyUserRead(d *schema.ResourceData, meta interface{}) error { } func resourcePagerDutyUserUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() user := buildUserStruct(d) @@ -254,7 +254,7 @@ func resourcePagerDutyUserUpdate(d *schema.ResourceData, meta interface{}) error } func resourcePagerDutyUserDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty user %s", d.Id()) diff --git a/pagerduty/resource_pagerduty_user_contact_method.go b/pagerduty/resource_pagerduty_user_contact_method.go index 9ca152624..2330a9872 100644 --- a/pagerduty/resource_pagerduty_user_contact_method.go +++ b/pagerduty/resource_pagerduty_user_contact_method.go @@ -93,7 +93,7 @@ func buildUserContactMethodStruct(d *schema.ResourceData) *pagerduty.ContactMeth return contactMethod } func resourcePagerDutyUserContactMethodCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) @@ -110,7 +110,7 @@ func resourcePagerDutyUserContactMethodCreate(d *schema.ResourceData, meta inter } func resourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) @@ -139,7 +139,7 @@ func resourcePagerDutyUserContactMethodRead(d *schema.ResourceData, meta interfa } func resourcePagerDutyUserContactMethodUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() contactMethod := buildUserContactMethodStruct(d) @@ -155,7 +155,7 @@ func resourcePagerDutyUserContactMethodUpdate(d *schema.ResourceData, meta inter } func resourcePagerDutyUserContactMethodDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty user contact method %s", d.Id()) @@ -171,7 +171,7 @@ func resourcePagerDutyUserContactMethodDelete(d *schema.ResourceData, meta inter } func resourcePagerDutyUserContactMethodImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.Split(d.Id(), ":") diff --git a/pagerduty/resource_pagerduty_user_contact_method_test.go b/pagerduty/resource_pagerduty_user_contact_method_test.go index 8ba604e6a..3947b2728 100644 --- a/pagerduty/resource_pagerduty_user_contact_method_test.go +++ b/pagerduty/resource_pagerduty_user_contact_method_test.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyUserContactMethodEmail_Basic(t *testing.T) { @@ -92,7 +91,7 @@ func TestAccPagerDutyUserContactMethodSMS_Basic(t *testing.T) { } func testAccCheckPagerDutyUserContactMethodDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_user_contact_method" { continue @@ -117,7 +116,7 @@ func testAccCheckPagerDutyUserContactMethodExists(n string) resource.TestCheckFu return fmt.Errorf("No user contact method ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Users.GetContactMethod(rs.Primary.Attributes["user_id"], rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_user_notification_rule.go b/pagerduty/resource_pagerduty_user_notification_rule.go index cb71e93a4..37663f065 100644 --- a/pagerduty/resource_pagerduty_user_notification_rule.go +++ b/pagerduty/resource_pagerduty_user_notification_rule.go @@ -72,7 +72,7 @@ func buildUserNotificationRuleStruct(d *schema.ResourceData) (*pagerduty.Notific } func resourcePagerDutyUserNotificationRuleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) @@ -92,7 +92,7 @@ func resourcePagerDutyUserNotificationRuleCreate(d *schema.ResourceData, meta in } func resourcePagerDutyUserNotificationRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() userID := d.Get("user_id").(string) @@ -117,7 +117,7 @@ func resourcePagerDutyUserNotificationRuleRead(d *schema.ResourceData, meta inte } func resourcePagerDutyUserNotificationRuleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() notificationRule, err := buildUserNotificationRuleStruct(d) if err != nil { @@ -136,7 +136,7 @@ func resourcePagerDutyUserNotificationRuleUpdate(d *schema.ResourceData, meta in } func resourcePagerDutyUserNotificationRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() log.Printf("[INFO] Deleting PagerDuty user notification rule %s", d.Id()) @@ -152,7 +152,7 @@ func resourcePagerDutyUserNotificationRuleDelete(d *schema.ResourceData, meta in } func resourcePagerDutyUserNotificationRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - client := meta.(*pagerduty.Client) + client, _ := meta.(*Config).Client() ids := strings.Split(d.Id(), ":") diff --git a/pagerduty/resource_pagerduty_user_notification_rule_test.go b/pagerduty/resource_pagerduty_user_notification_rule_test.go index 051279f2e..6e80e3f6f 100644 --- a/pagerduty/resource_pagerduty_user_notification_rule_test.go +++ b/pagerduty/resource_pagerduty_user_notification_rule_test.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" ) func TestAccPagerDutyUserNotificationRuleContactMethod_Basic(t *testing.T) { @@ -114,7 +113,7 @@ func TestAccPagerDutyUserNotificationRuleContactMethod_Unknown_key(t *testing.T) } func testAccCheckPagerDutyUserNotificationRuleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_user_notification_rule" { continue @@ -139,7 +138,7 @@ func testAccCheckPagerDutyUserNotificationRuleExists(n string) resource.TestChec return fmt.Errorf("No user notification rule ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Users.GetNotificationRule(rs.Primary.Attributes["user_id"], rs.Primary.ID) if err != nil { diff --git a/pagerduty/resource_pagerduty_user_test.go b/pagerduty/resource_pagerduty_user_test.go index 7d2939c0e..89bd18759 100644 --- a/pagerduty/resource_pagerduty_user_test.go +++ b/pagerduty/resource_pagerduty_user_test.go @@ -152,7 +152,7 @@ func TestAccPagerDutyUserWithTeams_Basic(t *testing.T) { } func testAccCheckPagerDutyUserDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() for _, r := range s.RootModule().Resources { if r.Type != "pagerduty_user" { continue @@ -176,7 +176,7 @@ func testAccCheckPagerDutyUserExists(n string) resource.TestCheckFunc { return fmt.Errorf("No user ID is set") } - client := testAccProvider.Meta().(*pagerduty.Client) + client, _ := testAccProvider.Meta().(*Config).Client() found, _, err := client.Users.Get(rs.Primary.ID, &pagerduty.GetUserOptions{}) if err != nil { diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 6b2e0de5b..2935e5cbc 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -44,4 +44,7 @@ resource "pagerduty_team_membership" "earline_engineering" { The following arguments are supported: * `token` - (Required) The v2 authorization token. It can also be sourced from the PAGERDUTY_TOKEN environment variable. See [API Documentation](https://developer.pagerduty.com/docs/rest-api-v2/authentication/) for more information. +* `user_token` - (Optional) The v2 user level authorization token. It can also be sourced from the PAGERDUTY_USER_TOKEN environment variable. See [API Documentation](https://developer.pagerduty.com/docs/rest-api-v2/authentication/) for more information. * `skip_credentials_validation` - (Optional) Skip validation of the token against the PagerDuty API. +* `service_region` - (Optional) Which PagerDuty service region to use. Default to empty (use US region) +