Skip to content

Commit

Permalink
Fix for schema change handling for SAP connectors (#360)
Browse files Browse the repository at this point in the history
* Fix for schema change handling for SAP connectors

* Addresss pr comments
  • Loading branch information
fivetran-jovanmanojlovic authored Sep 18, 2024
1 parent d45b71c commit 8e99df5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ 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.3.1...HEAD)
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.3.2...HEAD)

## [1.3.2](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.3.1...v1.3.2)

- `schema_change_handling` is no longer required for `fivetran_connector_schema_config` resource

## [1.3.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.3.0...v1.3.1)

Expand Down
5 changes: 4 additions & 1 deletion fivetran/framework/core/model/connector_schema_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func (d *ConnectorSchemaResourceModel) ReadFromResponse(response connectors.Conn
d.SchemasRaw = fivetrantypes.NewJsonSchemaValue(schemasJson)
}

d.SchemaChangeHandling = types.StringValue(response.Data.SchemaChangeHandling)
// SAP connectors will not accept schemaChangeHandling in request and will return ALLOW_COLUMNS as default
if d.SchemaChangeHandling.IsNull() || d.SchemaChangeHandling.IsUnknown() || d.SchemaChangeHandling.ValueString() != "" {
d.SchemaChangeHandling = types.StringValue(response.Data.SchemaChangeHandling)
}
}

func (d *ConnectorSchemaResourceModel) getNullSchema() basetypes.SetValue {
Expand Down
2 changes: 1 addition & 1 deletion fivetran/framework/core/schema/connector_schema_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetConnectorSchemaResourceSchema(ctx context.Context) schema.Schema {
Description: "The unique identifier for the connector within the Fivetran system.",
},
"schema_change_handling": schema.StringAttribute{
Required: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("ALLOW_ALL", "ALLOW_COLUMNS", "BLOCK_ALL"),
},
Expand Down
8 changes: 4 additions & 4 deletions fivetran/framework/resources/connector_schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (r *connectorSchema) Create(ctx context.Context, req resource.CreateRequest
svc := config.PrepareRequest(client.NewConnectorSchemaUpdateService())
svc.ConnectorID(connectorID)
// update schema_change_handling if needed
if schemaChangeHandling != schemaResponse.Data.SchemaChangeHandling {
if schemaChangeHandling != "" && schemaChangeHandling != schemaResponse.Data.SchemaChangeHandling {
svc.SchemaChangeHandling(schemaChangeHandling)
}
// we should not parse response here because it will contain only applied diffs, not the whole configuration
Expand All @@ -244,7 +244,7 @@ func (r *connectorSchema) Create(ctx context.Context, req resource.CreateRequest
}
} else {
// we update only schema_change_handling if needed
if schemaChangeHandling != schemaResponse.Data.SchemaChangeHandling {
if schemaChangeHandling != "" && schemaChangeHandling != schemaResponse.Data.SchemaChangeHandling {
svc := client.NewConnectorSchemaUpdateService().ConnectorID(connectorID)
svc.SchemaChangeHandling(schemaChangeHandling)
schResponse, err := svc.Do(ctx)
Expand Down Expand Up @@ -433,7 +433,7 @@ func (r *connectorSchema) Update(ctx context.Context, req resource.UpdateRequest
svc := config.PrepareRequest(client.NewConnectorSchemaUpdateService())
svc.ConnectorID(connectorID)
// update schema_change_handling as well if needed
if plan.SchemaChangeHandling != state.SchemaChangeHandling {
if plan.SchemaChangeHandling.String() != "" && plan.SchemaChangeHandling != state.SchemaChangeHandling {
svc.SchemaChangeHandling(plan.SchemaChangeHandling.ValueString())
}
// we should not parse response here because it will contain only applied diffs, not the whole configuration
Expand All @@ -449,7 +449,7 @@ func (r *connectorSchema) Update(ctx context.Context, req resource.UpdateRequest

} else {
// update schema_change_handling if needed
if plan.SchemaChangeHandling != state.SchemaChangeHandling {
if plan.SchemaChangeHandling.String() != "" && plan.SchemaChangeHandling != state.SchemaChangeHandling {
svc := client.NewConnectorSchemaUpdateService().ConnectorID(connectorID)
svc.SchemaChangeHandling(plan.SchemaChangeHandling.ValueString())
schResponse, err := svc.Do(ctx)
Expand Down

0 comments on commit 8e99df5

Please sign in to comment.