Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/hashicorp/t…
Browse files Browse the repository at this point in the history
…erraform-plugin-framework-validators-0.16.0
  • Loading branch information
deanhuynh authored Jan 15, 2025
2 parents 62b07b4 + 71794aa commit 5621714
Show file tree
Hide file tree
Showing 28 changed files with 153 additions and 113 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 1.2.0 (Octover 25, 2024)
## 1.2.2 (January 15, 2025)
Enabled support for `cron` and `dbt_cloud` schedule strategies on Reverse ETL subscriptions.

## 1.2.1 (October 25, 2024)
Fixes a bug where the `segment_reverse_etl_model` resource would continously update the schedule config. Also adds resource ID to error messages and upgrades some packages.

## 1.2.0 (October 25, 2024)
Moves RETL schedule config to destination_subscription and deprecates those fields in reverse_etl_model.

## 1.1.0 (August 20, 2024)
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/destination_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.16.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
)

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/destination_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d *destinationDataSource) Read(ctx context.Context, req datasource.ReadReq
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Destination",
fmt.Sprintf("Unable to read Destination (ID: %s)", state.ID.ValueString()),
getError(err, body),
)

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/destination_filter_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (r *destinationFilterResource) Read(ctx context.Context, req resource.ReadR
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Destination Filter",
fmt.Sprintf("Unable to read Destination Filter (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -271,7 +271,7 @@ func (r *destinationFilterResource) Update(ctx context.Context, req resource.Upd
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Destination Filter",
fmt.Sprintf("Unable to update Destination Filter (ID: %s)", state.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -314,7 +314,7 @@ func (r *destinationFilterResource) Delete(ctx context.Context, req resource.Del
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Destination Filter",
fmt.Sprintf("Unable to delete Destination Filter (ID: %s)", state.ID.ValueString()),
getError(err, body),
)

Expand Down
4 changes: 2 additions & 2 deletions internal/provider/destination_metadata_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (d *destinationMetadataDataSource) Read(ctx context.Context, req datasource
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Source metadata",
fmt.Sprintf("Unable to read Source metadata (ID: %s)", state.ID.ValueString()),
getError(err, body),
)

Expand All @@ -412,7 +412,7 @@ func (d *destinationMetadataDataSource) Read(ctx context.Context, req datasource
err = state.Fill(destinationMetadata)
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Source metadata",
fmt.Sprintf("Unable to read Source metadata (ID: %s)", state.ID.ValueString()),
err.Error(),
)

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/destination_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (r *destinationResource) Read(ctx context.Context, req resource.ReadRequest
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Destination",
fmt.Sprintf("Unable to read Destination (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -650,7 +650,7 @@ func (r *destinationResource) Update(ctx context.Context, req resource.UpdateReq
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Destination",
fmt.Sprintf("Unable to update Destination (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -695,7 +695,7 @@ func (r *destinationResource) Delete(ctx context.Context, req resource.DeleteReq
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Destination",
fmt.Sprintf("Unable to delete Destination (ID: %s)", state.ID.ValueString()),
getError(err, body),
)

Expand Down
62 changes: 57 additions & 5 deletions internal/provider/destination_subscription_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -182,7 +182,7 @@ func (r *destinationSubscriptionResource) Create(ctx context.Context, req resour
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Destination subscription",
fmt.Sprintf("Unable to update Destination subscription (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -229,7 +229,7 @@ func (r *destinationSubscriptionResource) Read(ctx context.Context, req resource
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Destination subscription",
fmt.Sprintf("Unable to read Destination subscription (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -312,7 +312,7 @@ func (r *destinationSubscriptionResource) Update(ctx context.Context, req resour
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Destination subscription",
fmt.Sprintf("Unable to update Destination subscription (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -353,7 +353,7 @@ func (r *destinationSubscriptionResource) Delete(ctx context.Context, req resour
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Destination subscription",
fmt.Sprintf("Unable to delete Destination subscription (ID: %s)", config.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/function_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (r *functionResource) Read(ctx context.Context, req resource.ReadRequest, r
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Function",
fmt.Sprintf("Unable to read Function (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -247,7 +247,7 @@ func (r *functionResource) Update(ctx context.Context, req resource.UpdateReques
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Function",
fmt.Sprintf("Unable to update Function (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -284,7 +284,7 @@ func (r *functionResource) Delete(ctx context.Context, req resource.DeleteReques
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Function",
fmt.Sprintf("Unable to delete Function (ID: %s)", config.ID.ValueString()),
getError(err, body),
)

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/insert_function_instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (r *insertFunctionInstanceResource) Read(ctx context.Context, req resource.
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Insert Function instance",
fmt.Sprintf("Unable to read Insert Function instance (ID: %s)", previousState.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -227,7 +227,7 @@ func (r *insertFunctionInstanceResource) Update(ctx context.Context, req resourc
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Insert Function instance",
fmt.Sprintf("Unable to update Insert Function instance (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -271,7 +271,7 @@ func (r *insertFunctionInstanceResource) Delete(ctx context.Context, req resourc
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Insert Function instance",
fmt.Sprintf("Unable to delete Insert Function instance (ID: %s)", config.ID.ValueString()),
getError(err, body),
)

Expand Down
51 changes: 15 additions & 36 deletions internal/provider/models/reverse_etl_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions internal/provider/profiles_warehouse_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (r *profilesWarehouseResource) Read(ctx context.Context, req resource.ReadR
warehouse, err := findProfileWarehouse(r.authContext, r.client, previousState.ID.ValueString(), previousState.SpaceID.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Unable to read Profiles Warehouse",
fmt.Sprintf("Unable to read Profiles Warehouse (ID: %s)", previousState.ID.ValueString()),
err.Error(),
)

Expand Down Expand Up @@ -240,7 +240,7 @@ func (r *profilesWarehouseResource) Update(ctx context.Context, req resource.Upd
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to update Profiles Warehouse",
fmt.Sprintf("Unable to update Profiles Warehouse (ID: %s)", plan.ID.ValueString()),
getError(err, body),
)

Expand Down Expand Up @@ -283,7 +283,7 @@ func (r *profilesWarehouseResource) Delete(ctx context.Context, req resource.Del
}
if err != nil {
resp.Diagnostics.AddError(
"Unable to delete Profiles Warehouse",
fmt.Sprintf("Unable to delete Profiles Warehouse (ID: %s)", config.ID.ValueString()),
getError(err, body),
)

Expand Down
Loading

0 comments on commit 5621714

Please sign in to comment.