From b6abb91b8374b4df2f8f15f54edb8685597374c0 Mon Sep 17 00:00:00 2001 From: Brett Mack Date: Fri, 6 Nov 2015 16:39:40 +0000 Subject: [PATCH] Class a resource that is in tfstate but unable to be found on the provider as deleted --- builtin/providers/vcd/resource_vcd_network.go | 4 +++- builtin/providers/vcd/resource_vcd_vapp.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/builtin/providers/vcd/resource_vcd_network.go b/builtin/providers/vcd/resource_vcd_network.go index c984d708e..b247be5da 100644 --- a/builtin/providers/vcd/resource_vcd_network.go +++ b/builtin/providers/vcd/resource_vcd_network.go @@ -207,7 +207,9 @@ func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error { network, err := vcd_client.OrgVdc.FindVDCNetwork(d.Id()) if err != nil { - return fmt.Errorf("Error finding network: %#v", err) + log.Printf("[DEBUG] Network no longer exists. Removing from tfstate") + d.SetId("") + return nil } d.Set("name", network.OrgVDCNetwork.Name) diff --git a/builtin/providers/vcd/resource_vcd_vapp.go b/builtin/providers/vcd/resource_vcd_vapp.go index ee50d63ea..c50037868 100644 --- a/builtin/providers/vcd/resource_vcd_vapp.go +++ b/builtin/providers/vcd/resource_vcd_vapp.go @@ -355,7 +355,9 @@ func resourceVcdVAppRead(d *schema.ResourceData, meta interface{}) error { vapp, err := vcd_client.OrgVdc.FindVAppByName(d.Id()) if err != nil { - return fmt.Errorf("Error finding vapp: %#v", err) + log.Printf("[DEBUG] Unable to find vapp. Removing from tfstate") + d.SetId("") + return nil } d.Set("ip", vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress)