Skip to content
Open
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
12 changes: 6 additions & 6 deletions fivetran/framework/core/model/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ type ConnectorResourceModel struct {
TrustFingerprints types.Bool `tfsdk:"trust_fingerprints"`
}

func (d *ConnectorResourceModel) ReadFromResponse(resp connections.DetailsWithCustomConfigNoTestsResponse, forceReadConfig bool) diag.Diagnostics {
func (d *ConnectorResourceModel) ReadFromResponse(resp connections.DetailsWithCustomConfigNoTestsResponse, isImporting bool) diag.Diagnostics {
responseContainer := ConnectorModelContainer{}
responseContainer.ReadFromResponseData(resp.Data.DetailsResponseDataCommon, resp.Data.Config)
d.ReadFromContainer(responseContainer, forceReadConfig)
d.ReadFromContainer(responseContainer, isImporting)
return nil
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func (d *ConnectorResourceModel) GetDestinatonSchemaForConfig() (map[string]inte
)
}

func (d *ConnectorResourceModel) ReadFromContainer(c ConnectorModelContainer, forceReadConfig bool) {
func (d *ConnectorResourceModel) ReadFromContainer(c ConnectorModelContainer, isImporting bool) {
d.Id = types.StringValue(c.Id)
d.Name = types.StringValue(c.Schema)
d.ConnectedBy = types.StringValue(c.ConnectedBy)
Expand Down Expand Up @@ -248,12 +248,12 @@ func (d *ConnectorResourceModel) ReadFromContainer(c ConnectorModelContainer, fo
d.NetworkingMethod = types.StringValue(c.NetworkingMethod)
}

if forceReadConfig || (!d.Config.IsNull() && !d.Config.IsUnknown()) {
if isImporting || (!d.Config.IsNull() && !d.Config.IsUnknown()) {
d.Config = getValue(
types.ObjectType{AttrTypes: getAttrTypes(common.GetConfigFieldsMap())},
c.Config,
getValueFromAttrValue(d.Config, common.GetConfigFieldsMap(), nil, c.Service).(map[string]interface{}),
common.GetConfigFieldsMap(), nil, c.Service).(basetypes.ObjectValue)
common.GetConfigFieldsMap(), nil, c.Service, isImporting).(basetypes.ObjectValue)
}
}

Expand Down Expand Up @@ -306,7 +306,7 @@ func (d *ConnectorDatasourceModel) ReadFromContainer(c ConnectorModelContainer)
c.Config,
common.GetConfigFieldsMap(),
nil,
c.Service).(basetypes.ObjectValue)
c.Service, false).(basetypes.ObjectValue)
}

func (d *ConnectorResourceModel) HasUpdates(plan ConnectorResourceModel, state ConnectorResourceModel) (bool, map[string]interface{}, map[string]interface{}, error) {
Expand Down
43 changes: 22 additions & 21 deletions fivetran/framework/core/model/connector_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,27 @@ func attrTypeFromConfigField(cf common.ConfigField) attr.Type {
return nil
}

func getStringValue(value, local interface{}, currentField *common.ConfigField, service string) types.String {
func getStringValue(value, local interface{}, currentField *common.ConfigField, service string, isImporting bool) types.String {
if currentField != nil && currentField.GetIsSensitive(service) && local != nil {
return types.StringValue(local.(string))
}
if value == nil {
if local != nil && local.(string) == "" {
return types.StringValue("")
}
return types.StringNull()
}
if local == nil && !currentField.Readonly { // we should not set non-nullable value to the state if it's not configured by tf, we just ignore it
if local == nil && !currentField.Readonly && // we should not set non-nullable value to the state if it's not configured by tf, we just ignore it
(!isImporting || currentField.GetIsSensitive(service)) {
return types.StringNull()
}
if currentField != nil && currentField.GetIsSensitive(service) && local != nil {
return types.StringValue(local.(string))
}

// print any value as a string
return types.StringValue(fmt.Sprintf("%v", value))
}

func getBoolValue(value, local interface{}, currentField *common.ConfigField) types.Bool {
if value == nil || (local == nil && !currentField.Readonly) { // we should not set value to the state if it's not configured by tf
func getBoolValue(value, local interface{}, currentField *common.ConfigField, isImporting bool) types.Bool {
if value == nil || (local == nil && !currentField.Readonly && !isImporting) { // we should not set value to the state if it's not configured by tf
return types.BoolNull()
}
if fValue, ok := value.(bool); ok {
Expand All @@ -170,8 +171,8 @@ func getBoolValue(value, local interface{}, currentField *common.ConfigField) ty
panic(fmt.Sprintf("Unable to read boolean value from %v", value))
}

func getIntValue(value, local interface{}, currentField *common.ConfigField) types.Int64 {
if value == nil || (local == nil && !currentField.Readonly) { // we should not set value to the state if it's not configured by tf
func getIntValue(value, local interface{}, currentField *common.ConfigField, isImporting bool) types.Int64 {
if value == nil || (local == nil && !currentField.Readonly && !isImporting) { // we should not set value to the state if it's not configured by tf
return types.Int64Null()
}
// value in json decoded response is always float64 for any kind of numbers
Expand All @@ -192,18 +193,18 @@ func getIntValue(value, local interface{}, currentField *common.ConfigField) typ

func getValue(
fieldType attr.Type,
value, local interface{},
value, local interface{},// value - api response value, local - tf state value
fieldsMap map[string]common.ConfigField,
currentField *common.ConfigField,
service string) attr.Value {
service string, isImporting bool) attr.Value {
if fieldType.Equal(types.StringType) {
return getStringValue(value, local, currentField, service)
return getStringValue(value, local, currentField, service, isImporting)
}
if fieldType.Equal(types.BoolType) {
return getBoolValue(value, local, currentField)
return getBoolValue(value, local, currentField, isImporting)
}
if fieldType.Equal(types.Int64Type) {
return getIntValue(value, local, currentField)
return getIntValue(value, local, currentField, isImporting)
}
if complexType, ok := fieldType.(attr.TypeWithAttributeTypes); ok {
if value == nil {
Expand All @@ -220,28 +221,28 @@ func getValue(

if _, ok := fieldsMap[fn+"_"+service]; ok {
// this field should be handled as service specific field, set this attr as nil
elements[fn] = getValue(et, nil, nil, cf.ItemFields, &cf, service)
elements[fn] = getValue(et, nil, nil, cf.ItemFields, &cf, service, isImporting)
continue
}
efn := fn
if cf.ApiField != "" {
efn = cf.ApiField
// field is not related to this particular service, set this attr as nil
if !strings.HasSuffix(fn, service) {
elements[fn] = getValue(et, nil, nil, cf.ItemFields, &cf, service)
elements[fn] = getValue(et, nil, nil, cf.ItemFields, &cf, service, isImporting)
continue
}
}
// get upstream value
if value, ok := vMap[efn]; ok {
lValue := lMap[fn]
elements[fn] = getValue(et, value, lValue, cf.ItemFields, &cf, service)
elements[fn] = getValue(et, value, lValue, cf.ItemFields, &cf, service, isImporting)
} else {
lValue := lMap[fn]
if et == nil {
panic(fmt.Sprintf("Type for field '%v' is nil, local value: %v", fn, lValue))
}
elements[fn] = getValue(et, nil, lValue, cf.ItemFields, &cf, service)
elements[fn] = getValue(et, nil, lValue, cf.ItemFields, &cf, service, isImporting)
}
}
objectValue, _ := types.ObjectValue(complexType.AttributeTypes(), elements)
Expand All @@ -255,7 +256,7 @@ func getValue(
items := []attr.Value{}
for _, v := range localArray {
items = append(items,
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service),
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service, isImporting),
)
}
if _, ok := collectionType.(basetypes.SetTypable); ok {
Expand Down Expand Up @@ -305,15 +306,15 @@ func getValue(
if keyV, ok := vMap[keyField]; ok {
if keyL == keyV {
items = append(items,
getValue(collectionType.ElementType(), v, li, fieldsMap, currentField, service),
getValue(collectionType.ElementType(), v, li, fieldsMap, currentField, service, isImporting),
)
}
}
}
}
} else {
items = append(items,
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service),
getValue(collectionType.ElementType(), v, v, fieldsMap, currentField, service, isImporting),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (d *DestinationDatasourceModel) SetConfig(value map[string]interface{}) {
value,
common.GetDestinationFieldsMap(),
nil,
service).(basetypes.ObjectValue)
service, false).(basetypes.ObjectValue)
}

func (d *DestinationDatasourceModel) ReadFromResponse(resp destinations.DestinationDetailsCustomResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (d *DestinationResourceModel) SetConfig(value map[string]interface{}) {
getValueFromAttrValue(config, common.GetDestinationFieldsMap(), nil, service).(map[string]interface{}),
common.GetDestinationFieldsMap(),
nil,
service).(basetypes.ObjectValue)
service, false).(basetypes.ObjectValue)
}

func (d *DestinationResourceModel) ReadFromResponse(resp destinations.DestinationDetailsCustomResponse) {
Expand Down
Loading