Skip to content

Commit 419ef6c

Browse files
committed
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.
1 parent 80a336f commit 419ef6c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

vultr/resource_ipv4.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func resourceIPV4Read(d *schema.ResourceData, meta interface{}) error {
111111

112112
ips, err := client.ListIPv4(instance)
113113
if err != nil {
114+
if strings.HasPrefix(err.Error(), "Invalid server.") {
115+
log.Printf("[WARN] Removing IPv4 address (%s) because the attached instance (%s) is gone", d.Id(), instance)
116+
d.SetId("")
117+
return nil
118+
}
114119
return fmt.Errorf("Error getting IPv4 addresses: %v", err)
115120
}
116121
var ip *lib.IPv4
@@ -124,7 +129,6 @@ func resourceIPV4Read(d *schema.ResourceData, meta interface{}) error {
124129
log.Printf("[WARN] Removing IPv4 address (%s) because it is gone", d.Id())
125130
d.SetId("")
126131
return nil
127-
128132
}
129133

130134
d.Set("gateway", ip.Gateway)

0 commit comments

Comments
 (0)