switch to go way of checking for key existence so that go doesn't crash when the value doesn't exist

This commit is contained in:
Eric Rutherford 2016-09-06 20:57:10 -05:00
parent 04c2d40e57
commit 2cca48a829
No known key found for this signature in database
GPG Key ID: C17F0EE0D14C4B94
2 changed files with 7 additions and 7 deletions

View File

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

View File

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