fix: Fixed handling of removed resources when reading from client
This commit is contained in:
parent
3ad1d4ec60
commit
ec291c6447
8 changed files with 22 additions and 10 deletions
4
go.mod
4
go.mod
|
|
@ -1,9 +1,9 @@
|
||||||
module github.com/DevFW-CICD/terraform-provider-edge-connect
|
module edp.buildth.ing/DevFW-CICD/terraform-provider-edge-connect
|
||||||
|
|
||||||
go 1.25.3
|
go 1.25.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.1
|
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.2
|
||||||
github.com/hashicorp/terraform-plugin-framework v1.16.1
|
github.com/hashicorp/terraform-plugin-framework v1.16.1
|
||||||
github.com/hashicorp/terraform-plugin-log v0.9.0
|
github.com/hashicorp/terraform-plugin-log v0.9.0
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -1,5 +1,5 @@
|
||||||
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.1 h1:4UqNkRb0d7kpsCpj6b+U4zZD8EEMi7AMspMrxstHcjE=
|
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.2 h1:g1iY/8Au4T6UV6cFm8/SQXAAF+DvFcjR6Hb0TqTF064=
|
||||||
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.1/go.mod h1:nPZ4K4BB7eXyeSrcHXvSPkNZbs+XgmxbDJOM4KhbI1A=
|
edp.buildth.ing/DevFW-CICD/edge-connect-client/v2 v2.1.2/go.mod h1:nPZ4K4BB7eXyeSrcHXvSPkNZbs+XgmxbDJOM4KhbI1A=
|
||||||
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
|
||||||
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
|
||||||
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ datasource.DataSource = &AppDataSource{}
|
var _ datasource.DataSource = &AppDataSource{}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package provider
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||||
|
|
@ -14,7 +15,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
|
||||||
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ resource.Resource = &AppResource{}
|
var _ resource.Resource = &AppResource{}
|
||||||
|
|
@ -266,6 +267,11 @@ func (r *AppResource) Read(ctx context.Context, req resource.ReadRequest, resp *
|
||||||
|
|
||||||
app, err := r.client.ShowApp(ctx, appKey, data.Region.ValueString())
|
app, err := r.client.ShowApp(ctx, appKey, data.Region.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
if errors.Is(err, edgeclient.ErrResourceNotFound) {
|
||||||
|
resp.State.RemoveResource(ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app %s, got error: %s", data.Id.ValueString(), err))
|
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app %s, got error: %s", data.Id.ValueString(), err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
|
||||||
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ datasource.DataSource = &AppInstanceDataSource{}
|
var _ datasource.DataSource = &AppInstanceDataSource{}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||||
|
|
@ -12,7 +13,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
|
||||||
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ resource.Resource = &AppInstanceResource{}
|
var _ resource.Resource = &AppInstanceResource{}
|
||||||
|
|
@ -226,6 +227,11 @@ func (r *AppInstanceResource) Read(ctx context.Context, req resource.ReadRequest
|
||||||
|
|
||||||
appInstance, err := r.client.ShowAppInstance(ctx, appInstKey, appKey, data.Region.ValueString())
|
appInstance, err := r.client.ShowAppInstance(ctx, appInstKey, appKey, data.Region.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
|
if errors.Is(err, edgeclient.ErrResourceNotFound) {
|
||||||
|
resp.State.RemoveResource(ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err))
|
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
|
|
||||||
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect"
|
edgeclient "edp.buildth.ing/DevFW-CICD/edge-connect-client/v2/sdk/edgeconnect/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ provider.Provider = &EdgeConnectProvider{}
|
var _ provider.Provider = &EdgeConnectProvider{}
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/DevFW-CICD/terraform-provider-edge-connect/internal/provider"
|
"edp.buildth.ing/DevFW-CICD/terraform-provider-edge-connect/internal/provider"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
"github.com/hashicorp/terraform-plugin-framework/providerserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue