Skip to content

Commit

Permalink
vultr/resource*: cleanup and standardize 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
squat committed Nov 17, 2018
1 parent 59cbee0 commit 74c2fad
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion vultr/resource_bare_metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func resourceBareMetalRead(d *schema.ResourceData, meta interface{}) error {

instance, err := client.GetBareMetalServer(d.Id())
if err != nil {
if err.Error() == "Invalid server." {
if strings.HasPrefix(err.Error(), "Invalid server") {
log.Printf("[WARN] Removing bare metal instance (%s) because it is gone", d.Id())
d.Set("status", "none")
d.SetId("")
Expand Down
5 changes: 3 additions & 2 deletions vultr/resource_block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vultr
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func resourceBlockStorageRead(d *schema.ResourceData, meta interface{}) error {

storage, err := client.GetBlockStorage(d.Id())
if err != nil {
if err.Error() == "Invalid block storage." {
if strings.HasPrefix(err.Error(), "Invalid block storage") {
log.Printf("[WARN] Removing block storage (%s) because it is gone", d.Id())
d.SetId("")
return nil
Expand Down Expand Up @@ -161,7 +162,7 @@ func resourceBlockStorageDelete(d *schema.ResourceData, meta interface{}) error
}
}
if err := client.DeleteBlockStorage(d.Id()); err != nil {
return fmt.Errorf("Error block storage (%s): %v", d.Id(), err)
return fmt.Errorf("Error destroying block storage (%s): %v", d.Id(), err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion vultr/resource_dns_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func resourceDNSDomainRead(d *schema.ResourceData, meta interface{}) error {
// Find the default record for the domain.
records, err := client.GetDNSRecords(dnsDomain.Domain)
if err != nil {
if strings.HasPrefix(err.Error(), "Invalid domain.") {
if strings.HasPrefix(err.Error(), "Invalid domain") {
log.Printf("[WARN] Removing DNS domain (%s) because it has no default record", d.Id())
d.SetId("")
return nil
Expand Down
2 changes: 1 addition & 1 deletion vultr/resource_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func resourceDNSRecordRead(d *schema.ResourceData, meta interface{}) error {

records, err := client.GetDNSRecords(domain)
if err != nil {
if strings.HasPrefix(err.Error(), "Invalid domain.") {
if strings.HasPrefix(err.Error(), "Invalid domain") {
log.Printf("[WARN] Removing DNS record (%s) because the domain is gone", d.Id())
d.SetId("")
return nil
Expand Down
3 changes: 2 additions & 1 deletion vultr/resource_firewall_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vultr
import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -60,7 +61,7 @@ func resourceFirewallGroupRead(d *schema.ResourceData, meta interface{}) error {

firewallGroup, err := client.GetFirewallGroup(d.Id())
if err != nil {
if err.Error() == fmt.Sprintf("Firewall group with ID %v not found", d.Id()) {
if strings.HasPrefix(err.Error(), fmt.Sprintf("Firewall group with ID %v not found", d.Id())) {
log.Printf("[WARN] Removing firewall group (%s) because it is gone", d.Id())
d.SetId("")
return nil
Expand Down
4 changes: 2 additions & 2 deletions vultr/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error {

instance, err := client.GetServer(d.Id())
if err != nil {
if err.Error() == "Invalid server." {
if strings.HasPrefix(err.Error(), "Invalid server") {
log.Printf("[WARN] Removing instance (%s) because it is gone", d.Id())
d.SetId("")
return nil
Expand Down Expand Up @@ -438,7 +438,7 @@ func resourceInstanceDelete(d *schema.ResourceData, meta interface{}) error {
}

// Server does not exist so it has been deleted.
if strings.HasPrefix(err.Error(), "Invalid server.") {
if strings.HasPrefix(err.Error(), "Invalid server") {
break
}
// There was a legitimate error.
Expand Down
2 changes: 1 addition & 1 deletion vultr/resource_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func resourceIPV4Read(d *schema.ResourceData, meta interface{}) error {

ips, err := client.ListIPv4(instance)
if err != nil {
if strings.HasPrefix(err.Error(), "Invalid server.") {
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
Expand Down
12 changes: 6 additions & 6 deletions vultr/resource_reserved_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vultr
import (
"fmt"
"log"
"strings"

"github.com/JamesClonk/vultr/lib"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -87,15 +88,14 @@ func resourceReservedIPRead(d *schema.ResourceData, meta interface{}) error {

rip, err := client.GetReservedIP(d.Id())
if err != nil {
if strings.HasPrefix(err.Error(), fmt.Sprintf("IP with ID %v not found", d.Id())) {
log.Printf("[WARN] Removing reserved ip (%s) because it is gone", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("Error getting reserved ip (%s): %v", d.Id(), err)
}

if rip == (lib.IP{}) {
log.Printf("[WARN] Removing reserved ip (%s) because it is gone", d.Id())
d.SetId("")
return nil
}

d.Set("attached_id", rip.AttachedTo)
d.Set("cidr", reservedIPToCIDR(rip))
d.Set("name", rip.Label)
Expand Down

0 comments on commit 74c2fad

Please sign in to comment.