From ec291c6447fa1775eb0542cf5e0b1b8844ad423b Mon Sep 17 00:00:00 2001 From: Patrick Sy Date: Mon, 17 Nov 2025 16:31:11 +0100 Subject: [PATCH 1/2] fix: Fixed handling of removed resources when reading from client --- go.mod | 4 ++-- go.sum | 4 ++-- internal/provider/app_data_source.go | 2 +- internal/provider/app_resource.go | 8 +++++++- internal/provider/appinst_data_source.go | 2 +- internal/provider/appinst_resource.go | 8 +++++++- internal/provider/provider.go | 2 +- main.go | 2 +- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 8c226a7..ca742a4 100644 --- a/go.mod +++ b/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 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-log v0.9.0 ) diff --git a/go.sum b/go.sum index fb160c6..a87b49f 100644 --- a/go.sum +++ b/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.1/go.mod h1:nPZ4K4BB7eXyeSrcHXvSPkNZbs+XgmxbDJOM4KhbI1A= +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.2/go.mod h1:nPZ4K4BB7eXyeSrcHXvSPkNZbs+XgmxbDJOM4KhbI1A= 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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/provider/app_data_source.go b/internal/provider/app_data_source.go index 676789e..0c2a6fc 100644 --- a/internal/provider/app_data_source.go +++ b/internal/provider/app_data_source.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "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{} diff --git a/internal/provider/app_resource.go b/internal/provider/app_resource.go index 6c4fcb1..6454e8f 100644 --- a/internal/provider/app_resource.go +++ b/internal/provider/app_resource.go @@ -3,6 +3,7 @@ package provider import ( "context" "encoding/json" + "errors" "fmt" "github.com/hashicorp/terraform-plugin-framework/path" @@ -14,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "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{} @@ -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()) 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)) return } diff --git a/internal/provider/appinst_data_source.go b/internal/provider/appinst_data_source.go index 35b9844..45f5784 100644 --- a/internal/provider/appinst_data_source.go +++ b/internal/provider/appinst_data_source.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "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{} diff --git a/internal/provider/appinst_resource.go b/internal/provider/appinst_resource.go index 5772a02..b57510d 100644 --- a/internal/provider/appinst_resource.go +++ b/internal/provider/appinst_resource.go @@ -2,6 +2,7 @@ package provider import ( "context" + "errors" "fmt" "github.com/hashicorp/terraform-plugin-framework/path" @@ -12,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "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{} @@ -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()) 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)) return } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6155e0c..0c418e3 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "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{} diff --git a/main.go b/main.go index 10c565f..1fe9f01 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "flag" "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" ) From a39300ce567bf08ffeef68d84b664a20a8c2f27a Mon Sep 17 00:00:00 2001 From: Patrick Sy Date: Mon, 17 Nov 2025 17:11:22 +0100 Subject: [PATCH 2/2] docs(README): Added section about installing local provider binary --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index b3b8798..d2f1b50 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,28 @@ Note: Adjust the path based on your OS and architecture (e.g., `linux_amd64`, `d ### Provider Configuration +As the provider is currently not officially registered for public download, terraform must be configured to use a locally built version. + +To generate the binary run `go install .` from the repository root. This installs the provider binary to `$HOME/go/bin` and means that `terraform init` is not necessary. + +You will also need a `~/.terraformrc` file with the following contents. `` should refer to your `$HOME` directory. + +```hcl +provider_installation { + + dev_overrides { + "local/edge-connect" = "/go/bin" + } + + # For all other providers, install them directly from their origin provider + # registries as normal. If you omit this, Terraform will _only_ use + # the dev_overrides block, and so no other providers will be available. + direct {} +} +``` + +You can then reference the local provider in your `.tf` files as follows: + ```hcl provider "edge-connect" { base_url = "https://edp.buildth.ing"