Skip to content

Commit

Permalink
vultr: delete ipv4 if instance is gone
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
squat committed May 26, 2018
1 parent 80a336f commit 419ef6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vultr/resource_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 419ef6c

Please sign in to comment.