From 04e86697fb1934ff311746db15dfe27b8fc22f08 Mon Sep 17 00:00:00 2001 From: Phil Frost Date: Thu, 29 Jan 2015 11:06:40 -0500 Subject: [PATCH] Fix error when refreshing on a deleted AWS subnet If a subnet exists in the state file and a refresh is performed, the read function for subnets would return an error. Now it updates the state to indicate that the subnet no longer exists, so Terraform can plan to recreate it. --- builtin/providers/aws/resource_aws_subnet.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_subnet.go b/builtin/providers/aws/resource_aws_subnet.go index 7bb88f58f..dce9151e6 100644 --- a/builtin/providers/aws/resource_aws_subnet.go +++ b/builtin/providers/aws/resource_aws_subnet.go @@ -94,6 +94,11 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error { resp, err := ec2conn.DescribeSubnets([]string{d.Id()}, ec2.NewFilter()) if err != nil { + if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidSubnetID.NotFound" { + // Update state to indicate the subnet no longer exists. + d.SetId("") + return nil + } return err } if resp == nil {