diff --git a/CHANGELOG.md b/CHANGELOG.md index 3965576b..53c785db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +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.4.1...HEAD) +## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.2...HEAD) + +## [1.4.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.1...v1.4.2) + +## Added +- Add `is_primary_key` to connector schema config ## [1.4.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.0...v1.4.1) diff --git a/fivetran/framework/core/model/connector_schema_config.go b/fivetran/framework/core/model/connector_schema_config.go index c0768820..29cf58f3 100644 --- a/fivetran/framework/core/model/connector_schema_config.go +++ b/fivetran/framework/core/model/connector_schema_config.go @@ -104,9 +104,10 @@ func (d *ConnectorSchemaResourceModel) ReadFromResponse(response connectors.Conn func (d *ConnectorSchemaResourceModel) getNullSchema() basetypes.SetValue { columnAttrTypes := map[string]attr.Type{ - "name": types.StringType, - "enabled": types.BoolType, - "hashed": types.BoolType, + "name": types.StringType, + "enabled": types.BoolType, + "hashed": types.BoolType, + "is_primary_key": types.BoolType, } tableAttrTypes := map[string]attr.Type{ "name": types.StringType, @@ -132,8 +133,9 @@ func (d *ConnectorSchemaResourceModel) getNullSchema() basetypes.SetValue { func (d *ConnectorSchemaResourceModel) getNullSchemas() basetypes.MapValue { columnsAttrTypes := map[string]attr.Type{ - "enabled": types.BoolType, - "hashed": types.BoolType, + "enabled": types.BoolType, + "hashed": types.BoolType, + "is_primary_key": types.BoolType, } tablesAttrTypes := map[string]attr.Type{ @@ -181,8 +183,9 @@ func (d *ConnectorSchemaResourceModel) getSchemasRawValue(schemas []interface{}) func (d *ConnectorSchemaResourceModel) getSchemasMap(schemas []interface{}) basetypes.MapValue { columnsAttrTypes := map[string]attr.Type{ - "enabled": types.BoolType, - "hashed": types.BoolType, + "enabled": types.BoolType, + "hashed": types.BoolType, + "is_primary_key": types.BoolType, } tablesAttrTypes := map[string]attr.Type{ @@ -259,6 +262,12 @@ func (d *ConnectorSchemaResourceModel) getSchemasMap(schemas []interface{}) base } else { columnElements["hashed"] = types.BoolNull() } + + if _, ok := localColumn["is_primary_key"]; ok && columnMap["is_primary_key"] != nil { + columnElements["is_primary_key"] = types.BoolValue(helpers.StrToBool(columnMap["is_primary_key"].(string))) + } else { + columnElements["is_primary_key"] = types.BoolNull() + } columnValue, _ := types.ObjectValue(columnsAttrTypes, columnElements) columns[columnName] = columnValue } @@ -310,9 +319,10 @@ func (d *ConnectorSchemaResourceModel) getLegacySchemaItems(schemas []interface{ schemaItems := []attr.Value{} localSchemas := d.mapLocalSchemas() columnAttrTypes := map[string]attr.Type{ - "name": types.StringType, - "enabled": types.BoolType, - "hashed": types.BoolType, + "name": types.StringType, + "enabled": types.BoolType, + "hashed": types.BoolType, + "is_primary_key": types.BoolType, } tableAttrTypes := map[string]attr.Type{ @@ -371,6 +381,11 @@ func (d *ConnectorSchemaResourceModel) getLegacySchemaItems(schemas []interface{ } else { columnElements["hashed"] = types.BoolNull() } + if _, ok := localColumn["is_primary_key"]; ok && columnMap["is_primary_key"] != nil { + columnElements["is_primary_key"] = types.BoolValue(helpers.StrToBool(columnMap["is_primary_key"].(string))) + } else { + columnElements["is_primary_key"] = types.BoolNull() + } columnValue, _ := types.ObjectValue(columnAttrTypes, columnElements) columns = append(columns, columnValue) } @@ -436,6 +451,11 @@ func (d *ConnectorSchemaResourceModel) getLegacySchemas() []interface{} { if !hashedValue.IsUnknown() && !hashedValue.IsNull() { column["hashed"] = columnElement.Attributes()["hashed"].(basetypes.BoolValue).ValueBool() } + + isPrimaryKey := columnElement.Attributes()["is_primary_key"].(basetypes.BoolValue) + if !isPrimaryKey.IsUnknown() && !isPrimaryKey.IsNull() { + column["is_primary_key"] = columnElement.Attributes()["is_primary_key"].(basetypes.BoolValue).ValueBool() + } } columns = append(columns, column) } @@ -509,6 +529,9 @@ func (d *ConnectorSchemaResourceModel) getSchemasRaw() []interface{} { if h, ok := cMap["hashed"].(bool); ok { column["hashed"] = h } + if p, ok := cMap["is_primary_key"].(bool); ok { + column["is_primary_key"] = p + } columns = append(columns, column) } } @@ -565,6 +588,9 @@ func (d *ConnectorSchemaResourceModel) getSchemas() []interface{} { if !columnElement.Attributes()["hashed"].(basetypes.BoolValue).IsUnknown() { column["hashed"] = columnElement.Attributes()["hashed"].(basetypes.BoolValue).ValueBool() } + if !columnElement.Attributes()["is_primary_key"].(basetypes.BoolValue).IsUnknown() { + column["is_primary_key"] = columnElement.Attributes()["is_primary_key"].(basetypes.BoolValue).ValueBool() + } columns = append(columns, column) } } diff --git a/fivetran/framework/core/schema/connector_schema_config.go b/fivetran/framework/core/schema/connector_schema_config.go index 49fd89bc..1d9e7db3 100644 --- a/fivetran/framework/core/schema/connector_schema_config.go +++ b/fivetran/framework/core/schema/connector_schema_config.go @@ -89,6 +89,11 @@ The value defines validation method. Computed: true, Description: "The boolean value specifying whether a column should be hashed.", }, + "is_primary_key": schema.BoolAttribute{ + Optional: true, + Computed: true, + Description: "", + }, }, }, }, @@ -184,6 +189,10 @@ func getColumnBlock() schema.SetNestedBlock { Computed: true, Description: "The boolean value specifying whether a column should be hashed.", }, + "is_primary_key": schema.BoolAttribute{ + Optional: true, + Description: "", + }, }, }, } diff --git a/fivetran/tests/mock/resource_connector_schema_config_logic_test.go b/fivetran/tests/mock/resource_connector_schema_config_logic_test.go index 608226cf..95a4ba5f 100644 --- a/fivetran/tests/mock/resource_connector_schema_config_logic_test.go +++ b/fivetran/tests/mock/resource_connector_schema_config_logic_test.go @@ -38,16 +38,16 @@ func TestUpstreamSchemaWithoutColumns(t *testing.T) { schema_1response.newTable("table_1", false, nil) // as table_2 stays enabled on switch to BLOCK_ALL - column settings are fetched from source and saved in config schema_1response.newTable("table_2", true, nil). - newColumn("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)) + newColumn("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false) schema_1response.newTable("table_3", false, nil) schema_2response := responseConfig.newSchema("schema_2", true) schema_2response.newTable("table_1", false, nil) // as table_2 stays enabled on switch to BLOCK_ALL - column settings are fetched from source and saved in config schema_2response.newTable("table_2", true, nil). - newColumn("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)) + newColumn("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false) schema_2response.newTable("table_3", false, nil) body := setupOneStepTest(t, upstreamConfig, tfConfig, responseConfig) @@ -92,7 +92,7 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { // Enable only two tables tfConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_1", true, nil) + newColumn("column_1", true, nil, true) responseConfig := schemaConfigTestData{ schemaChangeHandling: "BLOCK_ALL", @@ -100,8 +100,8 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { responseConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_1", true, boolPtr(false)). // column user configured in tf - newColumn("column_2", true, boolPtr(false)) // column present in source, but not saved to standard config before switch to BA mode + newColumn("column_1", true, boolPtr(false), false). // column user configured in tf + newColumn("column_2", true, boolPtr(false), false) // column present in source, but not saved to standard config before switch to BA mode response2Config := schemaConfigTestData{ schemaChangeHandling: "BLOCK_ALL", @@ -109,8 +109,8 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { response2Config.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_1", true, boolPtr(false)). // column user configured in tf - newColumn("column_2", false, boolPtr(false)) // column set disbled after second patch + newColumn("column_1", true, boolPtr(false), false). // column user configured in tf + newColumn("column_2", false, boolPtr(false), false) // column set disbled after second patch bodies := setupComplexTestWithColumnsReload( t, upstreamConfig, @@ -119,7 +119,7 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { map[string]map[string][]columnsConfigTestData{ "schema_1": map[string][]columnsConfigTestData{ "table_1": []columnsConfigTestData{ - newColumnConfigTestData().newColumn("column_1", false, boolPtr(false)).newColumn("column_2", false, boolPtr(false)), + newColumnConfigTestData().newColumn("column_1", false, boolPtr(false), true).newColumn("column_2", false, boolPtr(false), false), }, }, }) @@ -142,7 +142,7 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { assertEqual(t, len(columns), 1) column11 := AssertKeyExists(t, columns, "column_1").(map[string]interface{}) - assertEqual(t, len(column11), 1) + assertEqual(t, len(column11), 2) assertKeyExistsAndHasValue(t, column11, "enabled", true) body2 := bodies[1] @@ -160,7 +160,7 @@ func TestUpstreamSchemaWithoutColumnsColumnConfigured(t *testing.T) { columns = AssertKeyExists(t, table11, "columns").(map[string]interface{}) assertEqual(t, len(columns), 1) column12 := AssertKeyExists(t, columns, "column_2").(map[string]interface{}) - assertEqual(t, len(column12), 1) + assertEqual(t, len(column12), 2) assertKeyExistsAndHasValue(t, column12, "enabled", false) } @@ -173,14 +173,14 @@ func TestSchemaDoesntTouchColumnsInBlockAllIfNoColumnSettingsMock(t *testing.T) schema_1 := upstreamConfig.newSchema("schema_1", true) schema_1.newTable("table_1", true, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) schema_1.newTable("table_2", true, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) // only schema_1.table_1 will stay enabled // table_2 will be disabled @@ -199,15 +199,15 @@ func TestSchemaDoesntTouchColumnsInBlockAllIfNoColumnSettingsMock(t *testing.T) schema_1response := responseConfig.newSchema("schema_1", true) // table_1 enabled, existing columns saved settings schema_1response.newTable("table_1", true, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) // table_2 enabled, existing columns saved settings schema_1response.newTable("table_2", false, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) // act body := setupOneStepTest(t, upstreamConfig, tfConfig, responseConfig) @@ -231,9 +231,9 @@ func TestSetupSchemaBlockAllMock(t *testing.T) { schema_1 := upstreamConfig.newSchema("schema_1", true) schema_1.newTable("table_1", true, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) schema_1.newTableLocked("table_locked", true, nil) @@ -243,7 +243,7 @@ func TestSetupSchemaBlockAllMock(t *testing.T) { tfConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_2", true, nil) + newColumn("column_2", true, nil, true) responseConfig := schemaConfigTestData{ schemaChangeHandling: "BLOCK_ALL", @@ -251,9 +251,9 @@ func TestSetupSchemaBlockAllMock(t *testing.T) { schema_1response := responseConfig.newSchema("schema_1", true) schema_1response.newTable("table_1", true, nil). - newColumnLocked("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", false, boolPtr(true)) + newColumnLocked("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", false, boolPtr(true), false) schema_1response.newTableLocked("table_locked", true, nil) // act @@ -272,7 +272,7 @@ func TestSetupSchemaBlockAllMock(t *testing.T) { assertEqual(t, len(columns), 1) column3 := assertKeyExists(t, columns, "column_3").(map[string]interface{}) - assertEqual(t, len(column3), 1) + assertEqual(t, len(column3), 2) assertKeyExistsAndHasValue(t, column3, "enabled", false) } @@ -282,9 +282,9 @@ func TestIgnoreNoPatchAllowedColumnsMock(t *testing.T) { } upstreamConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_1", true, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", true, boolPtr(true)) + newColumn("column_1", true, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", true, boolPtr(true), false) tfConfig := schemaConfigTestData{ schemaChangeHandling: "BLOCK_ALL", @@ -292,16 +292,16 @@ func TestIgnoreNoPatchAllowedColumnsMock(t *testing.T) { tfConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_2", true, nil) + newColumn("column_2", true, nil, true) responseConfig := schemaConfigTestData{ schemaChangeHandling: "BLOCK_ALL", } responseConfig.newSchema("schema_1", true). newTable("table_1", true, nil). - newColumn("column_1", false, boolPtr(false)). - newColumn("column_2", true, boolPtr(false)). - newColumn("column_3", false, boolPtr(true)) + newColumn("column_1", false, boolPtr(false), true). + newColumn("column_2", true, boolPtr(false), false). + newColumn("column_3", false, boolPtr(true), false) // act body := setupOneStepTest(t, upstreamConfig, tfConfig, responseConfig) @@ -317,10 +317,10 @@ func TestIgnoreNoPatchAllowedColumnsMock(t *testing.T) { columns := assertKeyExists(t, table_1, "columns").(map[string]interface{}) assertEqual(t, len(columns), 2) column_1 := assertKeyExists(t, columns, "column_1").(map[string]interface{}) - assertEqual(t, len(column_1), 1) + assertEqual(t, len(column_1), 2) assertKeyExistsAndHasValue(t, column_1, "enabled", false) column_3 := assertKeyExists(t, columns, "column_3").(map[string]interface{}) - assertEqual(t, len(column_3), 1) + assertEqual(t, len(column_3), 2) assertKeyExistsAndHasValue(t, column_3, "enabled", false) } diff --git a/fivetran/tests/mock/schema_tests_common.go b/fivetran/tests/mock/schema_tests_common.go index de267e16..2eb07d61 100644 --- a/fivetran/tests/mock/schema_tests_common.go +++ b/fivetran/tests/mock/schema_tests_common.go @@ -13,6 +13,7 @@ type columnTestData struct { enabled bool hashed *bool enabledPatchSettings bool + isPrimaryKey bool } type tableTestData struct { @@ -40,7 +41,7 @@ func newColumnConfigTestData() columnsConfigTestData { return columnsConfigTestData{} } -func (cctd columnsConfigTestData) newColumn(name string, enabled bool, hashed *bool) columnsConfigTestData { +func (cctd columnsConfigTestData) newColumn(name string, enabled bool, hashed *bool, isPrimaryKey bool) columnsConfigTestData { if cctd.columns == nil { cctd.columns = map[string]*columnTestData{} } @@ -48,6 +49,7 @@ func (cctd columnsConfigTestData) newColumn(name string, enabled bool, hashed *b enabled: enabled, hashed: hashed, enabledPatchSettings: true, + isPrimaryKey: isPrimaryKey, } return cctd } @@ -173,7 +175,7 @@ func (std *schemaTestData) newTableLocked(name string, enabled bool, syncMode *s return table } -func (ttd *tableTestData) newColumn(name string, enabled bool, hashed *bool) *tableTestData { +func (ttd *tableTestData) newColumn(name string, enabled bool, hashed *bool, isPrimaryKey bool) *tableTestData { if ttd.columns == nil { ttd.columns = map[string]*columnTestData{} } @@ -181,11 +183,12 @@ func (ttd *tableTestData) newColumn(name string, enabled bool, hashed *bool) *ta enabled: enabled, hashed: hashed, enabledPatchSettings: true, + isPrimaryKey: isPrimaryKey, } return ttd } -func (ttd *tableTestData) newColumnLocked(name string, enabled bool, hashed *bool) *tableTestData { +func (ttd *tableTestData) newColumnLocked(name string, enabled bool, hashed *bool, isPrimaryKey bool) *tableTestData { if ttd.columns == nil { ttd.columns = map[string]*columnTestData{} } @@ -193,6 +196,7 @@ func (ttd *tableTestData) newColumnLocked(name string, enabled bool, hashed *boo enabled: enabled, hashed: hashed, enabledPatchSettings: false, + isPrimaryKey: isPrimaryKey, } return ttd } diff --git a/go.mod b/go.mod index 23f53bac..9a3ec587 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/fivetran/terraform-provider-fivetran require ( - github.com/fivetran/go-fivetran v1.0.4 + github.com/fivetran/go-fivetran v1.0.5 github.com/hashicorp/terraform-plugin-framework v1.8.0 github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 diff --git a/go.sum b/go.sum index 63d22a4b..d799dff2 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg= github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0= github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= @@ -7,16 +11,33 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= -github.com/fivetran/go-fivetran v1.0.4 h1:wYNS72Zw/bEZpuBKFYGm07TRQtqoo1/Y6oWayHAqEHk= -github.com/fivetran/go-fivetran v1.0.4/go.mod h1:EIy5Uwn1zylQCr/7O+8rrwvmjvhW3PPpzHkQj26ON7Y= +github.com/fivetran/go-fivetran v1.0.5 h1:xLnfXVWMiKoIkERlPhinj+Bkt8lzsCmhlgnu2Wjak/U= +github.com/fivetran/go-fivetran v1.0.5/go.mod h1:EIy5Uwn1zylQCr/7O+8rrwvmjvhW3PPpzHkQj26ON7Y= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -77,11 +98,21 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -103,9 +134,18 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= @@ -114,6 +154,8 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.14.3 h1:1JXy1XroaGrzZuG6X9dt7HL6s9AwbY+l4UNL8o5B6ho= github.com/zclconf/go-cty v1.14.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= @@ -133,6 +175,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -175,6 +219,10 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/modules/connector/schema/const.go b/modules/connector/schema/const.go index 5c060390..0c7237fa 100644 --- a/modules/connector/schema/const.go +++ b/modules/connector/schema/const.go @@ -18,6 +18,7 @@ const ( NAME = "name" ENABLED = "enabled" HASHED = "hashed" + IS_PRIMARY_KEY = "is_primary_key" SYNC_MODE = "sync_mode" HANDLED = "handled" diff --git a/modules/connector/schema/schema_column.go b/modules/connector/schema/schema_column.go index 93126a2e..c8cac37b 100644 --- a/modules/connector/schema/schema_column.go +++ b/modules/connector/schema/schema_column.go @@ -23,6 +23,15 @@ func (c *_column) setHashed(value *bool) { } } +func (c *_column) setIsPrimaryKey(value *bool) { + if value != nil && (c.isPrimaryKey == nil || *value != *c.isPrimaryKey) { + c.isPrimaryKey = value + c.updated = true + } else { + c.isPrimaryKey = nil + } +} + func (c *_column) setHashedToDefault() { hashedDefault := false c.setHashed(&hashedDefault) @@ -36,6 +45,9 @@ func (c _column) prepareRequest() *connectors.ConnectorSchemaConfigColumn { if c.hashed != nil { result.Hashed(*c.hashed) } + if c.isPrimaryKey != nil { + result.IsPrimaryKey(*c.isPrimaryKey) + } return result } @@ -45,6 +57,9 @@ func (c _column) prepareCreateRequest() *connectors.ConnectorSchemaConfigColumn if c.hashed != nil { result.Hashed(*c.hashed) } + if c.isPrimaryKey != nil { + result.IsPrimaryKey(*c.isPrimaryKey) + } return result } @@ -58,6 +73,7 @@ func (c *_column) override(local *_column, sch string) error { } } c.setHashed(local.hashed) + c.setIsPrimaryKey(local.isPrimaryKey) } else { // patch silently if possible c.setEnabled(sch != BLOCK_ALL) @@ -85,6 +101,11 @@ func (c *_column) readFromResourceData(source map[string]interface{}, sch string } else { c.enabled = (c.hashed != nil) || sch != BLOCK_ALL } + + if isPrimaryKey, ok := source[IS_PRIMARY_KEY]; ok { + value := getBoolValue(isPrimaryKey) + c.isPrimaryKey = &value + } c.name = source[NAME].(string) } @@ -92,6 +113,7 @@ func (c *_column) readFromResponse(name string, response *connectors.ConnectorSc c.name = name c.enabled = *response.Enabled c.hashed = response.Hashed + c.isPrimaryKey = response.IsPrimaryKey c.patchAllowed = response.EnabledPatchSettings.Allowed if !c.isPatchAllowed() { lockReason := "Reason unknown. Please report this error to provider developers." @@ -138,6 +160,9 @@ func (c _column) toStateObject(sch string, local *_column, diag *diag.Diagnostic if local != nil && local.hashed != nil && c.hashed != nil { result[HASHED] = helpers.BoolToStr(*c.hashed) } + if local != nil && local.isPrimaryKey != nil && c.isPrimaryKey != nil { + result[IS_PRIMARY_KEY] = helpers.BoolToStr(*c.isPrimaryKey) + } return result, local != nil || (c.enabled != (sch != BLOCK_ALL) && c.isPatchAllowed()) // if column is not aligned with sch it should not be included if patch not allowed } diff --git a/modules/connector/schema/schema_element.go b/modules/connector/schema/schema_element.go index be57c81f..adb5963b 100644 --- a/modules/connector/schema/schema_element.go +++ b/modules/connector/schema/schema_element.go @@ -1,9 +1,10 @@ package schema type _element struct { - name string - enabled bool - updated bool + name string + enabled bool + updated bool + isPrimaryKey *bool patchAllowed *bool lockReason *string