Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset ID if not found
Browse files Browse the repository at this point in the history
Philip Reichenberger committed Sep 9, 2020
1 parent 9d92531 commit e91a8db
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/terraform-provider-paperspace/resource_autoscaling_group.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,18 @@ import (
"github.com/paperspace/paperspace-go"
)

func resetIfNotFound(d *schema.ResourceData, err error) error {
paperspaceError, ok := err.(paperspace.PaperspaceError)
if ok {
if paperspaceError.Status == 404 {
d.SetId("")
return nil
}
}

return err
}

func resourceAutoscalingGroupCreate(d *schema.ResourceData, m interface{}) error {
var autoscalingGroup paperspace.AutoscalingGroup

@@ -52,15 +64,7 @@ func resourceAutoscalingGroupRead(d *schema.ResourceData, m interface{}) error {

autoscalingGroup, err := paperspaceClient.GetAutoscalingGroup(d.Id(), paperspace.AutoscalingGroupGetParams{})
if err != nil {
paperspaceError, ok := err.(paperspace.PaperspaceError)
if ok {
if paperspaceError.Status == 404 {
d.SetId("")
return nil
}
}

return err
return resetIfNotFound(d, err)
}

d.Set("name", autoscalingGroup.Name)
@@ -90,7 +94,7 @@ func resourceAutoscalingGroupUpdate(d *schema.ResourceData, m interface{}) error

err := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
if err := paperspaceClient.UpdateAutoscalingGroup(d.Id(), autoscalingGroupUpdateParams); err != nil {
return resource.RetryableError(err)
return resource.RetryableError(resetIfNotFound(d, err))
}

return resource.NonRetryableError(nil)
@@ -114,7 +118,7 @@ func resourceAutoscalingGroupDelete(d *schema.ResourceData, m interface{}) error

return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
if err := paperspaceClient.DeleteAutoscalingGroup(d.Id(), paperspace.AutoscalingGroupDeleteParams{}); err != nil {
return resource.RetryableError(err)
return resource.RetryableError(resetIfNotFound(d, err))
}

return resource.NonRetryableError(nil)

0 comments on commit e91a8db

Please sign in to comment.