From ea6841d7d4da3022083837a37c1336a564c98547 Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Thu, 30 May 2024 13:32:22 -0600 Subject: [PATCH 1/7] Fix project warnings - Tweak go.mod to have correct syntax - Run `go mod tidy` - Update to preferred build constraint in tools.go (as of Go 1.18) --- go.mod | 2 +- go.sum | 10 ---------- tools/tools.go | 1 + 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 5299f313..ea88fe7c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/dbt-labs/terraform-provider-dbtcloud -go 1.21.0 +go 1.21 toolchain go1.21.4 diff --git a/go.sum b/go.sum index 6516086c..b5ab79dc 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4er github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -101,14 +99,10 @@ github.com/hashicorp/terraform-json v0.21.0 h1:9NQxbLNqPbEMze+S6+YluEdXgJmhQykRy github.com/hashicorp/terraform-json v0.21.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk= github.com/hashicorp/terraform-plugin-docs v0.19.2 h1:YjdKa1vuqt9EnPYkkrv9HnGZz175HhSJ7Vsn8yZeWus= github.com/hashicorp/terraform-plugin-docs v0.19.2/go.mod h1:gad2aP6uObFKhgNE8DR9nsEuEQnibp7il0jZYYOunWY= -github.com/hashicorp/terraform-plugin-framework v1.7.0 h1:wOULbVmfONnJo9iq7/q+iBOBJul5vRovaYJIu2cY/Pw= -github.com/hashicorp/terraform-plugin-framework v1.7.0/go.mod h1:jY9Id+3KbZ17OMpulgnWLSfwxNVYSoYBQFTgsx044CI= github.com/hashicorp/terraform-plugin-framework v1.8.0 h1:P07qy8RKLcoBkCrY2RHJer5AEvJnDuXomBgou6fD8kI= github.com/hashicorp/terraform-plugin-framework v1.8.0/go.mod h1:/CpTukO88PcL/62noU7cuyaSJ4Rsim+A/pa+3rUVufY= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= -github.com/hashicorp/terraform-plugin-go v0.22.1 h1:iTS7WHNVrn7uhe3cojtvWWn83cm2Z6ryIUDTRO0EV7w= -github.com/hashicorp/terraform-plugin-go v0.22.1/go.mod h1:qrjnqRghvQ6KnDbB12XeZ4FluclYwptntoWCr9QaXTI= github.com/hashicorp/terraform-plugin-go v0.22.2 h1:5o8uveu6eZUf5J7xGPV0eY0TPXg3qpmwX9sce03Bxnc= github.com/hashicorp/terraform-plugin-go v0.22.2/go.mod h1:drq8Snexp9HsbFZddvyLHN6LuWHHndSQg+gV+FPkcIM= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= @@ -279,12 +273,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/tools/tools.go b/tools/tools.go index f03ce3dd..8abc7c8d 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,3 +1,4 @@ +//go:build tools // +build tools package tools From 464437f5a86b40c2f8666a3c9bafa42b2a73ec4e Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Thu, 30 May 2024 13:34:10 -0600 Subject: [PATCH 2/7] Update document generation - Move guides into templates directory - These are copied as-is by `tfplugindocs` so unnecessary to do in Makefile --- Makefile | 2 +- {guides => templates/guides}/1_getting_started.md | 0 {guides => templates/guides}/2_leveraging_http_provider.md | 0 .../guides}/3_importing_existing_configuration.md | 0 {guides => templates/guides}/99_list_resources.md | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {guides => templates/guides}/1_getting_started.md (100%) rename {guides => templates/guides}/2_leveraging_http_provider.md (100%) rename {guides => templates/guides}/3_importing_existing_configuration.md (100%) rename {guides => templates/guides}/99_list_resources.md (100%) diff --git a/Makefile b/Makefile index cfbfa57e..3b48b2a8 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ install: build mv ./$(BINARY) $(HOME)/.terraform.d/plugins/$(BINARY) doc: - go generate ./... && cp -r guides docs/ + go generate ./... test: deps go test -mod=readonly -count=1 ./... diff --git a/guides/1_getting_started.md b/templates/guides/1_getting_started.md similarity index 100% rename from guides/1_getting_started.md rename to templates/guides/1_getting_started.md diff --git a/guides/2_leveraging_http_provider.md b/templates/guides/2_leveraging_http_provider.md similarity index 100% rename from guides/2_leveraging_http_provider.md rename to templates/guides/2_leveraging_http_provider.md diff --git a/guides/3_importing_existing_configuration.md b/templates/guides/3_importing_existing_configuration.md similarity index 100% rename from guides/3_importing_existing_configuration.md rename to templates/guides/3_importing_existing_configuration.md diff --git a/guides/99_list_resources.md b/templates/guides/99_list_resources.md similarity index 100% rename from guides/99_list_resources.md rename to templates/guides/99_list_resources.md From 007f337d85075745ca26b8228433dfa6922a3120 Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Wed, 5 Jun 2024 09:00:38 -0600 Subject: [PATCH 3/7] Add support for on_warning to dbtcloud_(partial_)notification Acceptance tests are pending --- pkg/dbt_cloud/notification.go | 3 ++ .../objects/notification/data_source.go | 10 +++++ pkg/framework/objects/notification/model.go | 5 ++- .../objects/notification/resource.go | 18 +++++++- pkg/framework/objects/notification/schema.go | 7 ++++ .../objects/partial_notification/model.go | 18 +++++--- .../objects/partial_notification/resource.go | 39 ++++++++++++++--- .../objects/partial_notification/schema.go | 7 ++++ pkg/provider/sdk_provider.go | 42 ++++++++----------- 9 files changed, 112 insertions(+), 37 deletions(-) diff --git a/pkg/dbt_cloud/notification.go b/pkg/dbt_cloud/notification.go index 24215024..b406960f 100644 --- a/pkg/dbt_cloud/notification.go +++ b/pkg/dbt_cloud/notification.go @@ -19,6 +19,7 @@ type Notification struct { UserId int `json:"user_id"` OnCancel []int `json:"on_cancel"` OnFailure []int `json:"on_failure"` + OnWarning []int `json:"on_warning"` OnSuccess []int `json:"on_success"` State int `json:"state"` NotificationType int `json:"type"` @@ -60,6 +61,7 @@ func (c *Client) CreateNotification( userId int, onCancel []int, onFailure []int, + onWarning []int, onSuccess []int, state int, notificationType int, @@ -72,6 +74,7 @@ func (c *Client) CreateNotification( UserId: userId, OnCancel: onCancel, OnFailure: onFailure, + OnWarning: onWarning, OnSuccess: onSuccess, State: state, NotificationType: notificationType, diff --git a/pkg/framework/objects/notification/data_source.go b/pkg/framework/objects/notification/data_source.go index acad955d..d0a981f7 100644 --- a/pkg/framework/objects/notification/data_source.go +++ b/pkg/framework/objects/notification/data_source.go @@ -58,6 +58,11 @@ func (d *notificationDataSource) Schema( Computed: true, Description: "List of job IDs to trigger the webhook on failure", }, + "on_warning": schema.SetAttribute{ + ElementType: types.Int64Type, + Computed: true, + Description: "List of job IDs to trigger the webhook on warning", + }, "on_success": schema.SetAttribute{ ElementType: types.Int64Type, Computed: true, @@ -124,6 +129,11 @@ func (d *notificationDataSource) Read( types.Int64Type, notification.OnFailure, ) + data.OnWarning, _ = types.SetValueFrom( + context.Background(), + types.Int64Type, + notification.OnWarning, + ) data.OnSuccess, _ = types.SetValueFrom( context.Background(), types.Int64Type, diff --git a/pkg/framework/objects/notification/model.go b/pkg/framework/objects/notification/model.go index ab53dd85..a45a5766 100644 --- a/pkg/framework/objects/notification/model.go +++ b/pkg/framework/objects/notification/model.go @@ -13,6 +13,7 @@ type NotificationResourceModel struct { UserID types.Int64 `tfsdk:"user_id"` OnCancel types.Set `tfsdk:"on_cancel"` OnFailure types.Set `tfsdk:"on_failure"` + OnWarning types.Set `tfsdk:"on_warning"` OnSuccess types.Set `tfsdk:"on_success"` State types.Int64 `tfsdk:"state"` NotificationType types.Int64 `tfsdk:"notification_type"` @@ -26,6 +27,7 @@ type NotificationDataSourceModel struct { UserID types.Int64 `tfsdk:"user_id"` OnCancel types.Set `tfsdk:"on_cancel"` OnFailure types.Set `tfsdk:"on_failure"` + OnWarning types.Set `tfsdk:"on_warning"` OnSuccess types.Set `tfsdk:"on_success"` State types.Int64 `tfsdk:"state"` NotificationType types.Int64 `tfsdk:"notification_type"` @@ -34,11 +36,12 @@ type NotificationDataSourceModel struct { SlackChannelName types.String `tfsdk:"slack_channel_name"` } -func ConvertNotificationModelToData(model NotificationResourceModel) dbt_cloud.Notification { +func ConvertStateToNotification(model NotificationResourceModel) dbt_cloud.Notification { notification := dbt_cloud.Notification{ UserId: int(model.UserID.ValueInt64()), OnCancel: helper.Int64SetToIntSlice(model.OnCancel), OnFailure: helper.Int64SetToIntSlice(model.OnFailure), + OnWarning: helper.Int64SetToIntSlice(model.OnWarning), OnSuccess: helper.Int64SetToIntSlice(model.OnSuccess), State: int(model.State.ValueInt64()), NotificationType: int(model.NotificationType.ValueInt64()), diff --git a/pkg/framework/objects/notification/resource.go b/pkg/framework/objects/notification/resource.go index 93363dc1..59e6efdd 100644 --- a/pkg/framework/objects/notification/resource.go +++ b/pkg/framework/objects/notification/resource.go @@ -110,6 +110,11 @@ func (r *notificationResource) Read( types.Int64Type, notification.OnFailure, ) + data.OnWarning, _ = types.SetValueFrom( + context.Background(), + types.Int64Type, + notification.OnWarning, + ) data.OnSuccess, _ = types.SetValueFrom( context.Background(), types.Int64Type, @@ -137,17 +142,23 @@ func (r *notificationResource) Create( return } - var intOnCancel, intOnFailure, intOnSuccess []int + var intOnCancel, intOnFailure, intOnWarning, intOnSuccess []int diags := data.OnCancel.ElementsAs(context.Background(), &intOnCancel, false) if diags.HasError() { return } + diags = data.OnFailure.ElementsAs(context.Background(), &intOnFailure, false) if diags.HasError() { return } + diags = data.OnWarning.ElementsAs(context.Background(), &intOnWarning, false) + if diags.HasError() { + return + } + diags = data.OnSuccess.ElementsAs(context.Background(), &intOnSuccess, false) if diags.HasError() { return @@ -157,6 +168,7 @@ func (r *notificationResource) Create( int(data.UserID.ValueInt64()), intOnCancel, intOnFailure, + intOnWarning, intOnSuccess, int(data.State.ValueInt64()), int(data.NotificationType.ValueInt64()), @@ -233,6 +245,10 @@ func (r *notificationResource) Update( state.OnFailure = plan.OnFailure } + if !plan.OnWarning.Equal(state.OnWarning) { + state.OnWarning = plan.OnWarning + } + if !plan.OnSuccess.Equal(state.OnSuccess) { state.OnSuccess = plan.OnSuccess } diff --git a/pkg/framework/objects/notification/schema.go b/pkg/framework/objects/notification/schema.go index 0aa5d228..c12a7f9e 100644 --- a/pkg/framework/objects/notification/schema.go +++ b/pkg/framework/objects/notification/schema.go @@ -53,6 +53,13 @@ func (r *notificationResource) Schema( Default: helper.EmptySetDefault(types.Int64Type), Description: "List of job IDs to trigger the webhook on failure", }, + "on_warning": schema.SetAttribute{ + ElementType: types.Int64Type, + Optional: true, + Computed: true, + Default: helper.EmptySetDefault(types.Int64Type), + Description: "List of job IDs to trigger the webhook on warning", + }, "on_success": schema.SetAttribute{ ElementType: types.Int64Type, Optional: true, diff --git a/pkg/framework/objects/partial_notification/model.go b/pkg/framework/objects/partial_notification/model.go index 368f774c..78eb36ab 100644 --- a/pkg/framework/objects/partial_notification/model.go +++ b/pkg/framework/objects/partial_notification/model.go @@ -42,26 +42,34 @@ func matchPartial( )) { return false } + + // TODO(cwalden): What happens with the other cases(i.e. the deprecated `3` type)? } return true } func extractModelJobLists( data notification.NotificationResourceModel, -) (intOnCancel, intOnFailure, intOnSuccess []int, ok bool) { +) (intOnCancel, intOnFailure, intOnWarning, intOnSuccess []int, ok bool) { diags := data.OnCancel.ElementsAs(context.Background(), &intOnCancel, false) if diags.HasError() { - return nil, nil, nil, false + return nil, nil, nil, nil, false } + diags = data.OnFailure.ElementsAs(context.Background(), &intOnFailure, false) if diags.HasError() { - return nil, nil, nil, false + return nil, nil, nil, nil, false + } + + diags = data.OnWarning.ElementsAs(context.Background(), &intOnWarning, false) + if diags.HasError() { + return nil, nil, nil, nil, false } diags = data.OnSuccess.ElementsAs(context.Background(), &intOnSuccess, false) if diags.HasError() { - return nil, nil, nil, false + return nil, nil, nil, nil, false } - return intOnCancel, intOnFailure, intOnSuccess, true + return intOnCancel, intOnFailure, intOnWarning, intOnSuccess, true } diff --git a/pkg/framework/objects/partial_notification/resource.go b/pkg/framework/objects/partial_notification/resource.go index 4933beb4..488f11a1 100644 --- a/pkg/framework/objects/partial_notification/resource.go +++ b/pkg/framework/objects/partial_notification/resource.go @@ -146,7 +146,7 @@ func (r *partialNotificationResource) Read( state.SlackChannelName = types.StringPointerValue(notification.SlackChannelName) // we set the "partial" values by intersecting the config with the remote - intOnCancel, intOnFailure, intOnSuccess, ok := extractModelJobLists(state) + intOnCancel, intOnFailure, intOnWarning, intOnSuccess, ok := extractModelJobLists(state) if !ok { resp.Diagnostics.AddError("Error extracting the model job lists", "") return @@ -164,6 +164,12 @@ func (r *partialNotificationResource) Read( lo.Intersect(intOnFailure, notification.OnFailure), ) + state.OnWarning, _ = types.SetValueFrom( + context.Background(), + types.Int64Type, + lo.Intersect(intOnWarning, notification.OnWarning), + ) + state.OnSuccess, _ = types.SetValueFrom( context.Background(), types.Int64Type, @@ -187,7 +193,7 @@ func (r *partialNotificationResource) Create( } // we read the values from the config - intOnCancel, intOnFailure, intOnSuccess, ok := extractModelJobLists(plan) + intOnCancel, intOnFailure, intOnWarning, intOnSuccess, ok := extractModelJobLists(plan) if !ok { resp.Diagnostics.AddError("Error extracting the model job lists", "") return @@ -228,6 +234,10 @@ func (r *partialNotificationResource) Create( remoteOnFailure := fullNotification.OnFailure missingOnFailure, _ := lo.Difference(configOnFailure, remoteOnFailure) + configOnWarning := intOnWarning + remoteOnWarning := fullNotification.OnWarning + missingOnWarning := lo.Without(configOnWarning, remoteOnWarning...) + configOnSuccess := intOnSuccess remoteOnSuccess := fullNotification.OnSuccess missingOnSuccess, _ := lo.Difference(configOnSuccess, remoteOnSuccess) @@ -237,6 +247,7 @@ func (r *partialNotificationResource) Create( plan.UserID == types.Int64Value(int64(fullNotification.UserId)) && len(missingOnCancel) == 0 && len(missingOnFailure) == 0 && + len(missingOnWarning) == 0 && len(missingOnSuccess) == 0 { // nothing to do if they are all the same resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...) @@ -246,6 +257,7 @@ func (r *partialNotificationResource) Create( // and we update the notification allOnCancel := append(remoteOnCancel, missingOnCancel...) allOnFailure := append(remoteOnFailure, missingOnFailure...) + allOnWarning := append(remoteOnWarning, missingOnWarning...) allOnSuccess := append(remoteOnSuccess, missingOnSuccess...) _, err := r.client.UpdateNotification( @@ -256,6 +268,7 @@ func (r *partialNotificationResource) Create( UserId: int(plan.UserID.ValueInt64()), OnCancel: allOnCancel, OnFailure: allOnFailure, + OnWarning: allOnWarning, OnSuccess: allOnSuccess, State: int(plan.State.ValueInt64()), NotificationType: int(plan.NotificationType.ValueInt64()), @@ -280,6 +293,7 @@ func (r *partialNotificationResource) Create( int(plan.UserID.ValueInt64()), intOnCancel, intOnFailure, + intOnWarning, intOnSuccess, int(plan.State.ValueInt64()), int(plan.NotificationType.ValueInt64()), @@ -321,7 +335,7 @@ func (r *partialNotificationResource) Delete( } // we read the values from the config - intOnCancel, intOnFailure, intOnSuccess, ok := extractModelJobLists(state) + intOnCancel, intOnFailure, intOnWarning, intOnSuccess, ok := extractModelJobLists(state) if !ok { resp.Diagnostics.AddError("Error extracting the model job lists", "") return @@ -335,11 +349,15 @@ func (r *partialNotificationResource) Delete( remoteOnFailure := notification.OnFailure requiredOnFailure, _ := lo.Difference(remoteOnFailure, configOnFailure) + configOnWarning := intOnWarning + remoteOnWarning := notification.OnWarning + requiredOnWarning := lo.Without(remoteOnWarning, configOnWarning...) + configOnSuccess := intOnSuccess remoteOnSuccess := notification.OnSuccess requiredOnSuccess, _ := lo.Difference(remoteOnSuccess, configOnSuccess) - if len(requiredOnCancel) > 0 || len(requiredOnFailure) > 0 || len(requiredOnSuccess) > 0 { + if len(requiredOnCancel) > 0 || len(requiredOnFailure) > 0 || len(requiredOnWarning) > 0 || len(requiredOnSuccess) > 0 { // we update the notification if there are some jobs left // but we leave the notification existing, without deleting it entirely _, err = r.client.UpdateNotification( @@ -350,6 +368,7 @@ func (r *partialNotificationResource) Delete( UserId: int(state.UserID.ValueInt64()), OnCancel: requiredOnCancel, OnFailure: requiredOnFailure, + OnWarning: requiredOnWarning, OnSuccess: requiredOnSuccess, State: int(state.State.ValueInt64()), NotificationType: int(state.NotificationType.ValueInt64()), @@ -400,13 +419,13 @@ func (r *partialNotificationResource) Update( } // we compare the partial objects and update them if needed - intOnCancelPlan, intOnFailurePlan, intOnSuccessPlan, ok := extractModelJobLists(plan) + intOnCancelPlan, intOnFailurePlan, intOnWarningPlan, intOnSuccessPlan, ok := extractModelJobLists(plan) if !ok { resp.Diagnostics.AddError("Error extracting the model job lists from the plan", "") return } - intOnCancelState, intOnFailureState, intOnSuccessState, ok := extractModelJobLists(state) + intOnCancelState, intOnFailureState, intOnWarningState, intOnSuccessState, ok := extractModelJobLists(state) if !ok { resp.Diagnostics.AddError("Error extracting the model job lists from the state", "") return @@ -420,6 +439,11 @@ func (r *partialNotificationResource) Update( deletedOnFailure, newOnFailure := lo.Difference(intOnFailureState, intOnFailurePlan) requiredOnFailure, _ := lo.Difference(lo.Union(remoteOnFailure, newOnFailure), deletedOnFailure) + remoteOnWarning := notification.OnWarning + deletedOnWarning := lo.Without(intOnWarningState, intOnWarningPlan...) + newOnWarning := lo.Without(intOnWarningPlan, intOnWarningState...) + requiredOnWarning := lo.Without(lo.Union(remoteOnWarning, newOnWarning), deletedOnWarning...) + remoteOnSuccess := notification.OnSuccess deletedOnSuccess, newOnSuccess := lo.Difference(intOnSuccessState, intOnSuccessPlan) requiredOnSuccess, _ := lo.Difference(lo.Union(remoteOnSuccess, newOnSuccess), deletedOnSuccess) @@ -431,6 +455,8 @@ func (r *partialNotificationResource) Update( len(newOnCancel) > 0 || len(deletedOnFailure) > 0 || len(newOnFailure) > 0 || + len(deletedOnWarning) > 0 || + len(newOnWarning) > 0 || len(deletedOnSuccess) > 0 || len(newOnSuccess) > 0 { @@ -443,6 +469,7 @@ func (r *partialNotificationResource) Update( Id: notification.Id, UserId: int(plan.UserID.ValueInt64()), OnCancel: requiredOnCancel, + OnWarning: requiredOnWarning, OnFailure: requiredOnFailure, OnSuccess: requiredOnSuccess, State: int(plan.State.ValueInt64()), diff --git a/pkg/framework/objects/partial_notification/schema.go b/pkg/framework/objects/partial_notification/schema.go index 590671aa..4392a3eb 100644 --- a/pkg/framework/objects/partial_notification/schema.go +++ b/pkg/framework/objects/partial_notification/schema.go @@ -70,6 +70,13 @@ func (r *partialNotificationResource) Schema( Default: helper.EmptySetDefault(types.Int64Type), Description: "List of job IDs to trigger the webhook on failure Those will be added/removed when config is added/removed.", }, + "on_warning": schema.SetAttribute{ + ElementType: types.Int64Type, + Optional: true, + Computed: true, + Default: helper.EmptySetDefault(types.Int64Type), + Description: "List of job IDs to trigger the webhook on warning Those will be added/removed when config is added/removed.", + }, "on_success": schema.SetAttribute{ ElementType: types.Int64Type, Optional: true, diff --git a/pkg/provider/sdk_provider.go b/pkg/provider/sdk_provider.go index 7b6b1643..53841d7e 100644 --- a/pkg/provider/sdk_provider.go +++ b/pkg/provider/sdk_provider.go @@ -16,31 +16,25 @@ import ( func SDKProvider(version string) func() *schema.Provider { return func() *schema.Provider { - // required := true - // optional := false - // if version == "test" { - // required = false - // optional = true - // } - - p := &schema.Provider{Schema: map[string]*schema.Schema{ - "token": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Sensitive: true, - Description: "API token for your dbt Cloud. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_TOKEN`", + p := &schema.Provider{ + Schema: map[string]*schema.Schema{ + "token": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "API token for your dbt Cloud. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_TOKEN`", + }, + "account_id": { + Type: schema.TypeInt, + Optional: true, + Description: "Account identifier for your dbt Cloud implementation. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_ACCOUNT_ID`", + }, + "host_url": { + Type: schema.TypeString, + Optional: true, + Description: "URL for your dbt Cloud deployment. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_HOST_URL` - Defaults to https://cloud.getdbt.com/api", + }, }, - "account_id": &schema.Schema{ - Type: schema.TypeInt, - Optional: true, - Description: "Account identifier for your dbt Cloud implementation. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_ACCOUNT_ID`", - }, - "host_url": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Description: "URL for your dbt Cloud deployment. Instead of setting the parameter, you can set the environment variable `DBT_CLOUD_HOST_URL` - Defaults to https://cloud.getdbt.com/api", - }, - }, DataSourcesMap: map[string]*schema.Resource{ "dbtcloud_job": data_sources.DatasourceJob(), "dbtcloud_project": data_sources.DatasourceProject(), From 73bb8218e02146e1e7863d7dfb3433c4912377d8 Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Wed, 5 Jun 2024 10:06:10 -0600 Subject: [PATCH 4/7] Regen docs --- docs/data-sources/notification.md | 1 + docs/resources/notification.md | 1 + docs/resources/partial_notification.md | 1 + 3 files changed, 3 insertions(+) diff --git a/docs/data-sources/notification.md b/docs/data-sources/notification.md index 97a5c29f..fd6199ff 100644 --- a/docs/data-sources/notification.md +++ b/docs/data-sources/notification.md @@ -32,6 +32,7 @@ data "dbtcloud_notification" "my_notification" { - `on_cancel` (Set of Number) List of job IDs to trigger the webhook on cancel - `on_failure` (Set of Number) List of job IDs to trigger the webhook on failure - `on_success` (Set of Number) List of job IDs to trigger the webhook on success +- `on_warning` (Set of Number) List of job IDs to trigger the webhook on warning - `slack_channel_id` (String) The ID of the Slack channel to receive the notification. It can be found at the bottom of the Slack channel settings - `slack_channel_name` (String) The name of the slack channel - `state` (Number) State of the notification (1 = active (default), 2 = inactive) diff --git a/docs/resources/notification.md b/docs/resources/notification.md index f96ed95e..625e6727 100644 --- a/docs/resources/notification.md +++ b/docs/resources/notification.md @@ -71,6 +71,7 @@ resource "dbtcloud_notification" "prod_job_slack_notifications" { - `on_cancel` (Set of Number) List of job IDs to trigger the webhook on cancel - `on_failure` (Set of Number) List of job IDs to trigger the webhook on failure - `on_success` (Set of Number) List of job IDs to trigger the webhook on success +- `on_warning` (Set of Number) List of job IDs to trigger the webhook on warning - `slack_channel_id` (String) The ID of the Slack channel to receive the notification. It can be found at the bottom of the Slack channel settings - `slack_channel_name` (String) The name of the slack channel - `state` (Number) State of the notification (1 = active (default), 2 = inactive) diff --git a/docs/resources/partial_notification.md b/docs/resources/partial_notification.md index 99ec0092..357de6e6 100644 --- a/docs/resources/partial_notification.md +++ b/docs/resources/partial_notification.md @@ -86,6 +86,7 @@ resource "dbtcloud_partial_notification" "prod_job_slack_notifications" { - `on_cancel` (Set of Number) List of job IDs to trigger the webhook on cancel. Those will be added/removed when config is added/removed. - `on_failure` (Set of Number) List of job IDs to trigger the webhook on failure Those will be added/removed when config is added/removed. - `on_success` (Set of Number) List of job IDs to trigger the webhook on success Those will be added/removed when config is added/removed. +- `on_warning` (Set of Number) List of job IDs to trigger the webhook on warning Those will be added/removed when config is added/removed. - `slack_channel_id` (String) The ID of the Slack channel to receive the notification. It can be found at the bottom of the Slack channel settings [global, used as identifier] - `slack_channel_name` (String) The name of the slack channel [global, used as identifier] - `state` (Number) State of the notification (1 = active (default), 2 = inactive) [global] From 2b119502a2b2087d36564b0200118be52a1d492a Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Wed, 5 Jun 2024 10:13:58 -0600 Subject: [PATCH 5/7] Fix function rename after rebase --- pkg/framework/objects/notification/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/framework/objects/notification/model.go b/pkg/framework/objects/notification/model.go index a45a5766..760b9856 100644 --- a/pkg/framework/objects/notification/model.go +++ b/pkg/framework/objects/notification/model.go @@ -36,7 +36,7 @@ type NotificationDataSourceModel struct { SlackChannelName types.String `tfsdk:"slack_channel_name"` } -func ConvertStateToNotification(model NotificationResourceModel) dbt_cloud.Notification { +func ConvertNotificationModelToData(model NotificationResourceModel) dbt_cloud.Notification { notification := dbt_cloud.Notification{ UserId: int(model.UserID.ValueInt64()), OnCancel: helper.Int64SetToIntSlice(model.OnCancel), From 63ea9afb09623f0eaa70b776f51a064075055233 Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Mon, 10 Jun 2024 13:49:41 -0600 Subject: [PATCH 6/7] Add Acceptance Tests for new `on_warning` field - Updated test for `dbtcloud_notification` resource - Updated test for `dbtcloud_partial_notification` resource --- .../notification/resource_acceptance_test.go | 14 ++++++++++++++ .../resource_acceptance_test.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/framework/objects/notification/resource_acceptance_test.go b/pkg/framework/objects/notification/resource_acceptance_test.go index efe4c521..ddad3aba 100644 --- a/pkg/framework/objects/notification/resource_acceptance_test.go +++ b/pkg/framework/objects/notification/resource_acceptance_test.go @@ -72,6 +72,10 @@ func TestAccDbtCloudNotificationResource(t *testing.T) { "notification_type", "4", ), + resource.TestCheckResourceAttrSet( + "dbtcloud_notification.test_notification_external", + "on_warning.0", + ), resource.TestCheckResourceAttrSet( "dbtcloud_notification.test_notification_external", "on_failure.0", @@ -98,6 +102,14 @@ func TestAccDbtCloudNotificationResource(t *testing.T) { "dbtcloud_notification.test_notification_internal", "on_cancel.0", ), + resource.TestCheckResourceAttrSet( + "dbtcloud_notification.test_notification_internal", + "on_warning.0", + ), + resource.TestCheckResourceAttrSet( + "dbtcloud_notification.test_notification_internal", + "on_warning.1", + ), testAccCheckDbtCloudNotificationExists( "dbtcloud_notification.test_notification_external", @@ -183,6 +195,7 @@ resource "dbtcloud_notification" "test_notification_internal" { resource "dbtcloud_notification" "test_notification_external" { user_id = %s + on_warning = [dbtcloud_job.test_notification_job_1.id] on_failure = [dbtcloud_job.test_notification_job_2.id] notification_type = 4 external_email = "%s" @@ -201,6 +214,7 @@ resource "dbtcloud_notification" "test_notification_internal" { on_success = [dbtcloud_job.test_notification_job_1.id] on_failure = [dbtcloud_job.test_notification_job_2.id] on_cancel = [] + on_warning = [dbtcloud_job.test_notification_job_1.id, dbtcloud_job.test_notification_job_2.id] notification_type = 1 } diff --git a/pkg/framework/objects/partial_notification/resource_acceptance_test.go b/pkg/framework/objects/partial_notification/resource_acceptance_test.go index fcf19f51..e0a19b8c 100644 --- a/pkg/framework/objects/partial_notification/resource_acceptance_test.go +++ b/pkg/framework/objects/partial_notification/resource_acceptance_test.go @@ -71,6 +71,10 @@ func TestAccDbtCloudPartialNotificationResource(t *testing.T) { "notification_type", "4", ), + resource.TestCheckResourceAttrSet( + "dbtcloud_partial_notification.test_notification_external", + "on_warning.0", + ), resource.TestCheckResourceAttrSet( "dbtcloud_partial_notification.test_notification_external", "on_failure.0", @@ -97,6 +101,14 @@ func TestAccDbtCloudPartialNotificationResource(t *testing.T) { "dbtcloud_partial_notification.test_notification_internal", "on_cancel.0", ), + resource.TestCheckResourceAttrSet( + "dbtcloud_partial_notification.test_notification_internal", + "on_warning.0", + ), + resource.TestCheckResourceAttrSet( + "dbtcloud_partial_notification.test_notification_internal", + "on_warning.1", + ), testAccCheckDbtCloudPartialNotificationExists( "dbtcloud_partial_notification.test_notification_external", @@ -178,6 +190,7 @@ resource "dbtcloud_partial_notification" "test_notification_internal" { resource "dbtcloud_partial_notification" "test_notification_external" { user_id = %s + on_warning = [dbtcloud_job.test_notification_job_1.id] on_failure = [dbtcloud_job.test_notification_job_2.id] notification_type = 4 external_email = "%s" @@ -198,6 +211,7 @@ resource "dbtcloud_partial_notification" "test_notification_internal" { on_success = [dbtcloud_job.test_notification_job_1.id] on_failure = [dbtcloud_job.test_notification_job_2.id] on_cancel = [] + on_warning = [dbtcloud_job.test_notification_job_1.id, dbtcloud_job.test_notification_job_2.id] notification_type = 1 } From 0a9340ca12566a69a932d150adb9304afcd7eb36 Mon Sep 17 00:00:00 2001 From: Chase Walden Date: Mon, 10 Jun 2024 13:57:40 -0600 Subject: [PATCH 7/7] Update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 329cf6c0..47f7b1a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.7...HEAD) +### Changes + +- Added new `on_warning` field to `dbtcloud_notification` and `dbtcloud_partial_notification`. + ## [0.3.7](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.6...v0.3.7) ### Changes