Skip to content

Commit

Permalink
[PagerDuty#273] adding servince now extension
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-spence-code committed Aug 29, 2021
1 parent 7819cf8 commit 0c53f96
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions pagerduty/resource_pagerduty_extension_servicenow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0c53f96

Please sign in to comment.