Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 20 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# increase the default timeout for slow CI needs
run:
timeout: 300s
concurrency: 0
version: "2"
linters:
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,18 @@ install: build ## Install built provider into the local terraform cache


.PHONY: tools
tools: $(GOBIN) ## Install useful tools for linting, docs generation and development
tools: $(GOBIN) tools-golangci-lint ## Install useful tools for linting, docs generation and development
@ cd tools && go install github.com/client9/misspell/cmd/misspell
@ cd tools && go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
@ cd tools && go install github.com/golangci/golangci-lint/cmd/golangci-lint
@ cd tools && go install github.com/goreleaser/goreleaser/v2
@ cd tools && go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
@ cd tools && go install go.uber.org/mock/mockgen

.PHONY: tools-golangci-lint
tools-golangci-lint: ## Download golangci-lint locally if necessary.
@[[ -f $(GOBIN)/golangci-lint ]] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.0.2


.PHONY: misspell
misspell:
@ $(GOBIN)/misspell -error -source go ./internal/
Expand Down
6 changes: 3 additions & 3 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func buildEsClient(cfg config.Client) (*elasticsearch.Client, error) {

es, err := elasticsearch.NewClient(*cfg.Elasticsearch)
if err != nil {
return nil, fmt.Errorf("Unable to create Elasticsearch client: %w", err)
return nil, fmt.Errorf("unable to create Elasticsearch client: %w", err)
}

return es, nil
Expand Down Expand Up @@ -475,7 +475,7 @@ func buildKibanaClient(cfg config.Client) (*kibana.Client, error) {
func buildKibanaOapiClient(cfg config.Client) (*kibana_oapi.Client, error) {
client, err := kibana_oapi.NewClient(*cfg.KibanaOapi)
if err != nil {
return nil, fmt.Errorf("Unable to create KibanaOapi client: %w", err)
return nil, fmt.Errorf("unable to create KibanaOapi client: %w", err)
}

return client, nil
Expand Down Expand Up @@ -539,7 +539,7 @@ func buildSloClient(cfg config.Client, httpClient *http.Client) *slo.APIClient {
func buildFleetClient(cfg config.Client) (*fleet.Client, error) {
client, err := fleet.NewClient(*cfg.Fleet)
if err != nil {
return nil, fmt.Errorf("Unable to create Fleet client: %w", err)
return nil, fmt.Errorf("unable to create Fleet client: %w", err)
}

return client, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/elasticsearch/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func getPolicyType(m map[string]enrichPolicyResponse) (string, error) {
return policyType, nil
}
}
return "", fmt.Errorf("Did not find expected policy type.")
return "", fmt.Errorf("did not find expected policy type")
}

func GetEnrichPolicy(ctx context.Context, apiClient *clients.ApiClient, policyName string) (*models.EnrichPolicy, diag.Diagnostics) {
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/cluster/snapshot_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ func flattenRepoSettings(r *models.SnapshotRepository, s map[string]*schema.Sche
case schema.TypeInt, schema.TypeFloat:
i, err := strconv.Atoi(v.(string))
if err != nil {
return nil, fmt.Errorf(`Failed to parse value = "%v" for setting = "%s"`, v, k)
return nil, fmt.Errorf(`failed to parse value = "%v" for setting = "%s"`, v, k)
}
settings[k] = i
case schema.TypeBool:
b, err := strconv.ParseBool(v.(string))
if err != nil {
return nil, fmt.Errorf(`Failed to parse value = "%v" for setting = "%s"`, v, k)
return nil, fmt.Errorf(`failed to parse value = "%v" for setting = "%s"`, v, k)
}
settings[k] = b
default:
Expand Down
2 changes: 1 addition & 1 deletion internal/elasticsearch/index/index/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (model tfModel) getFieldValueByTagValue(tagName string, t reflect.Type) (at
}

func convertSettingsKeyToTFFieldKey(settingKey string) string {
return strings.Replace(settingKey, ".", "_", -1)
return strings.ReplaceAll(settingKey, ".", "_")
}

func (model aliasTfModel) toAPIModel() (models.IndexAlias, diag.Diagnostics) {
Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/security/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestAccImportedUserDoesNotResetPassword(t *testing.T) {
}
body := fmt.Sprintf("{\"password\": \"%s\"}", userUpdatedPassword)

req := esClient.API.Security.ChangePassword.WithUsername(username)
req := esClient.Security.ChangePassword.WithUsername(username)
resp, err := esClient.Security.ChangePassword(strings.NewReader(body), req)
if err != nil {
return false, nil
Expand Down Expand Up @@ -175,7 +175,7 @@ func checkUserCanAuthenticate(username string, password string) func(*terraform.
credentials := fmt.Sprintf("%s:%s", username, password)
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(credentials)))

req := esClient.API.Security.Authenticate.WithHeader(map[string]string{"Authorization": authHeader})
req := esClient.Security.Authenticate.WithHeader(map[string]string{"Authorization": authHeader})
resp, err := esClient.Security.Authenticate(req)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/kibana/slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestAccResourceSloErrors(t *testing.T) {
}`

budgetingMethodFailConfig := getSLOConfig(sloVars{name: "budgetingmethodfail", indicatorType: "apm_latency_indicator"})
budgetingMethodFailConfig = strings.Replace(budgetingMethodFailConfig, "budgeting_method = \"timeslices\"", "budgeting_method = \"supdawg\"", -1)
budgetingMethodFailConfig = strings.ReplaceAll(budgetingMethodFailConfig, "budgeting_method = \"timeslices\"", "budgeting_method = \"supdawg\"")

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Expand Down
15 changes: 8 additions & 7 deletions internal/kibana/synthetics/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/disaster37/go-kibana-rest/v8/kbapi"
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
Expand All @@ -25,7 +27,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"strconv"
)

const (
Expand Down Expand Up @@ -857,7 +858,7 @@ func (v *tfModelV0) toMonitorFields(ctx context.Context) (kbapi.MonitorFields, d

func toTFAlertConfig(ctx context.Context, v basetypes.ObjectValue) *kbapi.MonitorAlertConfig {
var alert *kbapi.MonitorAlertConfig
if !(v.IsNull() || v.IsUnknown()) {
if !v.IsNull() && !v.IsUnknown() {
tfAlert := tfAlertConfigV0{}
tfsdk.ValueAs(ctx, v, &tfAlert)
alert = tfAlert.toTfAlertConfigV0()
Expand Down Expand Up @@ -899,7 +900,7 @@ func tfInt64ToString(v types.Int64) string {
func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p string) (*kbapi.SSLConfig, diag.Diagnostics) {

var ssl *kbapi.SSLConfig
if !(v.SslSupportedProtocols.IsNull() || v.SslSupportedProtocols.IsUnknown()) {
if !v.SslSupportedProtocols.IsNull() && !v.SslSupportedProtocols.IsUnknown() {
sslSupportedProtocols := utils.ListTypeToSlice_String(ctx, v.SslSupportedProtocols, path.Root(p).AtName("ssl_supported_protocols"), &dg)
if dg.HasError() {
return nil, dg
Expand All @@ -908,7 +909,7 @@ func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p stri
ssl.SupportedProtocols = sslSupportedProtocols
}

if !(v.SslVerificationMode.IsNull() || v.SslVerificationMode.IsUnknown()) {
if !v.SslVerificationMode.IsNull() && !v.SslVerificationMode.IsUnknown() {
if ssl == nil {
ssl = &kbapi.SSLConfig{}
}
Expand All @@ -923,21 +924,21 @@ func toSSLConfig(ctx context.Context, dg diag.Diagnostics, v tfSSLConfig, p stri
ssl.CertificateAuthorities = certAuths
}

if !(v.SslCertificate.IsUnknown() || v.SslCertificate.IsNull()) {
if !v.SslCertificate.IsUnknown() && !v.SslCertificate.IsNull() {
if ssl == nil {
ssl = &kbapi.SSLConfig{}
}
ssl.Certificate = v.SslCertificate.ValueString()
}

if !(v.SslKey.IsUnknown() || v.SslKey.IsNull()) {
if !v.SslKey.IsUnknown() && !v.SslKey.IsNull() {
if ssl == nil {
ssl = &kbapi.SSLConfig{}
}
ssl.Key = v.SslKey.ValueString()
}

if !(v.SslKeyPassphrase.IsUnknown() || v.SslKeyPassphrase.IsNull()) {
if !v.SslKeyPassphrase.IsUnknown() && !v.SslKeyPassphrase.IsNull() {
if ssl == nil {
ssl = &kbapi.SSLConfig{}
}
Expand Down
5 changes: 2 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

providerSchema "github.com/elastic/terraform-provider-elasticstack/internal/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
fwdiag "github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -146,7 +145,7 @@ func ExpandIndividuallyDefinedSettings(ctx context.Context, d *schema.ResourceDa
}

func ConvertSettingsKeyToTFFieldKey(settingKey string) string {
return strings.Replace(settingKey, ".", "_", -1)
return strings.ReplaceAll(settingKey, ".", "_")
}

func Pointer[T any](value T) *T {
Expand Down Expand Up @@ -232,7 +231,7 @@ func ConvertToAttrDiags(diags fwdiag.Diagnostics, path path.Path) fwdiag.Diagnos
for _, d := range diags {
if d.Severity() == fwdiag.SeverityError {
nd.AddAttributeError(path, d.Summary(), d.Detail())
} else if d.Severity() == diag.SeverityWarning {
} else if d.Severity() == fwdiag.SeverityWarning {
nd.AddAttributeWarning(path, d.Summary(), d.Detail())
} else {
nd.Append(d)
Expand Down
Loading
Loading