Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on_warning to dbtcloud_notification and dbtcloud_partial_notification #269

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/partial_notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dbt-labs/terraform-provider-dbtcloud

go 1.21.0
go 1.21

toolchain go1.21.4

Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions pkg/dbt_cloud/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -60,6 +61,7 @@ func (c *Client) CreateNotification(
userId int,
onCancel []int,
onFailure []int,
onWarning []int,
onSuccess []int,
state int,
notificationType int,
Expand All @@ -72,6 +74,7 @@ func (c *Client) CreateNotification(
UserId: userId,
OnCancel: onCancel,
OnFailure: onFailure,
OnWarning: onWarning,
OnSuccess: onSuccess,
State: state,
NotificationType: notificationType,
Expand Down
10 changes: 10 additions & 0 deletions pkg/framework/objects/notification/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pkg/framework/objects/notification/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -39,6 +41,7 @@ func ConvertNotificationModelToData(model NotificationResourceModel) dbt_cloud.N
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()),
Expand Down
18 changes: 17 additions & 1 deletion pkg/framework/objects/notification/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -157,6 +168,7 @@ func (r *notificationResource) Create(
int(data.UserID.ValueInt64()),
intOnCancel,
intOnFailure,
intOnWarning,
intOnSuccess,
int(data.State.ValueInt64()),
int(data.NotificationType.ValueInt64()),
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/framework/objects/notification/resource_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/framework/objects/notification/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions pkg/framework/objects/partial_notification/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading
Loading