From 419ef6c152cca13c12b9a18c0b6af662db8db856 Mon Sep 17 00:00:00 2001 From: Lucas Serven Date: Sat, 26 May 2018 08:40:36 +0200 Subject: [PATCH] vultr: delete ipv4 if instance is gone This commit fixes an issue where the provider errors out if the user manually deletes an instance with attached IPv4 resources. In this case, the provider would be unable to find the underlying instance, causing the IPv4 state read to fail. Instead, since IPv4s must be associated with an instance and are deleted when the instance is destroyed, assume that the resources are gone if the instance cannot be found. --- vultr/resource_ipv4.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vultr/resource_ipv4.go b/vultr/resource_ipv4.go index 2953432f..3b336db1 100644 --- a/vultr/resource_ipv4.go +++ b/vultr/resource_ipv4.go @@ -111,6 +111,11 @@ func resourceIPV4Read(d *schema.ResourceData, meta interface{}) error { ips, err := client.ListIPv4(instance) if err != nil { + if strings.HasPrefix(err.Error(), "Invalid server.") { + log.Printf("[WARN] Removing IPv4 address (%s) because the attached instance (%s) is gone", d.Id(), instance) + d.SetId("") + return nil + } return fmt.Errorf("Error getting IPv4 addresses: %v", err) } var ip *lib.IPv4 @@ -124,7 +129,6 @@ func resourceIPV4Read(d *schema.ResourceData, meta interface{}) error { log.Printf("[WARN] Removing IPv4 address (%s) because it is gone", d.Id()) d.SetId("") return nil - } d.Set("gateway", ip.Gateway)