Skip to content

Commit

Permalink
Merge pull request #307 from alekstorm/aws-db-instance-gone
Browse files Browse the repository at this point in the history
providers/aws: don't error out when RDS DB instance disappears
  • Loading branch information
mitchellh committed Sep 30, 2014
2 parents 61a4ac7 + f928829 commit 452cc07
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions builtin/providers/aws/resource_aws_db_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func resource_aws_db_instance_refresh(
if err != nil {
return s, err
}
if v == nil {
s.ID = ""
return s, nil
}

return resource_aws_db_instance_update_state(s, v)
}
Expand Down Expand Up @@ -298,13 +302,16 @@ func resource_aws_db_instance_retrieve(id string, conn *rds.Rds) (*rds.DBInstanc
resp, err := conn.DescribeDBInstances(&opts)

if err != nil {
if strings.Contains(err.Error(), "DBInstanceNotFound") {
return nil, nil
}
return nil, fmt.Errorf("Error retrieving DB Instances: %s", err)
}

if len(resp.DBInstances) != 1 ||
resp.DBInstances[0].DBInstanceIdentifier != id {
if err != nil {
return nil, fmt.Errorf("Unable to find DB Instance: %#v", resp.DBInstances)
return nil, nil
}
}

Expand Down Expand Up @@ -347,16 +354,14 @@ func DBInstanceStateRefreshFunc(id string, conn *rds.Rds) resource.StateRefreshF
v, err := resource_aws_db_instance_retrieve(id, conn)

if err != nil {
// We want to special-case "not found" instances because
// it could be waiting for it to be gone.
if strings.Contains(err.Error(), "DBInstanceNotFound") {
return nil, "", nil
}

log.Printf("Error on retrieving DB Instance when waiting: %s", err)
return nil, "", err
}

if v == nil {
return nil, "", nil
}

return v, v.DBInstanceStatus, nil
}
}

0 comments on commit 452cc07

Please sign in to comment.