moving to using a map to clean up the error check

This commit is contained in:
Eric Rutherford 2016-09-06 14:54:17 -05:00
parent 7a6b04dfa2
commit 91f6f2a143
No known key found for this signature in database
GPG Key ID: C17F0EE0D14C4B94
2 changed files with 14 additions and 2 deletions

View File

@ -101,7 +101,14 @@ func resourceAwsNatGatewayRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
if ngRaw == nil || strings.ToLower(state) == "deleted" || strings.ToLower(state) == "deleting" || strings.ToLower(state) == "failed" {
status := map[string]bool {
"deleted": true,
"deleting": true,
"failed": true,
}
if ngRaw == nil || status[strings.ToLower(state)] {
log.Printf("[INFO] Removing %s from Terraform state as it is not found or in the deleted state.", d.Id())
d.SetId("")
return nil

View File

@ -43,8 +43,13 @@ func testAccCheckNatGatewayDestroy(s *terraform.State) error {
resp, err := conn.DescribeNatGateways(&ec2.DescribeNatGatewaysInput{
NatGatewayIds: []*string{aws.String(rs.Primary.ID)},
})
status := map[string]bool {
"deleted": false,
"deleting": false,
"failed": false,
}
if err == nil {
if len(resp.NatGateways) > 0 && strings.ToLower(*resp.NatGateways[0].State) != "deleted" && strings.ToLower(*resp.NatGateways[0].State) != "deleting" && strings.ToLower(*resp.NatGateways[0].State) != "failed" {
if len(resp.NatGateways) > 0 && status[strings.ToLower(*resp.NatGateways[0].State)] {
return fmt.Errorf("still exists")
}