Skip to content

Commit

Permalink
Fix schedule.connection_ids handling (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-aleksandrboldyrev authored Feb 12, 2025
1 parent 45dafda commit 2bd1ac5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0...HEAD)
## [Unreleased](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.5.1...HEAD)

## [1.5.1](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.5.0...v1.5.1)

## Fixed
Issue with `fivetran_transformation.schedule.connection_ids` for Quickstart Transformations

## [1.5.0](https://github.com/fivetran/terraform-provider-fivetran/compare/v1.4.2...v1.5.0)

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -4197,7 +4197,7 @@ Optional:

1. To import an existing `fivetran_connector` resource into your Terraform state, you need to get **Fivetran Connector ID** on the **Setup** tab of the connector page in your Fivetran dashboard.

2. Retrieve all connectors in a particular group using the [fivetran_group_connectors data source](/docs/data-sources/group_connectors). To retrieve existing groups, use the [fivetran_groups data source](/docs/data-sources/groups).
2. Retrieve all connectors in a particular group using the [fivetran_group_connectors data source](/providers/fivetran/fivetran/latest/docs/data-sources/group_connectors). To retrieve existing groups, use the [fivetran_groups data source](/providers/fivetran/fivetran/latest/docs/data-sources/groups).

3. Define an empty resource in your `.tf` configuration:

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/destination.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ The default value is `false` - this means that no setup tests will be performed
## Import

1. To import an existing `fivetran_destination` resource into your Terraform state, you need to get **Destination Group ID** on the destination page in your Fivetran dashboard.
To retrieve existing groups, use the [fivetran_groups data source](/docs/data-sources/groups).
To retrieve existing groups, use the [fivetran_groups data source](/providers/fivetran/fivetran/latest/docs/data-sources/groups).
2. Define an empty resource in your `.tf` configuration:

```hcl
Expand Down
18 changes: 7 additions & 11 deletions fivetran/framework/core/model/transformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
if resp.Data.TransformationSchedule.ScheduleType == "INTERVAL" || resp.Data.TransformationSchedule.Interval > 0 {
scheduleAttrValues["interval"] = types.Int64Value(int64(resp.Data.TransformationSchedule.Interval))
} else {
if !d.Schedule.Attributes()["interval"].IsUnknown() {
if !d.Schedule.IsNull() && !d.Schedule.Attributes()["interval"].IsUnknown() {
scheduleAttrValues["interval"] = d.Schedule.Attributes()["interval"]
} else {
scheduleAttrValues["interval"] = types.Int64Null()
Expand All @@ -81,7 +81,7 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
if resp.Data.TransformationSchedule.TimeOfDay != "" {
scheduleAttrValues["time_of_day"] = types.StringValue(resp.Data.TransformationSchedule.TimeOfDay)
} else {
if !d.Schedule.Attributes()["time_of_day"].IsUnknown() {
if !d.Schedule.IsNull() && !d.Schedule.Attributes()["time_of_day"].IsUnknown() {
scheduleAttrValues["time_of_day"] = d.Schedule.Attributes()["time_of_day"]
} else {
scheduleAttrValues["time_of_day"] = types.StringNull()
Expand All @@ -91,7 +91,7 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
if resp.Data.TransformationSchedule.ScheduleType != "" {
scheduleAttrValues["schedule_type"] = types.StringValue(resp.Data.TransformationSchedule.ScheduleType)
} else {
if !d.Schedule.Attributes()["schedule_type"].IsUnknown() {
if !d.Schedule.IsNull() && !d.Schedule.Attributes()["schedule_type"].IsUnknown() {
scheduleAttrValues["schedule_type"] = d.Schedule.Attributes()["schedule_type"]
} else {
scheduleAttrValues["schedule_type"] = types.StringNull()
Expand All @@ -109,14 +109,14 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
scheduleAttrValues["cron"] = types.SetNull(types.StringType)
}
} else {
if !d.Schedule.Attributes()["cron"].IsUnknown() {
if !d.Schedule.IsNull() && !d.Schedule.Attributes()["cron"].IsUnknown() {
scheduleAttrValues["cron"] = d.Schedule.Attributes()["cron"]
} else {
scheduleAttrValues["cron"] = types.SetNull(types.StringType)
}
}

if resp.Data.TransformationSchedule.ConnectionIds != nil {
if resp.Data.TransformationSchedule.ConnectionIds != nil && d.ProjectType.ValueString() == "DBT_CORE" {
vars := []attr.Value{}
for _, el := range resp.Data.TransformationSchedule.ConnectionIds {
vars = append(vars, types.StringValue(el))
Expand All @@ -127,11 +127,7 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
scheduleAttrValues["connection_ids"] = types.SetNull(types.StringType)
}
} else {
if !d.Schedule.Attributes()["connection_ids"].IsUnknown() {
scheduleAttrValues["connection_ids"] = d.Schedule.Attributes()["connection_ids"]
} else {
scheduleAttrValues["connection_ids"] = types.SetNull(types.StringType)
}
scheduleAttrValues["connection_ids"] = types.SetNull(types.StringType)
}

if resp.Data.TransformationSchedule.DaysOfWeek != nil {
Expand All @@ -145,7 +141,7 @@ func (d *Transformation) ReadFromResponse(ctx context.Context, resp sdk.Transfor
scheduleAttrValues["days_of_week"] = types.SetNull(types.StringType)
}
} else {
if !d.Schedule.Attributes()["days_of_week"].IsUnknown() {
if !d.Schedule.IsNull() && !d.Schedule.Attributes()["days_of_week"].IsUnknown() {
scheduleAttrValues["days_of_week"] = d.Schedule.Attributes()["days_of_week"]
} else {
scheduleAttrValues["days_of_week"] = types.SetNull(types.StringType)
Expand Down
2 changes: 0 additions & 2 deletions fivetran/framework/datasources/transformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ func TestDataSourcetransformationMappingMock(t *testing.T) {
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.schedule_type", "schedule_type"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.cron.0", "cron1"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.cron.1", "cron2"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.connection_ids.0", "connection_id1"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.connection_ids.1", "connection_id2"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.days_of_week.0", "days_of_week1"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.days_of_week.1", "days_of_week2"),
resource.TestCheckResourceAttr("data.fivetran_transformation.transformation", "schedule.time_of_day", "time_of_day"),
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.5.0" // Current provider version
const Version = "1.5.1" // Current provider version

type fivetranProvider struct {
mockClient httputils.HttpClient
Expand Down
8 changes: 8 additions & 0 deletions fivetran/framework/resources/transformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ var (
"days_of_week1",
"days_of_week2"
],
"connection_ids": [
"connection_id1",
"connection_id2"
],
"time_of_day": "time_of_day1"
},
"type": "QUICKSTART",
Expand Down Expand Up @@ -159,6 +163,10 @@ var (
"days_of_week1",
"days_of_week2"
],
"connection_ids": [
"connection_id1",
"connection_id2"
],
"time_of_day": "14:00"
},
"type": "QUICKSTART",
Expand Down
2 changes: 1 addition & 1 deletion templates/resources/connector.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ resource "fivetran_connector" "amplitude" {

1. To import an existing `fivetran_connector` resource into your Terraform state, you need to get **Fivetran Connector ID** on the **Setup** tab of the connector page in your Fivetran dashboard.

2. Retrieve all connectors in a particular group using the [fivetran_group_connectors data source](/docs/data-sources/group_connectors). To retrieve existing groups, use the [fivetran_groups data source](/docs/data-sources/groups).
2. Retrieve all connectors in a particular group using the [fivetran_group_connectors data source](/providers/fivetran/fivetran/latest/docs/data-sources/group_connectors). To retrieve existing groups, use the [fivetran_groups data source](/providers/fivetran/fivetran/latest/docs/data-sources/groups).

3. Define an empty resource in your `.tf` configuration:

Expand Down
2 changes: 1 addition & 1 deletion templates/resources/destination.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The default value is `false` - this means that no setup tests will be performed
## Import

1. To import an existing `fivetran_destination` resource into your Terraform state, you need to get **Destination Group ID** on the destination page in your Fivetran dashboard.
To retrieve existing groups, use the [fivetran_groups data source](/docs/data-sources/groups).
To retrieve existing groups, use the [fivetran_groups data source](/providers/fivetran/fivetran/latest/docs/data-sources/groups).
2. Define an empty resource in your `.tf` configuration:

```hcl
Expand Down

0 comments on commit 2bd1ac5

Please sign in to comment.