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

Add data delay's fields in TF #387

Merged
merged 9 commits into from
Jan 21, 2025
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
2 changes: 2 additions & 0 deletions docs/data-sources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ data "fivetran_connector" "connector" {
- `connected_by` (String) The unique identifier of the user who has created the connector in your account.
- `created_at` (String) The timestamp of the time the connector was created in your account.
- `daily_sync_time` (String) The optional parameter that defines the sync start time when the sync frequency is already set or being set by the current request to 1440. It can be specified in one hour increments starting from 00:00 to 23:00. If not specified, we will use [the baseline sync start time](https://fivetran.com/docs/getting-started/syncoverview#syncfrequencyandscheduling). This parameter has no effect on the [0 to 60 minutes offset](https://fivetran.com/docs/getting-started/syncoverview#syncstarttimesandoffsets) used to determine the actual sync start time.
- `data_delay_sensitivity` (String) The level of data delay notification threshold. Possible values: LOW, NORMAL, HIGH, CUSTOM. The default value NORMAL. CUSTOM is only available for customers using the Enterprise plan or above.
- `data_delay_threshold` (Number) Custom sync delay notification threshold in minutes. The default value is 0. This parameter is only used when data_delay_sensitivity set to CUSTOM.
- `destination_schema` (Block, Read-only) (see [below for nested schema](#nestedblock--destination_schema))
- `failed_at` (String) The timestamp of the time the connector sync failed last time.
- `group_id` (String) The unique identifier for the Group (Destination) within the Fivetran system.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ resource "fivetran_connector" "amplitude" {

- `auth` (Block, Optional) (see [below for nested schema](#nestedblock--auth))
- `config` (Block, Optional) (see [below for nested schema](#nestedblock--config))
- `data_delay_sensitivity` (String) The level of data delay notification threshold. Possible values: LOW, NORMAL, HIGH, CUSTOM. The default value NORMAL. CUSTOM is only available for customers using the Enterprise plan or above.
- `data_delay_threshold` (Number) Custom sync delay notification threshold in minutes. The default value is 0. This parameter is only used when data_delay_sensitivity set to CUSTOM.
- `destination_schema` (Block, Optional) (see [below for nested schema](#nestedblock--destination_schema))
- `hybrid_deployment_agent_id` (String) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
- `local_processing_agent_id` (String, Deprecated) (Deprecated) The hybrid deployment agent ID that refers to the controller created for the group the connection belongs to. If the value is specified, the system will try to associate the connection with an existing agent.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/connector_schema_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Optional:

- `enabled` (Boolean) The boolean value specifying whether the sync of the column into the destination is enabled.
- `hashed` (Boolean) The boolean value specifying whether a column should be hashed.
- `is_primary_key` (Boolean)



Expand Down Expand Up @@ -260,6 +261,7 @@ Optional:

- `enabled` (Boolean) The boolean value specifying whether the sync of the column into the destination is enabled.
- `hashed` (Boolean) The boolean value specifying whether a column should be hashed.
- `is_primary_key` (Boolean)



Expand Down
46 changes: 45 additions & 1 deletion fivetran/framework/core/model/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ type ConnectorDatasourceModel struct {
Paused types.Bool `tfsdk:"paused"`
PauseAfterTrial types.Bool `tfsdk:"pause_after_trial"`
DailySyncTime types.String `tfsdk:"daily_sync_time"`

DataDelaySensitivity types.String `tfsdk:"data_delay_sensitivity"`
DataDelayThreshold types.Int64 `tfsdk:"data_delay_threshold"`

ProxyAgentId types.String `tfsdk:"proxy_agent_id"`
NetworkingMethod types.String `tfsdk:"networking_method"`
HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"`
LocalProcessingAgentId types.String `tfsdk:"local_processing_agent_id"`
PrivateLinkId types.String `tfsdk:"private_link_id"`
PrivateLinkId types.String `tfsdk:"private_link_id"`
Status types.Object `tfsdk:"status"`

Config types.Object `tfsdk:"config"`
Expand All @@ -62,6 +65,14 @@ func (d *ConnectorDatasourceModel) ReadFromResponse(resp connectors.DetailsWithC
d.ScheduleType = types.StringValue(resp.Data.ScheduleType)
d.Paused = types.BoolValue(*resp.Data.Paused)
d.PauseAfterTrial = types.BoolValue(*resp.Data.PauseAfterTrial)

d.DataDelaySensitivity = types.StringValue(resp.Data.DataDelaySensitivity)

if resp.Data.DataDelayThreshold != nil {
d.DataDelayThreshold = types.Int64Value(int64(*resp.Data.DataDelayThreshold))
} else {
d.DataDelayThreshold = types.Int64Null()
}

if resp.Data.DailySyncTime != "" {
d.DailySyncTime = types.StringValue(resp.Data.DailySyncTime)
Expand Down Expand Up @@ -136,6 +147,9 @@ type ConnectorResourceModel struct {
HybridDeploymentAgentId types.String `tfsdk:"hybrid_deployment_agent_id"`
PrivateLinkId types.String `tfsdk:"private_link_id"`

DataDelaySensitivity types.String `tfsdk:"data_delay_sensitivity"`
DataDelayThreshold types.Int64 `tfsdk:"data_delay_threshold"`

Config types.Object `tfsdk:"config"`
Auth types.Object `tfsdk:"auth"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Expand Down Expand Up @@ -206,6 +220,17 @@ func (d *ConnectorResourceModel) ReadFromContainer(c ConnectorModelContainer, fo
d.GroupId = types.StringValue(c.GroupId)
d.Service = types.StringValue(c.Service)

// as fact - this is computed attribute which user can change
if !d.DataDelaySensitivity.IsUnknown() && !d.DataDelaySensitivity.IsNull() {
d.DataDelaySensitivity = types.StringValue(c.DataDelaySensitivity)
}

if c.DataDelayThreshold != nil {
d.DataDelayThreshold = types.Int64Value(int64(*c.DataDelayThreshold))
} else {
d.DataDelayThreshold = types.Int64Null()
}

if c.LocalProcessingAgentId != "" && !d.LocalProcessingAgentId.IsUnknown() && !d.LocalProcessingAgentId.IsNull(){
d.LocalProcessingAgentId = types.StringValue(c.HybridDeploymentAgentId)
} else {
Expand Down Expand Up @@ -251,6 +276,17 @@ func (d *ConnectorDatasourceModel) ReadFromContainer(c ConnectorModelContainer)
d.GroupId = types.StringValue(c.GroupId)
d.Service = types.StringValue(c.Service)

// as fact - this is computed attribute which user can change
if !d.DataDelaySensitivity.IsUnknown() && !d.DataDelaySensitivity.IsNull() {
d.DataDelaySensitivity = types.StringValue(c.DataDelaySensitivity)
}

if c.DataDelayThreshold != nil {
d.DataDelayThreshold = types.Int64Value(int64(*c.DataDelayThreshold))
} else {
d.DataDelayThreshold = types.Int64Null()
}

d.DestinationSchema = getDestinationSchemaValue(c.Service, c.Schema)

if c.PrivateLinkId != "" {
Expand Down Expand Up @@ -306,6 +342,10 @@ type ConnectorModelContainer struct {
HybridDeploymentAgentId string
LocalProcessingAgentId string
PrivateLinkId string

DataDelaySensitivity string
DataDelayThreshold *int

Config map[string]interface{}

RunSetupTests bool
Expand All @@ -321,6 +361,10 @@ func (c *ConnectorModelContainer) ReadFromResponseData(data connectors.DetailsRe
c.GroupId = data.GroupID
c.Service = data.Service
c.Schema = data.Schema

c.DataDelaySensitivity = data.DataDelaySensitivity
c.DataDelayThreshold = data.DataDelayThreshold

c.Config = config

if data.ProxyAgentId != "" {
Expand Down
8 changes: 8 additions & 0 deletions fivetran/framework/core/schema/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ func ConnectorAttributesSchema() core.Schema {
ValueType: core.String,
Description: "The private link ID.",
},
"data_delay_sensitivity": {
ValueType: core.String,
Description: "The level of data delay notification threshold. Possible values: LOW, NORMAL, HIGH, CUSTOM. The default value NORMAL. CUSTOM is only available for customers using the Enterprise plan or above.",
},
"data_delay_threshold": {
ValueType: core.Integer,
Description: "Custom sync delay notification threshold in minutes. The default value is 0. This parameter is only used when data_delay_sensitivity set to CUSTOM.",
},
},
}
}
Expand Down
6 changes: 6 additions & 0 deletions fivetran/framework/datasources/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
"failed_at": null,
"sync_frequency": 5,
"schedule_type": "auto",
"data_delay_sensitivity": "NORMAL",
"data_delay_threshold": 0,
"status": {
"setup_state": "incomplete",
"sync_state": "paused",
Expand Down Expand Up @@ -101,6 +103,8 @@ func TestDataSourceConnectorConfigMappingMock(t *testing.T) {
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "sync_frequency", "5"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "paused", "true"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "pause_after_trial", "true"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "data_delay_sensitivity", "NORMAL"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "data_delay_threshold", "0"),
),
}

Expand Down Expand Up @@ -156,6 +160,8 @@ func TestDataSourceConnectorMock(t *testing.T) {
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "config.reports.1.report_type", "report_2"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "config.reports.1.metrics.0", "metric2"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "config.reports.1.metrics.1", "metric3"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "data_delay_sensitivity", "NORMAL"),
resource.TestCheckResourceAttr("data.fivetran_connector.test_connector", "data_delay_threshold", "0"),
),
}

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.4.0" // Current provider version
const Version = "1.4.3" // Current provider version

type fivetranProvider struct {
mockClient httputils.HttpClient
Expand Down
18 changes: 18 additions & 0 deletions fivetran/framework/resources/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ func (r *connector) Create(ctx context.Context, req resource.CreateRequest, resp
svc.PrivateLinkId(data.PrivateLinkId.ValueString())
}

if data.DataDelaySensitivity.ValueString() != "" {
svc.DataDelaySensitivity(data.DataDelaySensitivity.ValueString())
}

if !data.DataDelayThreshold.IsNull() {
value := int(data.DataDelayThreshold.ValueInt64())
svc.DataDelayThreshold(&value)
}

if data.LocalProcessingAgentId.ValueString() != "" {
resp.Diagnostics.AddWarning(
"Field `local_processing_agent_id` is Deprecated",
Expand Down Expand Up @@ -381,6 +390,15 @@ func (r *connector) Update(ctx context.Context, req resource.UpdateRequest, resp
svc.NetworkingMethod(plan.NetworkingMethod.ValueString())
}

if plan.DataDelaySensitivity.ValueString() != "" {
svc.DataDelaySensitivity(plan.DataDelaySensitivity.ValueString())
}

if !plan.DataDelayThreshold.IsNull() {
value := int(plan.DataDelayThreshold.ValueInt64())
svc.DataDelayThreshold(&value)
}

response, err := svc.DoCustom(ctx)

if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions fivetran/framework/resources/connector_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func upgradeConnectorState(ctx context.Context, req resource.UpgradeStateRequest
"proxy_agent_id": tftypes.NewValue(tftypes.String, nil),
"local_processing_agent_id": tftypes.NewValue(tftypes.String, nil),
"private_link_id": tftypes.NewValue(tftypes.String, nil),
"data_delay_sensitivity": tftypes.NewValue(tftypes.String, nil),
"data_delay_threshold": tftypes.NewValue(tftypes.Number, nil),
"hybrid_deployment_agent_id": rawState["local_processing_agent_id"],
"run_setup_tests": convertStringStateValueToBool("run_setup_tests", rawState["run_setup_tests"], resp.Diagnostics),
"trust_fingerprints": convertStringStateValueToBool("trust_fingerprints", rawState["trust_fingerprints"], resp.Diagnostics),
Expand Down Expand Up @@ -106,6 +108,8 @@ func getConnectorStateModel(version int) tftypes.Type {
base["networking_method"] = tftypes.String
base["local_processing_agent_id"] = tftypes.String
base["private_link_id"] = tftypes.String
base["data_delay_sensitivity"] = tftypes.String
base["data_delay_threshold"] = tftypes.Number
base["config"] = tftypes.Object{AttributeTypes: model.GetTfTypes(common.GetConfigFieldsMap(), 3)}
base["auth"] = tftypes.Object{AttributeTypes: model.GetTfTypes(common.GetAuthFieldsMap(), 3)}
} else {
Expand Down
35 changes: 34 additions & 1 deletion fivetran/framework/resources/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const (
"sync_frequency": 5,
"schedule_type": "auto",
"networking_method": "Directly",
"data_delay_sensitivity": "NORMAL",
"data_delay_threshold": 0,
"status": {
"setup_state": "incomplete",
"sync_state": "paused",
Expand Down Expand Up @@ -76,6 +78,8 @@ const (
"sync_frequency": 5,
"schedule_type": "auto",
"networking_method": "Directly",
"data_delay_sensitivity": "NORMAL",
"data_delay_threshold": 0,
"status": {
"setup_state": "incomplete",
"sync_state": "paused",
Expand Down Expand Up @@ -120,6 +124,8 @@ const (
"failed_at": null,
"schedule_type": "auto",
"networking_method": "Directly",
"data_delay_sensitivity": "NORMAL",
"data_delay_threshold": 0,
"status": {
"setup_state": "incomplete",
"sync_state": "paused",
Expand Down Expand Up @@ -164,6 +170,8 @@ const (
"sync_frequency": 5,
"schedule_type": "auto",
"networking_method": "Directly",
"data_delay_sensitivity": "NORMAL",
"data_delay_threshold": 0,
"status": {
"setup_state": "incomplete",
"sync_state": "paused",
Expand Down Expand Up @@ -239,6 +247,9 @@ const (
table = "table"
}

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

trust_certificates = false
trust_fingerprints = false
run_setup_tests = false
Expand Down Expand Up @@ -394,6 +405,9 @@ func TestResourceConnectorUpdateMock(t *testing.T) {
group_id = "group_id"
service = "postgres"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
prefix = "postgres"
}
Expand Down Expand Up @@ -439,6 +453,9 @@ func TestResourceConnectorUpdateMock(t *testing.T) {
group_id = "group_id"
service = "postgres"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
prefix = "postgres"
}
Expand Down Expand Up @@ -508,6 +525,9 @@ func TestResourceConnectorEmptyConfigMock(t *testing.T) {
group_id = "group_id"
service = "postgres"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
prefix = "postgres"
}
Expand Down Expand Up @@ -666,6 +686,9 @@ func TestResourceConnectorUnknownServiceMock(t *testing.T) {
group_id = "group_id"
service = "unknown-service-name"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
name = "schema"
}
Expand Down Expand Up @@ -699,6 +722,9 @@ func TestResourceConnectorMock(t *testing.T) {
service = "google_ads"
group_id = "group_id"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
name = "adwords_schema"
}
Expand Down Expand Up @@ -732,6 +758,8 @@ func TestResourceConnectorMock(t *testing.T) {
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "group_id", "group_id"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "service", "google_ads"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "destination_schema.name", "adwords_schema"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "data_delay_sensitivity", "NORMAL"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "data_delay_threshold", "0"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.user", "user_name"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.password", "password"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.port", "5432"),
Expand All @@ -755,6 +783,9 @@ func TestResourceConnectorMock(t *testing.T) {
service = "google_ads"
group_id = "group_id"

data_delay_sensitivity = "NORMAL"
data_delay_threshold = 0

destination_schema {
name = "adwords_schema"
}
Expand Down Expand Up @@ -787,6 +818,8 @@ func TestResourceConnectorMock(t *testing.T) {
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "group_id", "group_id"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "service", "google_ads"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "destination_schema.name", "adwords_schema"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "data_delay_sensitivity", "NORMAL"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "data_delay_threshold", "0"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.user", "user_name_1"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.password", "password_1"),
resource.TestCheckResourceAttr("fivetran_connector.test_connector", "config.port", "2345"),
Expand Down Expand Up @@ -883,7 +916,7 @@ func TestResourceConnectorMock(t *testing.T) {
body := tfmock.RequestBodyToJson(t, req)

// Check the request
tfmock.AssertEqual(t, len(body), 4)
tfmock.AssertEqual(t, len(body), 6)

tfmock.AssertKeyExistsAndHasValue(t, body, "run_setup_tests", true)
tfmock.AssertKeyExistsAndHasValue(t, body, "trust_certificates", true)
Expand Down
Loading
Loading