diff --git a/docs/resources/destination_subscription.md b/docs/resources/destination_subscription.md index 68e701b..bf810e9 100644 --- a/docs/resources/destination_subscription.md +++ b/docs/resources/destination_subscription.md @@ -86,7 +86,7 @@ resource "segment_destination_subscription" "send_to_webhook" { Required: -- `strategy` (String) Strategy supports three modes: PERIODIC, SPECIFIC_DAYS, or MANUAL. +- `strategy` (String) Strategy supports the following modes: PERIODIC, SPECIFIC_DAYS, CRON, DBT_CLOUD or MANUAL. Optional: diff --git a/go.mod b/go.mod index 69e6c86..ad47a01 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 github.com/hashicorp/terraform-plugin-go v0.25.0 github.com/hashicorp/terraform-plugin-testing v1.10.0 - github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559 + github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd gotest.tools/gotestsum v1.12.0 ) diff --git a/go.sum b/go.sum index b828eae..2365418 100644 --- a/go.sum +++ b/go.sum @@ -187,6 +187,8 @@ github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3V github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559 h1:6jgXPksz5bEJUMbhp4biSIViye/Os2yfAOx9yy44e1g= github.com/segmentio/public-api-sdk-go v0.0.0-20241025180535-501a23c07559/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd h1:slroHJmwguMVr+wLnpigxN+51E6rkeoSsdp0f2YdmTI= +github.com/segmentio/public-api-sdk-go v0.0.0-20250113195817-34106b6e08dd/go.mod h1:rtbFvYN1VVsfSc55BtGTC45YwkcrbOgCwTqZwlauBh0= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= 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 github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= diff --git a/internal/provider/destination_subscription_resource.go b/internal/provider/destination_subscription_resource.go index d7aaa52..72392a9 100644 --- a/internal/provider/destination_subscription_resource.go +++ b/internal/provider/destination_subscription_resource.go @@ -100,7 +100,7 @@ func (r *destinationSubscriptionResource) Schema(_ context.Context, _ resource.S Attributes: map[string]schema.Attribute{ "strategy": schema.StringAttribute{ Required: true, - Description: "Strategy supports three modes: PERIODIC, SPECIFIC_DAYS, or MANUAL.", + Description: "Strategy supports the following modes: PERIODIC, SPECIFIC_DAYS, CRON, DBT_CLOUD or MANUAL.", }, "config": schema.StringAttribute{ Optional: true, @@ -494,6 +494,58 @@ func getSchedule(ctx context.Context, planSchedule basetypes.ObjectValue) (*api. "Manual reverse ETL schedule strategy does not require a config", ) reverseETLSchedule.Config = *api.NewNullableConfig(nil) + } else if reverseETLSchedule.Strategy == "CRON" { + reverseETLModelScheduleConfig := api.ReverseEtlCronScheduleConfig{} + var config string + err = wrappedReverseETLModelScheduleConfig.As(&config) + if err != nil { + diags.AddError( + "Unable to decode reverse ETL schedule config", + err.Error(), + ) + + return nil, diags + } + + err = json.Unmarshal([]byte(config), &reverseETLModelScheduleConfig) + if err != nil { + diags.AddError( + "Unable to decode reverse ETL schedule config", + err.Error(), + ) + + return nil, diags + } + + reverseETLSchedule.Config = *api.NewNullableConfig(&api.Config{ + ReverseEtlCronScheduleConfig: &reverseETLModelScheduleConfig, + }) + } else if reverseETLSchedule.Strategy == "DBT_CLOUD" { + reverseETLModelScheduleConfig := api.ReverseEtlDbtCloudScheduleConfig{} + var config string + err = wrappedReverseETLModelScheduleConfig.As(&config) + if err != nil { + diags.AddError( + "Unable to decode reverse ETL schedule config", + err.Error(), + ) + + return nil, diags + } + + err = json.Unmarshal([]byte(config), &reverseETLModelScheduleConfig) + if err != nil { + diags.AddError( + "Unable to decode reverse ETL schedule config", + err.Error(), + ) + + return nil, diags + } + + reverseETLSchedule.Config = *api.NewNullableConfig(&api.Config{ + ReverseEtlDbtCloudScheduleConfig: &reverseETLModelScheduleConfig, + }) } else { diags.AddError( "Unsupported reverse ETL schedule strategy", diff --git a/internal/provider/models/reverse_etl_model.go b/internal/provider/models/reverse_etl_model.go index 56b313a..a57f452 100644 --- a/internal/provider/models/reverse_etl_model.go +++ b/internal/provider/models/reverse_etl_model.go @@ -7,15 +7,17 @@ import ( ) type ReverseETLModelState struct { - ID types.String `tfsdk:"id"` - SourceID types.String `tfsdk:"source_id"` - Name types.String `tfsdk:"name"` - Description types.String `tfsdk:"description"` - Enabled types.Bool `tfsdk:"enabled"` - ScheduleStrategy types.String `tfsdk:"schedule_strategy"` - Query types.String `tfsdk:"query"` - QueryIdentifierColumn types.String `tfsdk:"query_identifier_column"` - ScheduleConfig jsontypes.Normalized `tfsdk:"schedule_config"` + ID types.String `tfsdk:"id"` + SourceID types.String `tfsdk:"source_id"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + 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 { @@ -24,35 +26,12 @@ func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error { r.Name = types.StringValue(model.Name) r.Description = types.StringValue(model.Description) r.Enabled = types.BoolValue(model.Enabled) - r.ScheduleStrategy = types.StringValue(model.ScheduleStrategy) r.Query = types.StringValue(model.Query) r.QueryIdentifierColumn = types.StringValue(model.QueryIdentifierColumn) - scheduleConfig, err := GetScheduleConfig(model.ScheduleConfig) - if err != nil { - return err - } - r.ScheduleConfig = scheduleConfig - if r.ScheduleConfig.IsNull() { - empty := "{}" - r.ScheduleConfig = jsontypes.NewNormalizedPointerValue(&empty) - } - return nil -} - -func GetScheduleConfig(scheduleConfig api.NullableScheduleConfig) (jsontypes.Normalized, error) { - if !scheduleConfig.IsSet() { - return jsontypes.NewNormalizedNull(), nil - } + // Deprecated, schedule moved to destination_subscription + r.ScheduleStrategy = types.StringPointerValue(nil) + r.ScheduleConfig = jsontypes.NewNormalizedNull() - jsonScheduleConfigString, err := scheduleConfig.Get().MarshalJSON() - if err != nil { - return jsontypes.NewNormalizedNull(), err - } - - if jsonScheduleConfigString == nil { - return jsontypes.NewNormalizedValue("{}"), nil - } - - return jsontypes.NewNormalizedValue(string(jsonScheduleConfigString)), nil + return nil }