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
4 changes: 2 additions & 2 deletions internal/apm/agent_configuration/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -53,7 +53,7 @@ func (r *resourceAgentConfiguration) Create(ctx context.Context, req resource.Cr
}
defer apiResp.Body.Close()

if diags := utils.CheckHttpErrorFromFW(apiResp, "Failed to create APM agent configuration"); diags.HasError() {
if diags := diagutil.CheckHttpErrorFromFW(apiResp, "Failed to create APM agent configuration"); diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/apm/agent_configuration/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func (r *resourceAgentConfiguration) Delete(ctx context.Context, req resource.De
}
defer apiResp.Body.Close()

if diags := utils.CheckHttpErrorFromFW(apiResp, "Failed to delete APM agent configuration"); diags.HasError() {
if diags := diagutil.CheckHttpErrorFromFW(apiResp, "Failed to delete APM agent configuration"); diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/apm/agent_configuration/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (r *resourceAgentConfiguration) read(ctx context.Context, state *AgentConfi
return nil, diags
}

if httpDiags := utils.CheckHttpErrorFromFW(apiResp.HTTPResponse, "Failed to get APM agent configurations"); httpDiags.HasError() {
if httpDiags := diagutil.CheckHttpErrorFromFW(apiResp.HTTPResponse, "Failed to get APM agent configurations"); httpDiags.HasError() {
diags.Append(httpDiags...)
return nil, diags
}
Expand Down
4 changes: 2 additions & 2 deletions internal/apm/agent_configuration/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -51,7 +51,7 @@ func (r *resourceAgentConfiguration) Update(ctx context.Context, req resource.Up
}
defer apiResp.Body.Close()

if diags := utils.CheckHttpErrorFromFW(apiResp, "Failed to update APM agent configuration"); diags.HasError() {
if diags := diagutil.CheckHttpErrorFromFW(apiResp, "Failed to update APM agent configuration"); diags.HasError() {
resp.Diagnostics.Append(diags...)
return
}
Expand Down
5 changes: 3 additions & 2 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/elastic/terraform-provider-elasticstack/internal/clients/config"
"github.com/elastic/terraform-provider-elasticstack/internal/clients/fleet"
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/elastic/terraform-provider-elasticstack/internal/models"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -53,7 +54,7 @@ func CompositeIdFromStr(id string) (*CompositeId, diag.Diagnostics) {

func CompositeIdFromStrFw(id string) (*CompositeId, fwdiags.Diagnostics) {
composite, diags := CompositeIdFromStr(id)
return composite, utils.FrameworkDiagsFromSDK(diags)
return composite, diagutil.FrameworkDiagsFromSDK(diags)
}

func ResourceIDFromStr(id string) (string, diag.Diagnostics) {
Expand Down Expand Up @@ -323,7 +324,7 @@ func (a *ApiClient) serverInfo(ctx context.Context) (*models.ClusterInfo, diag.D
return nil, diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to connect to the Elasticsearch cluster"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to connect to the Elasticsearch cluster"); diags.HasError() {
return nil, diags
}

Expand Down
26 changes: 13 additions & 13 deletions internal/clients/elasticsearch/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"

"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/elastic/terraform-provider-elasticstack/internal/models"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

Expand All @@ -24,7 +24,7 @@ func GetClusterInfo(ctx context.Context, apiClient *clients.ApiClient) (*models.
return nil, diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to connect to the Elasticsearch cluster"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to connect to the Elasticsearch cluster"); diags.HasError() {
return nil, diags
}

Expand All @@ -50,7 +50,7 @@ func PutSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient, re
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to create or update the snapshot repository"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to create or update the snapshot repository"); diags.HasError() {
return diags
}

Expand All @@ -72,7 +72,7 @@ func GetSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient, na
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
if diags := utils.CheckError(res, fmt.Sprintf("Unable to get the information about snapshot repository: %s", name)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to get the information about snapshot repository: %s", name)); diags.HasError() {
return nil, diags
}
snapRepoResponse := make(map[string]models.SnapshotRepository)
Expand Down Expand Up @@ -106,7 +106,7 @@ func DeleteSnapshotRepository(ctx context.Context, apiClient *clients.ApiClient,
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, fmt.Sprintf("Unable to delete snapshot repository: %s", name)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to delete snapshot repository: %s", name)); diags.HasError() {
return diags
}
return diags
Expand All @@ -129,7 +129,7 @@ func PutSlm(ctx context.Context, apiClient *clients.ApiClient, slm *models.Snaps
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to create or update the SLM"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to create or update the SLM"); diags.HasError() {
return diags
}

Expand All @@ -151,7 +151,7 @@ func GetSlm(ctx context.Context, apiClient *clients.ApiClient, slmName string) (
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
if diags := utils.CheckError(res, "Unable to get SLM policy from ES API"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to get SLM policy from ES API"); diags.HasError() {
return nil, diags
}
type SlmResponse = map[string]struct {
Expand Down Expand Up @@ -183,7 +183,7 @@ func DeleteSlm(ctx context.Context, apiClient *clients.ApiClient, slmName string
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, fmt.Sprintf("Unable to delete SLM policy: %s", slmName)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to delete SLM policy: %s", slmName)); diags.HasError() {
return diags
}

Expand All @@ -205,7 +205,7 @@ func PutSettings(ctx context.Context, apiClient *clients.ApiClient, settings map
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to update cluster settings."); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to update cluster settings."); diags.HasError() {
return diags
}
return diags
Expand All @@ -223,7 +223,7 @@ func GetSettings(ctx context.Context, apiClient *clients.ApiClient) (map[string]
return nil, diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to read cluster settings."); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to read cluster settings."); diags.HasError() {
return nil, diags
}

Expand All @@ -247,7 +247,7 @@ func GetScript(ctx context.Context, apiClient *clients.ApiClient, id string) (*m
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
if diags := utils.CheckError(res, fmt.Sprintf("Unable to get stored script: %s", id)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to get stored script: %s", id)); diags.HasError() {
return nil, diags
}
var scriptResponse struct {
Expand Down Expand Up @@ -279,7 +279,7 @@ func PutScript(ctx context.Context, apiClient *clients.ApiClient, script *models
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, "Unable to put stored script"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to put stored script"); diags.HasError() {
return diags
}
return nil
Expand All @@ -295,7 +295,7 @@ func DeleteScript(ctx context.Context, apiClient *clients.ApiClient, id string)
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, fmt.Sprintf("Unable to delete script: %s", id)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to delete script: %s", id)); diags.HasError() {
return diags
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions internal/clients/elasticsearch/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"

"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/elastic/terraform-provider-elasticstack/internal/models"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
Expand Down Expand Up @@ -54,7 +54,7 @@ func GetEnrichPolicy(ctx context.Context, apiClient *clients.ApiClient, policyNa
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
if diags := utils.CheckError(res, fmt.Sprintf("Unable to get requested EnrichPolicy: %s", policyName)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to get requested EnrichPolicy: %s", policyName)); diags.HasError() {
return nil, diags
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func PutEnrichPolicy(ctx context.Context, apiClient *clients.ApiClient, policy *
}
defer res.Body.Close()

if diags := utils.CheckError(res, "Unable to create enrich policy"); diags.HasError() {
if diags := diagutil.CheckError(res, "Unable to create enrich policy"); diags.HasError() {
return diags
}
return diags
Expand All @@ -149,7 +149,7 @@ func DeleteEnrichPolicy(ctx context.Context, apiClient *clients.ApiClient, polic
return diag.FromErr(err)
}
defer res.Body.Close()
if diags := utils.CheckError(res, fmt.Sprintf("Unable to delete enrich policy: %s", policyName)); diags.HasError() {
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to delete enrich policy: %s", policyName)); diags.HasError() {
return diags
}

Expand Down
Loading
Loading