Skip to content

Commit

Permalink
Fix empty lists issue (#300)
Browse files Browse the repository at this point in the history
* Fix empty lists issue

* Release version
  • Loading branch information
beevital authored Apr 18, 2024
1 parent 73f4236 commit 2693827
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.1.21...HEAD)
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.1.22...HEAD)

## [1.1.22](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.1.21...v1.1.22)

## Fixed
- Issue with empty string values in config. API doesn't return empty values in response, so we had inconsistent state after apply.
- Issue with empty string and list values in config. API doesn't return empty values in response, so we had inconsistent state after apply.
- Issue with disabled schemas: disabled schemas were added to state because of configured tables in upstream.

## [1.1.21](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.1.20...v1.1.21)
Expand Down
29 changes: 16 additions & 13 deletions fivetran/framework/core/model/connector_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,22 @@ func getValue(
}

if collectionType, ok := fieldType.(attr.TypeWithElementType); ok {
if currentField.GetIsSensitive(service) && local != nil {
items := []attr.Value{}
for _, v := range local.([]interface{}) {
items = append(items,
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service),
)
}
if _, ok := collectionType.(basetypes.SetTypable); ok {
setValue, _ := types.SetValue(collectionType.ElementType(), items)
return setValue
} else {
listValue, _ := types.ListValue(collectionType.ElementType(), items)
return listValue
if local != nil {
localArray := local.([]interface{})
if (currentField.GetIsSensitive(service)) || (value == nil && len(localArray) == 0) {
items := []attr.Value{}
for _, v := range localArray {
items = append(items,
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service),
)
}
if _, ok := collectionType.(basetypes.SetTypable); ok {
setValue, _ := types.SetValue(collectionType.ElementType(), items)
return setValue
} else {
listValue, _ := types.ListValue(collectionType.ElementType(), items)
return listValue
}
}
}
if value == nil {
Expand Down
2 changes: 1 addition & 1 deletion fivetran/framework/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

const Version = "1.1.21" // Current provider version
const Version = "1.1.22" // Current provider version

type fivetranProvider struct {
mockClient httputils.HttpClient
Expand Down
24 changes: 24 additions & 0 deletions fivetran/framework/resources/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,3 +1453,27 @@ func TestConnectorConfigemptyStringToNullConversionMock(t *testing.T) {
nil,
)
}

func TestConnectorConfigEmptyListConversionMock(t *testing.T) {
testConnectorCreateUpdate(t,
"dynamodb",
`name = "schema_name"`,
`
packed_mode_tables = []
`,
`
packed_mode_tables = ["table"]
`,
"schema_name",
`{
}`,
`{
"packed_mode_tables": ["table"]
}`,
nil, nil,
resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "id", "connector_id"),
),
nil,
)
}

0 comments on commit 2693827

Please sign in to comment.