Skip to content

Commit

Permalink
Merge pull request #59 from latitudesh/fix/refresh-state-404
Browse files Browse the repository at this point in the history
Fix: Error when refreshing state
  • Loading branch information
ynhummel authored Feb 26, 2024
2 parents d305c46 + e7577a0 commit 24b8da7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
8 changes: 7 additions & 1 deletion latitudesh/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package latitudesh
import (
"context"
"errors"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -84,8 +85,13 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, m interfac

projectID := d.Id()

project, _, err := c.Projects.Get(projectID, nil)
project, resp, err := c.Projects.Get(projectID, nil)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down
8 changes: 7 additions & 1 deletion latitudesh/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latitudesh

import (
"context"
"net/http"
"strconv"
"time"

Expand Down Expand Up @@ -131,8 +132,13 @@ func resourceServerRead(ctx context.Context, d *schema.ResourceData, m interface

serverID := d.Id()

server, _, err := c.Servers.Get(serverID, nil)
server, resp, err := c.Servers.Get(serverID, nil)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down
8 changes: 7 additions & 1 deletion latitudesh/resource_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latitudesh

import (
"context"
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -83,8 +84,13 @@ func resourceSSHKeyRead(ctx context.Context, d *schema.ResourceData, m interface

keyID := d.Id()

key, _, err := c.SSHKeys.Get(keyID, d.Get("project").(string), nil)
key, resp, err := c.SSHKeys.Get(keyID, d.Get("project").(string), nil)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down
8 changes: 7 additions & 1 deletion latitudesh/resource_user_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latitudesh

import (
"context"
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -83,8 +84,13 @@ func resourceUserDataRead(ctx context.Context, d *schema.ResourceData, m interfa

userDataID := d.Id()

userData, _, err := c.UserData.Get(userDataID, d.Get("project").(string), nil)
userData, resp, err := c.UserData.Get(userDataID, d.Get("project").(string), nil)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down
8 changes: 7 additions & 1 deletion latitudesh/resource_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latitudesh

import (
"context"
"net/http"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -84,8 +85,13 @@ func resourceVirtualNetworkRead(ctx context.Context, d *schema.ResourceData, m i

virtualNetworkID := d.Id()

virtualNetwork, _, err := c.VirtualNetworks.Get(virtualNetworkID, nil)
virtualNetwork, resp, err := c.VirtualNetworks.Get(virtualNetworkID, nil)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down
8 changes: 7 additions & 1 deletion latitudesh/resource_vlan_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latitudesh

import (
"context"
"net/http"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -92,8 +93,13 @@ func resourceVlanAssignmentRead(ctx context.Context, d *schema.ResourceData, m i

vlanAssignmentID := d.Id()

vlanAssignment, _, err := c.VlanAssignments.Get(vlanAssignmentID)
vlanAssignment, resp, err := c.VlanAssignments.Get(vlanAssignmentID)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
d.SetId("")
return diags
}

return diag.FromErr(err)
}

Expand Down

0 comments on commit 24b8da7

Please sign in to comment.