Skip to content

Commit

Permalink
empty state resource when remote doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobioz committed Mar 12, 2021
1 parent f61e83e commit 9585a75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion geoserver/resource_geoserver_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ func resourceGeoserverDatastoreRead(d *schema.ResourceData, meta interface{}) er
client := meta.(*Config).Client()

datastore, err := client.GetDatastore(workspaceName, datastoreName)
if err != nil {
if err != nil && err.Error() != "Not Found" {
return err
}

if datastore == nil {
d.SetId("")
return nil
}

d.Set("workspace_name", datastore.Workspace.Name)
d.Set("name", datastore.Name)
d.Set("description", datastore.Description)
Expand Down
6 changes: 5 additions & 1 deletion geoserver/resource_geoserver_featuretype.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ func resourceGeoserverFeatureTypeRead(d *schema.ResourceData, meta interface{})
client := meta.(*Config).Client()

featureType, err := client.GetFeatureType(workspaceName, datastoreName, featureTypeName)
if err != nil {
if err != nil && err.Error() != "Not Found" {
return err
}

if featureType == nil {
d.SetId("")
return nil
}
d.Set("workspace_name", workspaceName)
d.Set("datastore_name", datastoreName)
d.Set("name", featureType.Name)
Expand Down
7 changes: 6 additions & 1 deletion geoserver/resource_geoserver_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ func resourceGeoserverWorkspaceRead(d *schema.ResourceData, meta interface{}) er
client := meta.(*Config).Client()

workspace, err := client.GetWorkspace(d.Id())
if err != nil {
if err != nil && err.Error() != "Not Found" {
return err
}

if workspace == nil {
d.SetId("")
return nil
}

d.Set("name", workspace.Name)
d.Set("isolated", workspace.Isolated)

Expand Down

0 comments on commit 9585a75

Please sign in to comment.