Skip to content

Commit ea41bbd

Browse files
committed
dbt_cloud related updates and remove deprecated fields on RETL models
1 parent 3bcca03 commit ea41bbd

File tree

7 files changed

+49
-79
lines changed

7 files changed

+49
-79
lines changed

docs/resources/reverse_etl_model.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ resource "segment_reverse_etl_model" "example" {
4747
name = "Example Reverse ETL model"
4848
enabled = true
4949
description = "Example Reverse ETL model"
50-
schedule_strategy = "SPECIFIC_DAYS"
5150
query = "SELECT good_stuff FROM stuff"
5251
query_identifier_column = "good_stuff"
53-
schedule_config = jsonencode({
54-
"days" : [0, 1, 2, 3],
55-
"hours" : [0, 1, 3],
56-
"timezone" : "America/Los_Angeles"
57-
})
5852
}
5953
```
6054

examples/resources/segment_reverse_etl_model/resource.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ resource "segment_reverse_etl_model" "example" {
44
name = "Example Reverse ETL model"
55
enabled = true
66
description = "Example Reverse ETL model"
7-
schedule_strategy = "SPECIFIC_DAYS"
87
query = "SELECT good_stuff FROM stuff"
98
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-
})
159
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0
1212
github.com/hashicorp/terraform-plugin-go v0.25.0
1313
github.com/hashicorp/terraform-plugin-testing v1.10.0
14-
github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559
14+
github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd
1515
gotest.tools/gotestsum v1.12.0
1616
)
1717

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3V
187187
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
188188
github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559 h1:6jgXPksz5bEJUMbhp4biSIViye/Os2yfAOx9yy44e1g=
189189
github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY=
190+
github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd h1:slroHJmwguMVr+wLnpigxN+51E6rkeoSsdp0f2YdmTI=
191+
github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd/go.mod h1:rtbFvYN1VVsfSc55BtGTC45YwkcrbOgCwTqZwlauBh0=
190192
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
191193
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
192194
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -204,6 +206,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
204206
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
205207
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
206208
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
209+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
207210
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
208211
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
209212
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=

internal/provider/destination_subscription_resource.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (r *destinationSubscriptionResource) Schema(_ context.Context, _ resource.S
100100
Attributes: map[string]schema.Attribute{
101101
"strategy": schema.StringAttribute{
102102
Required: true,
103-
Description: "Strategy supports three modes: PERIODIC, SPECIFIC_DAYS, or MANUAL.",
103+
Description: "Strategy supports three modes: PERIODIC, SPECIFIC_DAYS, DBT_CLOUD or MANUAL.",
104104
},
105105
"config": schema.StringAttribute{
106106
Optional: true,
@@ -494,6 +494,32 @@ func getSchedule(ctx context.Context, planSchedule basetypes.ObjectValue) (*api.
494494
"Manual reverse ETL schedule strategy does not require a config",
495495
)
496496
reverseETLSchedule.Config = *api.NewNullableConfig(nil)
497+
} else if reverseETLSchedule.Strategy == "DBT_CLOUD" {
498+
reverseETLModelScheduleConfig := api.ReverseEtlDbtCloudScheduleConfig{}
499+
var config string
500+
err = wrappedReverseETLModelScheduleConfig.As(&config)
501+
if err != nil {
502+
diags.AddError(
503+
"Unable to decode reverse ETL schedule config",
504+
err.Error(),
505+
)
506+
507+
return nil, diags
508+
}
509+
510+
err = json.Unmarshal([]byte(config), &reverseETLModelScheduleConfig)
511+
if err != nil {
512+
diags.AddError(
513+
"Unable to decode reverse ETL schedule config",
514+
err.Error(),
515+
)
516+
517+
return nil, diags
518+
}
519+
520+
reverseETLSchedule.Config = *api.NewNullableConfig(&api.Config{
521+
ReverseEtlDbtCloudScheduleConfig: &reverseETLModelScheduleConfig,
522+
})
497523
} else {
498524
diags.AddError(
499525
"Unsupported reverse ETL schedule strategy",
Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package models
22

33
import (
4-
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
54
"github.com/hashicorp/terraform-plugin-framework/types"
65
"github.com/segmentio/public-api-sdk-go/api"
76
)
87

98
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"`
9+
ID types.String `tfsdk:"id"`
10+
SourceID types.String `tfsdk:"source_id"`
11+
Name types.String `tfsdk:"name"`
12+
Description types.String `tfsdk:"description"`
13+
Enabled types.Bool `tfsdk:"enabled"`
14+
Query types.String `tfsdk:"query"`
15+
QueryIdentifierColumn types.String `tfsdk:"query_identifier_column"`
1916
}
2017

2118
func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error {
@@ -24,35 +21,8 @@ func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error {
2421
r.Name = types.StringValue(model.Name)
2522
r.Description = types.StringValue(model.Description)
2623
r.Enabled = types.BoolValue(model.Enabled)
27-
r.ScheduleStrategy = types.StringValue(model.ScheduleStrategy)
2824
r.Query = types.StringValue(model.Query)
2925
r.QueryIdentifierColumn = types.StringValue(model.QueryIdentifierColumn)
30-
scheduleConfig, err := GetScheduleConfig(model.ScheduleConfig)
31-
if err != nil {
32-
return err
33-
}
34-
r.ScheduleConfig = scheduleConfig
35-
if r.ScheduleConfig.IsNull() {
36-
empty := "{}"
37-
r.ScheduleConfig = jsontypes.NewNormalizedPointerValue(&empty)
38-
}
3926

4027
return nil
4128
}
42-
43-
func GetScheduleConfig(scheduleConfig api.NullableScheduleConfig) (jsontypes.Normalized, error) {
44-
if !scheduleConfig.IsSet() {
45-
return jsontypes.NewNormalizedNull(), nil
46-
}
47-
48-
jsonScheduleConfigString, err := scheduleConfig.Get().MarshalJSON()
49-
if err != nil {
50-
return jsontypes.NewNormalizedNull(), err
51-
}
52-
53-
if jsonScheduleConfigString == nil {
54-
return jsontypes.NewNormalizedValue("{}"), nil
55-
}
56-
57-
return jsontypes.NewNormalizedValue(string(jsonScheduleConfigString)), nil
58-
}

internal/provider/reverse_etl_model_resource.go

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
88
"github.com/segmentio/terraform-provider-segment/internal/provider/models"
99

10-
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1110
"github.com/hashicorp/terraform-plugin-framework/path"
1211
"github.com/hashicorp/terraform-plugin-framework/resource"
1312
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -67,11 +66,11 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
6766
Required: true,
6867
Description: "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.",
6968
},
70-
"schedule_strategy": schema.StringAttribute{
71-
Optional: true,
72-
DeprecationMessage: "Remove this attribute's configuration as it no longer is used and the attribute will be removed in the next major version of the provider. Please use `reverse_etl_schedule` in the destination_subscription resource instead.",
73-
Description: "Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.",
74-
},
69+
// "schedule_strategy": schema.StringAttribute{
70+
// Optional: true,
71+
// DeprecationMessage: "Remove this attribute's configuration as it no longer is used and the attribute will be removed in the next major version of the provider. Please use `reverse_etl_schedule` in the destination_subscription resource instead.",
72+
// Description: "Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.",
73+
// },
7574
"query": schema.StringAttribute{
7675
Required: true,
7776
Description: "The SQL query that will be executed to extract data from the connected Source.",
@@ -80,12 +79,12 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
8079
Required: true,
8180
Description: "Indicates the column named in `query` that should be used to uniquely identify the extracted records.",
8281
},
83-
"schedule_config": schema.StringAttribute{
84-
Optional: true,
85-
DeprecationMessage: "Remove this attribute's configuration as it no longer is used and the attribute will be removed in the next major version of the provider. Please use `reverse_etl_schedule` in the destination_subscription resource instead.",
86-
Description: "Depending on the chosen strategy, configures the schedule for this model.",
87-
CustomType: jsontypes.NormalizedType{},
88-
},
82+
// "schedule_config": schema.StringAttribute{
83+
// Optional: true,
84+
// DeprecationMessage: "Remove this attribute's configuration as it no longer is used and the attribute will be removed in the next major version of the provider. Please use `reverse_etl_schedule` in the destination_subscription resource instead.",
85+
// Description: "Depending on the chosen strategy, configures the schedule for this model.",
86+
// CustomType: jsontypes.NormalizedType{},
87+
// },
8988
},
9089
}
9190
}
@@ -139,10 +138,6 @@ func (r *reverseETLModelResource) Create(ctx context.Context, req resource.Creat
139138
if resp.Diagnostics.HasError() {
140139
return
141140
}
142-
143-
// Since we deprecated these values, we just need to set them to the plan values so there are no errors
144-
resp.State.SetAttribute(ctx, path.Root("schedule_config"), plan.ScheduleConfig)
145-
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), plan.ScheduleStrategy)
146141
}
147142

148143
func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
@@ -185,14 +180,6 @@ func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadReq
185180
if resp.Diagnostics.HasError() {
186181
return
187182
}
188-
189-
// Since we deprecated these values, we just need to set them to the plan values so there are no errors
190-
if !previousState.ScheduleConfig.IsUnknown() {
191-
resp.State.SetAttribute(ctx, path.Root("schedule_config"), previousState.ScheduleConfig)
192-
}
193-
if !previousState.ScheduleStrategy.IsUnknown() {
194-
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), previousState.ScheduleStrategy)
195-
}
196183
}
197184

198185
func (r *reverseETLModelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
@@ -244,10 +231,6 @@ func (r *reverseETLModelResource) Update(ctx context.Context, req resource.Updat
244231
if resp.Diagnostics.HasError() {
245232
return
246233
}
247-
248-
// Since we deprecated these values, we just need to set them to the plan values so there are no errors
249-
resp.State.SetAttribute(ctx, path.Root("schedule_config"), plan.ScheduleConfig)
250-
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), plan.ScheduleStrategy)
251234
}
252235

253236
func (r *reverseETLModelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {

0 commit comments

Comments
 (0)