From 95bebbaffb4bb2141daa3fd65a395a92714620af Mon Sep 17 00:00:00 2001 From: Dean Huynh Date: Tue, 10 Sep 2024 11:17:44 -0700 Subject: [PATCH] Stop connecting sources and warehouses by default (#139) --- CHANGELOG.md | 3 +++ go.mod | 2 +- go.sum | 16 ++++++++++++++-- internal/provider/function_resource.go | 4 ++-- internal/provider/models/function.go | 2 +- internal/provider/models/reverse_etl_model.go | 19 ++++++++++++++++++- internal/provider/source_resource.go | 11 +++++++---- internal/provider/warehouse_resource.go | 11 +++++++---- 8 files changed, 53 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf643e4..6194a5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.1.0 (August 20, 2024) +Stops connecting newly created sources and warehouses by default. + ## 1.0.5 (August 12, 2024) Fixes a bug where user groups could not be cleared. diff --git a/go.mod b/go.mod index 6255c43..3996bcd 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-testing v1.10.0 - github.com/segmentio/public-api-sdk-go v0.0.0-20231114153454-3be55fde5c99 + github.com/segmentio/public-api-sdk-go v0.0.0-20240909200753-311bb8d791a2 gotest.tools/gotestsum v1.12.0 ) diff --git a/go.sum b/go.sum index 0b4939d..7478498 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,20 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= -github.com/segmentio/public-api-sdk-go v0.0.0-20231114153454-3be55fde5c99 h1:55dfJRsEeZLLFln+0gQ1pNZvalFMyeMV9nTPQwShkok= -github.com/segmentio/public-api-sdk-go v0.0.0-20231114153454-3be55fde5c99/go.mod h1:1mLoKkR7t90unwNx7qx9PicO3AX5NflFD7ny3TvLExU= +github.com/segmentio/public-api-sdk-go v0.0.0-20240820173358-a52384e5ccc7 h1:04d9X+Bw1RY+lmbs0DajdA61xSQOZCAIUJuZfcFpz0g= +github.com/segmentio/public-api-sdk-go v0.0.0-20240820173358-a52384e5ccc7/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240820210528-faf5e1da4b4a h1:vSCltBxaOD5NRP3zGh/Xha3evkt0ZeXdAc6fTDTuwzg= +github.com/segmentio/public-api-sdk-go v0.0.0-20240820210528-faf5e1da4b4a/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240905000934-07e8214ff9da h1:SiFK2+vk+r2zEfUUZm2FbfY6F050L5zPzKsCGlvdUg4= +github.com/segmentio/public-api-sdk-go v0.0.0-20240905000934-07e8214ff9da/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240905231636-2922a096fe56 h1:IKxTy9Mw02je+m8AhpnYaKqrrjzBzHRn+Y99C4kGsEo= +github.com/segmentio/public-api-sdk-go v0.0.0-20240905231636-2922a096fe56/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240906231017-4e91c4889f50 h1:RsFkUN2lGzupgzXLsWdDdvsPp1oj6kwHLgucV77MPCk= +github.com/segmentio/public-api-sdk-go v0.0.0-20240906231017-4e91c4889f50/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240906235131-c22dd0e0d0b9 h1:g8gpxgqCPsFvOKhu55fPXl6H3wNm0CdbOH8cNri/1Fs= +github.com/segmentio/public-api-sdk-go v0.0.0-20240906235131-c22dd0e0d0b9/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= +github.com/segmentio/public-api-sdk-go v0.0.0-20240909200753-311bb8d791a2 h1:vlKTelJ32DPBuiiSx2PJaxN9jJd3OFK2avHU/XR/qB8= +github.com/segmentio/public-api-sdk-go v0.0.0-20240909200753-311bb8d791a2/go.mod h1:yKkoPfcOkkYjiZQj4lRWxji0Qwc6ncNEf7wCfywochY= 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= diff --git a/internal/provider/function_resource.go b/internal/provider/function_resource.go index 64f8f1a..c312660 100644 --- a/internal/provider/function_resource.go +++ b/internal/provider/function_resource.go @@ -159,7 +159,7 @@ func (r *functionResource) Create(ctx context.Context, req resource.CreateReques resp.State.SetAttribute(ctx, path.Root("id"), function.Id) var state models.FunctionState - state.Fill(api.Function(function)) + state.Fill(function) // Destination functions append workspace name to display name causing inconsistency if state.ResourceType.ValueString() == "DESTINATION" || state.ResourceType.ValueString() == "INSERT_DESTINATION" { @@ -256,7 +256,7 @@ func (r *functionResource) Update(ctx context.Context, req resource.UpdateReques function := out.Data.GetFunction() - state.Fill(api.Function(function)) + state.Fill(function) // Destination functions append workspace name to display name causing inconsistency if state.ResourceType.ValueString() == "DESTINATION" || state.ResourceType.ValueString() == "INSERT_DESTINATION" { diff --git a/internal/provider/models/function.go b/internal/provider/models/function.go index a37be64..62b5fc3 100644 --- a/internal/provider/models/function.go +++ b/internal/provider/models/function.go @@ -41,7 +41,7 @@ type FunctionPlan struct { Settings types.Set `tfsdk:"settings"` } -func (f *FunctionState) Fill(function api.Function) { +func (f *FunctionState) Fill(function api.FunctionV1) { f.ID = types.StringPointerValue(function.Id) f.Code = types.StringPointerValue(function.Code) f.DisplayName = types.StringPointerValue(function.DisplayName) diff --git a/internal/provider/models/reverse_etl_model.go b/internal/provider/models/reverse_etl_model.go index 69fbcd6..56b313a 100644 --- a/internal/provider/models/reverse_etl_model.go +++ b/internal/provider/models/reverse_etl_model.go @@ -27,7 +27,7 @@ func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error { r.ScheduleStrategy = types.StringValue(model.ScheduleStrategy) r.Query = types.StringValue(model.Query) r.QueryIdentifierColumn = types.StringValue(model.QueryIdentifierColumn) - scheduleConfig, err := GetSettings(model.ScheduleConfig) + scheduleConfig, err := GetScheduleConfig(model.ScheduleConfig) if err != nil { return err } @@ -39,3 +39,20 @@ func (r *ReverseETLModelState) Fill(model api.ReverseEtlModel) error { return nil } + +func GetScheduleConfig(scheduleConfig api.NullableScheduleConfig) (jsontypes.Normalized, error) { + if !scheduleConfig.IsSet() { + return jsontypes.NewNormalizedNull(), nil + } + + 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 +} diff --git a/internal/provider/source_resource.go b/internal/provider/source_resource.go index d0d6615..f27ef9c 100644 --- a/internal/provider/source_resource.go +++ b/internal/provider/source_resource.go @@ -276,11 +276,14 @@ func (r *sourceResource) Create(ctx context.Context, req resource.CreateRequest, return } + disconnectAllWarehouses := true + out, body, err := r.client.SourcesAPI.CreateSource(r.authContext).CreateSourceV1Input(api.CreateSourceV1Input{ - Slug: plan.Slug.ValueString(), - Enabled: plan.Enabled.ValueBool(), - MetadataId: metadataID, - Settings: settings, + Slug: plan.Slug.ValueString(), + Enabled: plan.Enabled.ValueBool(), + MetadataId: metadataID, + Settings: settings, + DisconnectAllWarehouses: &disconnectAllWarehouses, }).Execute() if body != nil { defer body.Body.Close() diff --git a/internal/provider/warehouse_resource.go b/internal/provider/warehouse_resource.go index ed4191d..17413b5 100644 --- a/internal/provider/warehouse_resource.go +++ b/internal/provider/warehouse_resource.go @@ -219,11 +219,14 @@ func (r *warehouseResource) Create(ctx context.Context, req resource.CreateReque name = nil } + disconnectAllSources := true + out, body, err := r.client.WarehousesAPI.CreateWarehouse(r.authContext).CreateWarehouseV1Input(api.CreateWarehouseV1Input{ - Enabled: plan.Enabled.ValueBoolPointer(), - MetadataId: metadataID, - Settings: settings, - Name: name, + Enabled: plan.Enabled.ValueBoolPointer(), + MetadataId: metadataID, + Settings: settings, + Name: name, + DisconnectAllSources: &disconnectAllSources, }).Execute() if body != nil { defer body.Body.Close()