From 2cca48a829b51da19b7a19a0e60f6ec4ef4e294b Mon Sep 17 00:00:00 2001 From: Eric Rutherford Date: Tue, 6 Sep 2016 20:57:10 -0500 Subject: [PATCH] switch to go way of checking for key existence so that go doesn't crash when the value doesn't exist --- builtin/providers/aws/resource_aws_nat_gateway.go | 2 +- .../providers/aws/resource_aws_nat_gateway_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_nat_gateway.go b/builtin/providers/aws/resource_aws_nat_gateway.go index deabc7297..1ec5e986e 100644 --- a/builtin/providers/aws/resource_aws_nat_gateway.go +++ b/builtin/providers/aws/resource_aws_nat_gateway.go @@ -108,7 +108,7 @@ func resourceAwsNatGatewayRead(d *schema.ResourceData, meta interface{}) error { "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()) d.SetId("") return nil diff --git a/builtin/providers/aws/resource_aws_nat_gateway_test.go b/builtin/providers/aws/resource_aws_nat_gateway_test.go index 96aac1625..dac50527c 100644 --- a/builtin/providers/aws/resource_aws_nat_gateway_test.go +++ b/builtin/providers/aws/resource_aws_nat_gateway_test.go @@ -43,13 +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 && 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") }