Skip to content

Commit

Permalink
Merge branch 's-maj-GH-4285'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed May 21, 2018
2 parents 86cecfd + 83b6b39 commit c1b986b
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions aws/resource_aws_appautoscaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac

log.Printf("[DEBUG] ApplicationAutoScaling PutScalingPolicy: %#v", params)
var resp *applicationautoscaling.PutScalingPolicyOutput
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
err = resource.Retry(2*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.PutScalingPolicy(&params)
if err != nil {
Expand Down Expand Up @@ -285,10 +285,23 @@ func resourceAwsAppautoscalingPolicyCreate(d *schema.ResourceData, meta interfac
}

func resourceAwsAppautoscalingPolicyRead(d *schema.ResourceData, meta interface{}) error {
p, err := getAwsAppautoscalingPolicy(d, meta)
var p *applicationautoscaling.ScalingPolicy

err := resource.Retry(2*time.Minute, func() *resource.RetryError {
var err error
p, err = getAwsAppautoscalingPolicy(d, meta)
if err != nil {
if isAWSErr(err, applicationautoscaling.ErrCodeFailedResourceAccessException, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return err
return fmt.Errorf("Failed to read scaling policy: %s", err)
}

if p == nil {
log.Printf("[WARN] Application AutoScaling Policy (%s) not found, removing from state", d.Id())
d.SetId("")
Expand Down Expand Up @@ -320,7 +333,16 @@ func resourceAwsAppautoscalingPolicyUpdate(d *schema.ResourceData, meta interfac
}

log.Printf("[DEBUG] Application Autoscaling Update Scaling Policy: %#v", params)
_, err := conn.PutScalingPolicy(&params)
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
_, err := conn.PutScalingPolicy(&params)
if err != nil {
if isAWSErr(err, applicationautoscaling.ErrCodeFailedResourceAccessException, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Failed to update scaling policy: %s", err)
}
Expand All @@ -345,10 +367,19 @@ func resourceAwsAppautoscalingPolicyDelete(d *schema.ResourceData, meta interfac
ServiceNamespace: aws.String(d.Get("service_namespace").(string)),
}
log.Printf("[DEBUG] Deleting Application AutoScaling Policy opts: %#v", params)
if _, err := conn.DeleteScalingPolicy(&params); err != nil {
return fmt.Errorf("Failed to delete autoscaling policy: %s", err)
err = resource.Retry(2*time.Minute, func() *resource.RetryError {
_, err = conn.DeleteScalingPolicy(&params)
if err != nil {
if isAWSErr(err, applicationautoscaling.ErrCodeFailedResourceAccessException, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Failed to delete scaling policy: %s", err)
}

return nil
}

Expand Down

0 comments on commit c1b986b

Please sign in to comment.