Skip to content

Commit 32d6044

Browse files
deanhuynhmarcelopv
andauthored
Reverse ETL model resource (#63)
Co-authored-by: Marcelo Vargas <[email protected]>
1 parent 055533b commit 32d6044

File tree

6 files changed

+592
-0
lines changed

6 files changed

+592
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "segment_reverse_etl_model Resource - terraform-provider-segment"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# segment_reverse_etl_model (Resource)
10+
11+
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Configures a specific Reverse ETL model
17+
resource "segment_reverse_etl_model" "example" {
18+
source_id = segment_source.javascript.id
19+
name = "Example Reverse ETL model"
20+
enabled = true
21+
description = "Example Reverse ETL model"
22+
schedule_strategy = "SPECIFIC_DAYS"
23+
query = "SELECT good_stuff FROM stuff"
24+
query_identifier_column = "good_stuff"
25+
schedule_config = jsonencode({
26+
"days" : [0, 1, 2, 3],
27+
"hours" : [0, 1, 3],
28+
"timezone" : "America/Los_Angeles"
29+
})
30+
}
31+
```
32+
33+
<!-- schema generated by tfplugindocs -->
34+
## Schema
35+
36+
### Required
37+
38+
- `description` (String) A longer, more descriptive explanation of the Model.
39+
- `enabled` (Boolean) Indicates whether the Model should have syncs enabled. When disabled, no syncs will be triggered, regardless of the enabled status of the attached destinations/subscriptions.
40+
- `name` (String) A short, human-readable description of the Model.
41+
- `query` (String) The SQL query that will be executed to extract data from the connected Source.
42+
- `query_identifier_column` (String) Indicates the column named in `query` that should be used to uniquely identify the extracted records.
43+
- `schedule_config` (String) Depending on the chosen strategy, configures the schedule for this model.
44+
- `schedule_strategy` (String) Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.
45+
- `source_id` (String) Indicates which Source to attach this model to.
46+
47+
### Read-Only
48+
49+
- `id` (String) The unique identifier for the model.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Configures a specific Reverse ETL model
2+
resource "segment_reverse_etl_model" "example" {
3+
source_id = segment_source.javascript.id
4+
name = "Example Reverse ETL model"
5+
enabled = true
6+
description = "Example Reverse ETL model"
7+
schedule_strategy = "SPECIFIC_DAYS"
8+
query = "SELECT good_stuff FROM stuff"
9+
query_identifier_column = "good_stuff"
10+
schedule_config = jsonencode({
11+
"days" : [0, 1, 2, 3],
12+
"hours" : [0, 1, 3],
13+
"timezone" : "America/Los_Angeles"
14+
})
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package models
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
5+
"github.com/hashicorp/terraform-plugin-framework/types"
6+
"github.com/segmentio/public-api-sdk-go/api"
7+
)
8+
9+
type ReverseETLModelState struct {
10+
ID types.String `tfsdk:"id"`
11+
SourceID types.String `tfsdk:"source_id"`
12+
Name types.String `tfsdk:"name"`
13+
Description types.String `tfsdk:"description"`
14+
Enabled types.Bool `tfsdk:"enabled"`
15+
ScheduleStrategy types.String `tfsdk:"schedule_strategy"`
16+
Query types.String `tfsdk:"query"`
17+
QueryIdentifierColumn types.String `tfsdk:"query_identifier_column"`
18+
ScheduleConfig jsontypes.Normalized `tfsdk:"schedule_config"`
19+
}
20+
21+
func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error {
22+
r.ID = types.StringValue(model.Id)
23+
r.SourceID = types.StringValue(model.SourceId)
24+
r.Name = types.StringValue(model.Name)
25+
r.Description = types.StringValue(model.Description)
26+
r.Enabled = types.BoolValue(model.Enabled)
27+
r.ScheduleStrategy = types.StringValue(model.ScheduleStrategy)
28+
r.Query = types.StringValue(model.Query)
29+
r.QueryIdentifierColumn = types.StringValue(model.QueryIdentifierColumn)
30+
scheduleConfig, err := GetSettings(model.ScheduleConfig)
31+
if err != nil {
32+
return err
33+
}
34+
r.ScheduleConfig = scheduleConfig
35+
36+
return nil
37+
}

internal/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (p *segmentProvider) Resources(_ context.Context) []func() resource.Resourc
155155
NewProfilesWarehouseResource,
156156
NewDestinationSubscriptionResource,
157157
NewSourceTrackingPlanConnectionResource,
158+
NewReverseETLModelResource,
158159
}
159160
}
160161

0 commit comments

Comments
 (0)