Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for schema change handling for SAP connectors #360

Merged
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
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
Loading