Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ linters:
- predeclared
- revive
- staticcheck
- tenv
- usetesting
- unconvert
- unparam
- unused
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/destination_filter_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"
"regexp"
"strings"

Expand Down Expand Up @@ -201,6 +202,12 @@ func (r *destinationFilterResource) Read(ctx context.Context, req resource.ReadR
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Destination Filter (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/destination_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
Expand Down Expand Up @@ -587,6 +588,12 @@ func (r *destinationResource) Read(ctx context.Context, req resource.ReadRequest
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Destination (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/destination_subscription_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
Expand Down Expand Up @@ -228,6 +229,12 @@ func (r *destinationSubscriptionResource) Read(ctx context.Context, req resource
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Destination subscription (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/function_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"
"regexp"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
Expand Down Expand Up @@ -189,6 +190,12 @@ func (r *functionResource) Read(ctx context.Context, req resource.ReadRequest, r
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Function (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/insert_function_instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"
"strings"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
Expand Down Expand Up @@ -159,6 +160,12 @@ func (r *insertFunctionInstanceResource) Read(ctx context.Context, req resource.
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Insert Function instance (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
5 changes: 1 addition & 4 deletions internal/provider/label_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ func (r *labelResource) Read(ctx context.Context, req resource.ReadRequest, resp
}

if label == nil {
resp.Diagnostics.AddError(
"Unable to find Label",
fmt.Sprintf("Unable to find Label with key: %q and value: %q", state.Key, state.Value),
)
resp.State.RemoveResource(ctx)

return
}
Expand Down
7 changes: 3 additions & 4 deletions internal/provider/profiles_warehouse_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (r *profilesWarehouseResource) Read(ctx context.Context, req resource.ReadR

warehouse, err := findProfileWarehouse(r.authContext, r.client, previousState.ID.ValueString(), previousState.SpaceID.ValueString())
if err != nil {
resp.State.RemoveResource(ctx)

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Profiles Warehouse (ID: %s)", previousState.ID.ValueString()),
err.Error(),
Expand All @@ -176,10 +178,7 @@ func (r *profilesWarehouseResource) Read(ctx context.Context, req resource.ReadR
}

if warehouse == nil {
resp.Diagnostics.AddError(
"Unable to find Profile Warehouse",
fmt.Sprintf("Profile Warehouse with id '%s' and space id '%s' not found", previousState.ID.ValueString(), previousState.SpaceID.ValueString()),
)
resp.State.RemoveResource(ctx)

return
}
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/reverse_etl_model_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
"github.com/segmentio/terraform-provider-segment/internal/provider/models"
Expand Down Expand Up @@ -160,6 +161,12 @@ func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadReq
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Reverse ETL model (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/source_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
Expand Down Expand Up @@ -387,6 +388,12 @@ func (r *sourceResource) Read(ctx context.Context, req resource.ReadRequest, res
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Source (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"strings"

"github.com/avast/retry-go/v4"
Expand Down Expand Up @@ -255,6 +256,12 @@ func (r *sourceTrackingPlanConnectionResource) Read(ctx context.Context, req res
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Source (ID: %s)", previousState.SourceID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/source_warehouse_connection_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -126,6 +127,12 @@ func (r *sourceWarehouseConnectionResource) Read(ctx context.Context, req resour
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
"Unable to read Source-Warehouse connection",
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/tracking_plan_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
"github.com/segmentio/terraform-provider-segment/internal/provider/models"
Expand Down Expand Up @@ -227,6 +228,12 @@ func (r *trackingPlanResource) Read(ctx context.Context, req resource.ReadReques
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Tracking Plan (ID: %s)", config.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/transformation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
"github.com/segmentio/terraform-provider-segment/internal/provider/models"
Expand Down Expand Up @@ -206,6 +207,12 @@ func (r *transformationResource) Read(ctx context.Context, req resource.ReadRequ
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound || body.StatusCode == http.StatusForbidden {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Transformation (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/user_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"
"regexp"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
Expand Down Expand Up @@ -238,6 +239,12 @@ func (r *userGroupResource) Read(ctx context.Context, req resource.ReadRequest,
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read User Group (ID: %s)", config.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"regexp"

"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
Expand Down Expand Up @@ -259,6 +260,12 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read user (ID: %s)", state.ID.ValueString()),
getError(err, body),
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/warehouse_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"net/http"

"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
"github.com/segmentio/terraform-provider-segment/internal/provider/models"
Expand Down Expand Up @@ -288,6 +289,12 @@ func (r *warehouseResource) Read(ctx context.Context, req resource.ReadRequest,
defer body.Body.Close()
}
if err != nil {
if body.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)

return
}

resp.Diagnostics.AddError(
fmt.Sprintf("Unable to read Warehouse (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
Expand Down
Loading