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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
terraform_wrapper: false

- name: Run linters
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
uses: golangci/golangci-lint-action@v8.0.0
with:
args: --timeout 3m

Expand All @@ -67,7 +67,7 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Run linters
uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
uses: golangci/golangci-lint-action@v8.0.0
with:
args: --timeout 3m

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace.xml
**/.terraform
**/terraform.tfstate
**/terraform.tfstate.backup
**/.terraform.tfstate.lock.info

# Coverage related report file(s)
coverage.*
Expand Down
59 changes: 35 additions & 24 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
---
version: "2"
run:
tests: true

output:
formats:
text:
path: stdout
print-issued-lines: true
linters:
disable-all: true
default: none
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gci

linters-settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/cloudera/terraform-provider-cdp) # Custom section: groups all imports with the specified Prefix.
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
# Skip generated files.
# Default: true
skip-generated: true

output:
formats:
- format: colored-line-number
path: stdout
print-issued-lines: true

exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gci
settings:
gci:
sections:
- standard
- default
- prefix(github.com/cloudera/terraform-provider-cdp)
- blank
- dot
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion resources/datahub/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func checkIfClusterCreationFailed(resp *operations.DescribeClusterOK) (interface{}, string, error) {
if utils.ContainsAsSubstring(failedStatusKeywords, resp.GetPayload().Cluster.Status) {
return nil, "", fmt.Errorf("Cluster status became unacceptable: %s", resp.GetPayload().Cluster.Status)
return nil, "", fmt.Errorf("cluster status became unacceptable: %s", resp.GetPayload().Cluster.Status)
}
return resp, resp.GetPayload().Cluster.Status, nil
}
Expand Down
2 changes: 1 addition & 1 deletion resources/datalake/resource_aws_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *awsDatalakeResource) Create(ctx context.Context, req resource.CreateReq
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
stateSaver := func(dlDtl *datalakemodels.DatalakeDetails) {
datalakeDetailsToAwsDatalakeResourceModel(ctx, dlDtl, &state, state.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, state)
Expand Down
2 changes: 1 addition & 1 deletion resources/datalake/resource_azure_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *azureDatalakeResource) Create(ctx context.Context, req resource.CreateR
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
stateSaver := func(dlDtl *datalakemodels.DatalakeDetails) {
datalakeDetailsToAzureDatalakeResourceModel(ctx, dlDtl, &state, state.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, state)
Expand Down
2 changes: 1 addition & 1 deletion resources/datalake/resource_gcp_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (r *gcpDatalakeResource) Create(ctx context.Context, req resource.CreateReq
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
stateSaver := func(dlDtl *datalakemodels.DatalakeDetails) {
datalakeDetailsToGcpDatalakeResourceModel(ctx, dlDtl, &state, state.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, state)
Expand Down
4 changes: 2 additions & 2 deletions resources/dw/cluster/aws/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (r *dwClusterResource) Create(ctx context.Context, req resource.CreateReque
return
}

if !(plan.PollingOptions != nil && plan.PollingOptions.Async.ValueBool()) {
if plan.PollingOptions == nil || !plan.PollingOptions.Async.ValueBool() {
callFailedCount := 0
stateConf := &retry.StateChangeConf{
Pending: []string{"Accepted", "Creating", "Created", "Starting"},
Expand Down Expand Up @@ -168,7 +168,7 @@ func (r *dwClusterResource) Delete(ctx context.Context, req resource.DeleteReque
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
callFailedCount := 0
stateConf := &retry.StateChangeConf{
Pending: []string{"Deleting", "Running"},
Expand Down
2 changes: 1 addition & 1 deletion resources/dw/databasecatalog/resource_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *dwDatabaseCatalogResource) Create(ctx context.Context, req resource.Cre

clusterID := plan.ClusterID.ValueStringPointer()

if opts := plan.PollingOptions; !(opts != nil && opts.Async.ValueBool()) {
if opts := plan.PollingOptions; opts == nil || !opts.Async.ValueBool() {
callFailedCount := 0
stateConf := &retry.StateChangeConf{
Pending: []string{"Accepted", "Creating", "Created", "Loading", "Starting"},
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/converter_freeipa.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func FreeIpaResponseToModel(ipaResp *environmentsmodels.FreeipaDetails, model *t
Instances: ipaInstances,
MultiAz: types.BoolValue(ipaResp.MultiAz),
Recipes: recipes,
Architecture: types.StringValue(freeIpaDetails.Architecture.ValueString()),
Architecture: getStringValueIfNotEmpty(freeIpaDetails.Architecture.ValueString()),
})
diags.Append(ipaDiags...)

Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_aws_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *awsEnvironmentResource) Create(ctx context.Context, req resource.Create
if err != nil {
return
}
if !(data.PollingOptions != nil && data.PollingOptions.Async.ValueBool()) {
if data.PollingOptions == nil || !data.PollingOptions.Async.ValueBool() {
stateSaver := func(env *environmentsmodels.Environment) {
toAwsEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, env, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, data)
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_azure_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *azureEnvironmentResource) Create(ctx context.Context, req resource.Crea
if err != nil {
return
}
if !(data.PollingOptions != nil && data.PollingOptions.Async.ValueBool()) {
if data.PollingOptions == nil || !data.PollingOptions.Async.ValueBool() {
stateSaver := func(env *environmentsmodels.Environment) {
toAzureEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, env, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, data)
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_gcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *gcpEnvironmentResource) Create(ctx context.Context, req resource.Create
if err != nil {
return
}
if !(data.PollingOptions != nil && data.PollingOptions.Async.ValueBool()) {
if data.PollingOptions == nil || !data.PollingOptions.Async.ValueBool() {
stateSaver := func(env *environmentsmodels.Environment) {
toGcpEnvironmentResource(ctx, utils.LogEnvironmentSilently(ctx, env, describeLogPrefix), &data, data.PollingOptions, &resp.Diagnostics)
diags = resp.State.Set(ctx, data)
Expand Down
2 changes: 1 addition & 1 deletion resources/environments/resource_user_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (r *userSyncResource) Create(ctx context.Context, req resource.CreateReques

opID := res.Payload.OperationID
tflog.Debug(ctx, fmt.Sprintf("User sync operation ID: %s", *opID))
if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
tflog.Debug(ctx, "User sync polling starts")
err = waitForUserSync(*opID, time.Hour*1, callFailureThreshold, r.client.Environments, ctx, state.PollingOptions)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions resources/environments/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"context"
"fmt"
"math"
"strings"

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
Expand Down Expand Up @@ -71,3 +72,11 @@ func safeIntToInt32(n int) (int32, error) {
}
return int32(n), nil
}

func getStringValueIfNotEmpty(s string) types.String {
val := strings.TrimSpace(s)
if len(val) > 0 {
return types.StringValue(val)
}
return types.StringNull()
}
33 changes: 33 additions & 0 deletions resources/environments/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@ func TestConvertTagsWhenInputIsEmpty(t *testing.T) {
}
}

func TestGetStringValueIfNotEmpty(t *testing.T) {
tests := []struct {
name string
input string
expected types.String
}{
{
name: "Empty string",
input: "",
expected: types.StringNull(),
},
{
name: "Normal content",
input: "arm",
expected: types.StringValue("arm"),
},
{
name: "String with spaces",
input: " ",
expected: types.StringNull(),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := getStringValueIfNotEmpty(tt.input)
if result != tt.expected {
t.Errorf("Unexpected result for input '%s'. Expected: %v, got: %v", tt.input, tt.expected, result)
}
})
}
}

func TestConvertTagsWhenInputIsNotEmpty(t *testing.T) {
key, value := "someKey-1", "someValue-1"
inMap, _ := types.MapValue(types.StringType, map[string]attr.Value{key: types.StringValue(value)})
Expand Down
6 changes: 3 additions & 3 deletions resources/opdb/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
return
}

if !(data.PollingOptions != nil && data.PollingOptions.Async.ValueBool()) {
if data.PollingOptions == nil || !data.PollingOptions.Async.ValueBool() {
status, err := waitForToBeAvailable(data.DatabaseName.ValueString(), data.Environment.ValueString(), r.client.Opdb, ctx, data.PollingOptions)
tflog.Debug(ctx, fmt.Sprintf("Database polling finished, setting status from '%s' to '%s'", data.Status.ValueString(), status))
data.Status = types.StringValue(status)
Expand Down Expand Up @@ -189,7 +189,7 @@ func (r *databaseResource) Update(ctx context.Context, req resource.UpdateReques
return
}

if !(data.PollingOptions != nil && data.PollingOptions.Async.ValueBool()) {
if data.PollingOptions == nil || !data.PollingOptions.Async.ValueBool() {
status, err := waitForToBeAvailable(data.DatabaseName.ValueString(), data.Environment.ValueString(), r.client.Opdb, ctx, data.PollingOptions)
tflog.Debug(ctx, fmt.Sprintf("Database polling finished, setting status from '%s' to '%s'", data.Status.ValueString(), status))
data.Status = types.StringValue(status)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques
return
}

if !(state.PollingOptions != nil && state.PollingOptions.Async.ValueBool()) {
if state.PollingOptions == nil || !state.PollingOptions.Async.ValueBool() {
err = waitForToBeDeleted(state.DatabaseName.ValueString(), state.Environment.ValueString(), r.client.Opdb, ctx, state.PollingOptions)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion resources/opdb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func checkIfDatabaseCreationFailed(resp *operations.DescribeDatabaseOK) (interface{}, string, error) {
if utils.ContainsAsSubstring(failedStatusKeywords, string(resp.GetPayload().DatabaseDetails.Status)) {
return nil, "", fmt.Errorf("Cluster status became unacceptable: %s", types.StringValue(string(resp.GetPayload().DatabaseDetails.Status)))
return nil, "", fmt.Errorf("cluster status became unacceptable: %s", types.StringValue(string(resp.GetPayload().DatabaseDetails.Status)))
}
return resp, string(resp.GetPayload().DatabaseDetails.Status), nil
}
Expand Down
Loading