diff --git a/pagerduty/resource_pagerduty_extension_servicenow.go b/pagerduty/resource_pagerduty_extension_servicenow.go index c375eb356..cb8ac3e52 100644 --- a/pagerduty/resource_pagerduty_extension_servicenow.go +++ b/pagerduty/resource_pagerduty_extension_servicenow.go @@ -116,32 +116,12 @@ func buildExtensionServiceNowStruct(d *schema.ResourceData) *pagerduty.Extension return Extension } -func resourcePagerDutyExtensionServiceNowCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - extension := buildExtensionServiceNowStruct(d) - - log.Printf("[INFO] Creating PagerDuty extension %s", extension.Name) - - extension, _, err := client.Extensions.Create(extension) - if err != nil { - return err - } - - d.SetId(extension.ID) - - return resourcePagerDutyExtensionServiceNowRead(d, meta) -} - -func resourcePagerDutyExtensionServiceNowRead(d *schema.ResourceData, meta interface{}) error { +func fetchPagerDutyExtensionServiceNowCreate(d *schema.ResourceData, meta interface{}, errCallback func(error, *schema.ResourceData) error) error { client := meta.(*pagerduty.Client) - - log.Printf("[INFO] Reading PagerDuty extension %s", d.Id()) - return resource.Retry(2*time.Minute, func() *resource.RetryError { extension, _, err := client.Extensions.Get(d.Id()) if err != nil { - errResp := handleNotFoundError(err, d) + errResp := errCallback(err, d) if errResp != nil { time.Sleep(2 * time.Second) return resource.RetryableError(errResp) @@ -173,6 +153,27 @@ func resourcePagerDutyExtensionServiceNowRead(d *schema.ResourceData, meta inter }) } +func resourcePagerDutyExtensionServiceNowCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*pagerduty.Client) + + extension := buildExtensionServiceNowStruct(d) + + log.Printf("[INFO] Creating PagerDuty extension %s", extension.Name) + + extension, _, err := client.Extensions.Create(extension) + if err != nil { + return err + } + + d.SetId(extension.ID) + return fetchPagerDutyExtensionServiceNowCreate(d, meta, genError) +} + +func resourcePagerDutyExtensionServiceNowRead(d *schema.ResourceData, meta interface{}) error { + log.Printf("[INFO] Reading PagerDuty extension %s", d.Id()) + return fetchPagerDutyExtensionServiceNowCreate(d, meta, handleNotFoundError) +} + func resourcePagerDutyExtensionServiceNowUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*pagerduty.Client)