Skip to content

Commit

Permalink
elasticache: Retry deletion on InvalidCacheParameterGroupState (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Jun 12, 2017
1 parent c4c7ce0 commit 12abeb2
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions aws/resource_aws_elasticache_parameter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,38 +171,26 @@ func resourceAwsElasticacheParameterGroupUpdate(d *schema.ResourceData, meta int
}

func resourceAwsElasticacheParameterGroupDelete(d *schema.ResourceData, meta interface{}) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"pending"},
Target: []string{"destroyed"},
Refresh: resourceAwsElasticacheParameterGroupDeleteRefreshFunc(d, meta),
Timeout: 3 * time.Minute,
MinTimeout: 1 * time.Second,
}
_, err := stateConf.WaitForState()
return err
}

func resourceAwsElasticacheParameterGroupDeleteRefreshFunc(
d *schema.ResourceData,
meta interface{}) resource.StateRefreshFunc {
conn := meta.(*AWSClient).elasticacheconn

return func() (interface{}, string, error) {

return resource.Retry(3*time.Minute, func() *resource.RetryError {
deleteOpts := elasticache.DeleteCacheParameterGroupInput{
CacheParameterGroupName: aws.String(d.Id()),
}

if _, err := conn.DeleteCacheParameterGroup(&deleteOpts); err != nil {
elasticahceerr, ok := err.(awserr.Error)
if ok && elasticahceerr.Code() == "CacheParameterGroupNotFoundFault" {
_, err := conn.DeleteCacheParameterGroup(&deleteOpts)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "CacheParameterGroupNotFoundFault" {
d.SetId("")
return d, "error", err
return nil
}
return d, "error", err
if ok && awsErr.Code() == "InvalidCacheParameterGroupState" {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return d, "destroyed", nil
}
return nil
})
}

func resourceAwsElasticacheParameterHash(v interface{}) int {
Expand Down

0 comments on commit 12abeb2

Please sign in to comment.