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.
This commit is contained in:
parent
6947ba2518
commit
04e86697fb
|
@ -94,6 +94,11 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
resp, err := ec2conn.DescribeSubnets([]string{d.Id()}, ec2.NewFilter())
|
resp, err := ec2conn.DescribeSubnets([]string{d.Id()}, ec2.NewFilter())
|
||||||
|
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
|
|
Loading…
Reference in New Issue