Skip to content

Commit

Permalink
revert field removals
Browse files Browse the repository at this point in the history
  • Loading branch information
rexatsegment committed Jan 14, 2025
1 parent 2ece474 commit e862112
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
11 changes: 11 additions & 0 deletions docs/resources/reverse_etl_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ resource "segment_reverse_etl_model" "example" {
name = "Example Reverse ETL model"
enabled = true
description = "Example Reverse ETL model"
schedule_strategy = "SPECIFIC_DAYS"
query = "SELECT good_stuff FROM stuff"
query_identifier_column = "good_stuff"
schedule_config = jsonencode({
"days" : [0, 1, 2, 3],
"hours" : [0, 1, 3],
"timezone" : "America/Los_Angeles"
})
}
```

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

### Optional

- `schedule_config` (String, Deprecated) Depending on the chosen strategy, configures the schedule for this model.
- `schedule_strategy` (String, Deprecated) Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.

### Read-Only

- `id` (String) The unique identifier for the model.
6 changes: 6 additions & 0 deletions examples/resources/segment_reverse_etl_model/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ resource "segment_reverse_etl_model" "example" {
name = "Example Reverse ETL model"
enabled = true
description = "Example Reverse ETL model"
schedule_strategy = "SPECIFIC_DAYS"
query = "SELECT good_stuff FROM stuff"
query_identifier_column = "good_stuff"
schedule_config = jsonencode({
"days" : [0, 1, 2, 3],
"hours" : [0, 1, 3],
"timezone" : "America/Los_Angeles"
})
}
9 changes: 9 additions & 0 deletions internal/provider/models/reverse_etl_model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/segmentio/public-api-sdk-go/api"
)
Expand All @@ -13,6 +14,10 @@ type ReverseETLModelState struct {
Enabled types.Bool `tfsdk:"enabled"`
Query types.String `tfsdk:"query"`
QueryIdentifierColumn types.String `tfsdk:"query_identifier_column"`

// Deprecated, schedule moved to destination_subscription
ScheduleStrategy types.String `tfsdk:"schedule_strategy"`
ScheduleConfig jsontypes.Normalized `tfsdk:"schedule_config"`
}

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

// Deprecated, schedule moved to destination_subscription
r.ScheduleStrategy = types.StringPointerValue(nil)
r.ScheduleConfig = jsontypes.NewNormalizedNull()

return nil
}
39 changes: 28 additions & 11 deletions internal/provider/reverse_etl_model_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
"github.com/segmentio/terraform-provider-segment/internal/provider/models"

"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -66,11 +67,11 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
Required: true,
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.",
},
// "schedule_strategy": schema.StringAttribute{
// Optional: true,
// 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.",
// Description: "Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.",
// },
"schedule_strategy": schema.StringAttribute{
Optional: true,
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.",
Description: "Determines the strategy used for triggering syncs, which will be used in conjunction with scheduleConfig.",
},
"query": schema.StringAttribute{
Required: true,
Description: "The SQL query that will be executed to extract data from the connected Source.",
Expand All @@ -79,12 +80,12 @@ func (r *reverseETLModelResource) Schema(_ context.Context, _ resource.SchemaReq
Required: true,
Description: "Indicates the column named in `query` that should be used to uniquely identify the extracted records.",
},
// "schedule_config": schema.StringAttribute{
// Optional: true,
// 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.",
// Description: "Depending on the chosen strategy, configures the schedule for this model.",
// CustomType: jsontypes.NormalizedType{},
// },
"schedule_config": schema.StringAttribute{
Optional: true,
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.",
Description: "Depending on the chosen strategy, configures the schedule for this model.",
CustomType: jsontypes.NormalizedType{},
},
},
}
}
Expand Down Expand Up @@ -138,6 +139,10 @@ func (r *reverseETLModelResource) Create(ctx context.Context, req resource.Creat
if resp.Diagnostics.HasError() {
return
}

// Since we deprecated these values, we just need to set them to the plan values so there are no errors
resp.State.SetAttribute(ctx, path.Root("schedule_config"), plan.ScheduleConfig)
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), plan.ScheduleStrategy)
}

func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
Expand Down Expand Up @@ -180,6 +185,14 @@ func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadReq
if resp.Diagnostics.HasError() {
return
}

// Since we deprecated these values, we just need to set them to the plan values so there are no errors
if !previousState.ScheduleConfig.IsUnknown() {
resp.State.SetAttribute(ctx, path.Root("schedule_config"), previousState.ScheduleConfig)
}
if !previousState.ScheduleStrategy.IsUnknown() {
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), previousState.ScheduleStrategy)
}
}

func (r *reverseETLModelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down Expand Up @@ -231,6 +244,10 @@ func (r *reverseETLModelResource) Update(ctx context.Context, req resource.Updat
if resp.Diagnostics.HasError() {
return
}

// Since we deprecated these values, we just need to set them to the plan values so there are no errors
resp.State.SetAttribute(ctx, path.Root("schedule_config"), plan.ScheduleConfig)
resp.State.SetAttribute(ctx, path.Root("schedule_strategy"), plan.ScheduleStrategy)
}

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

0 comments on commit e862112

Please sign in to comment.