Skip to content

Commit e862112

Browse files
committed
revert field removals
1 parent 2ece474 commit e862112

File tree

4 files changed

+54
-11
lines changed

4 files changed

+54
-11
lines changed

docs/resources/reverse_etl_model.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ 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"
5051
query = "SELECT good_stuff FROM stuff"
5152
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+
})
5258
}
5359
```
5460

@@ -64,6 +70,11 @@ resource "segment_reverse_etl_model" "example" {
6470
- `query_identifier_column` (String) Indicates the column named in `query` that should be used to uniquely identify the extracted records.
6571
- `source_id` (String) Indicates which Source to attach this model to.
6672

73+
### Optional
74+
75+
- `schedule_config` (String, Deprecated) Depending on the chosen strategy, configures the schedule for this model.
76+
- `schedule_strategy` (String, Deprecated) Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.
77+
6778
### Read-Only
6879

6980
- `id` (String) The unique identifier for the model.

examples/resources/segment_reverse_etl_model/resource.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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"
78
query = "SELECT good_stuff FROM stuff"
89
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+
})
915
}

internal/provider/models/reverse_etl_model.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package models
22

33
import (
4+
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
45
"github.com/hashicorp/terraform-plugin-framework/types"
56
"github.com/segmentio/public-api-sdk-go/api"
67
)
@@ -13,6 +14,10 @@ type ReverseETLModelState struct {
1314
Enabled types.Bool `tfsdk:"enabled"`
1415
Query types.String `tfsdk:"query"`
1516
QueryIdentifierColumn types.String `tfsdk:"query_identifier_column"`
17+
18+
// Deprecated, schedule moved to destination_subscription
19+
ScheduleStrategy types.String `tfsdk:"schedule_strategy"`
20+
ScheduleConfig jsontypes.Normalized `tfsdk:"schedule_config"`
1621
}
1722

1823
func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error {
@@ -24,5 +29,9 @@ func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error {
2429
r.Query = types.StringValue(model.Query)
2530
r.QueryIdentifierColumn = types.StringValue(model.QueryIdentifierColumn)
2631

32+
// Deprecated, schedule moved to destination_subscription
33+
r.ScheduleStrategy = types.StringPointerValue(nil)
34+
r.ScheduleConfig = jsontypes.NewNormalizedNull()
35+
2736
return nil
2837
}

internal/provider/reverse_etl_model_resource.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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"
1011
"github.com/hashicorp/terraform-plugin-framework/path"
1112
"github.com/hashicorp/terraform-plugin-framework/resource"
1213
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -66,11 +67,11 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
6667
Required: true,
6768
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.",
6869
},
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-
// },
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+
},
7475
"query": schema.StringAttribute{
7576
Required: true,
7677
Description: "The SQL query that will be executed to extract data from the connected Source.",
@@ -79,12 +80,12 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
7980
Required: true,
8081
Description: "Indicates the column named in `query` that should be used to uniquely identify the extracted records.",
8182
},
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-
// },
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+
},
8889
},
8990
}
9091
}
@@ -138,6 +139,10 @@ func (r *reverseETLModelResource) Create(ctx context.Context, req resource.Creat
138139
if resp.Diagnostics.HasError() {
139140
return
140141
}
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)
141146
}
142147

143148
func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
@@ -180,6 +185,14 @@ func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadReq
180185
if resp.Diagnostics.HasError() {
181186
return
182187
}
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+
}
183196
}
184197

185198
func (r *reverseETLModelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
@@ -231,6 +244,10 @@ func (r *reverseETLModelResource) Update(ctx context.Context, req resource.Updat
231244
if resp.Diagnostics.HasError() {
232245
return
233246
}
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)
234251
}
235252

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

0 commit comments

Comments
 (0)