Skip to content

Commit 154d66c

Browse files
alexottnfx
andauthored
Add support for notifications in databricks_pipeline resource (#2218)
* Add support for notifications in `databricks_pipeline` resource Also added support for `min_items` terraform annotation to simplify specificaiton of non-empty lists. * fix typo Co-authored-by: Serge Smertin <[email protected]> --------- Co-authored-by: Serge Smertin <[email protected]>
1 parent 57d4553 commit 154d66c

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

common/reflect_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ func typeToSchema(v reflect.Value, t reflect.Type, path []string) map[string]*sc
216216
continue
217217
}
218218
scm[fieldName].MaxItems = maxItems
219+
case "min_items":
220+
minItems, err := strconv.Atoi(tfValue)
221+
if err != nil {
222+
continue
223+
}
224+
scm[fieldName].MinItems = minItems
219225
}
220226
}
221227
}

common/reflect_resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type testPtr struct {
5151
}
5252

5353
type testStruct struct {
54-
Integer int `json:"integer,omitempty" tf:"default:10,max_items:invalid"`
54+
Integer int `json:"integer,omitempty" tf:"default:10,min_items:invalid,max_items:invalid"`
5555
Float float64 `json:"float,omitempty"`
5656
Bool bool `json:"bool,omitempty"`
5757
NonOptional string `json:"non_optional"`
@@ -201,7 +201,7 @@ type Dummy struct {
201201
Enabled bool `json:"enabled" tf:"conflicts:workers"`
202202
Workers int `json:"workers,omitempty" tf:"suppress_diff"`
203203
Description string `json:"description,omitempty"`
204-
Addresses []Address `json:"addresses,omitempty" tf:"max_items:10"`
204+
Addresses []Address `json:"addresses,omitempty" tf:"min_items:1,max_items:10"`
205205
Unique []Address `json:"unique,omitempty" tf:"slice_set"`
206206
Things []string `json:"things,omitempty" tf:"slice_set"`
207207
Tags map[string]string `json:"tags,omitempty" tf:"max_items:5"`

docs/resources/pipeline.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ resource "databricks_pipeline" "this" {
5353
}
5454
5555
continuous = false
56+
57+
notification {
58+
email_recipients = ["[email protected]", "[email protected]"]
59+
alerts = [
60+
"on-update-failure",
61+
"on-update-fatal-failure",
62+
"on-update-success",
63+
"on-flow-failure"
64+
]
65+
}
5666
}
5767
```
5868

@@ -72,6 +82,18 @@ The following arguments are supported:
7282
* `edition` - optional name of the [product edition](https://docs.databricks.com/data-engineering/delta-live-tables/delta-live-tables-concepts.html#editions). Supported values are: `core`, `pro`, `advanced` (default).
7383
* `channel` - optional name of the release channel for Spark version used by DLT pipeline. Supported values are: `current` (default) and `preview`.
7484

85+
### notification block
86+
87+
DLT allows to specify one or more notification blocks to get notifications about pipeline's execution. This block consists of following attributes:
88+
89+
* `email_recipients` (Required) non-empty list of emails to notify.
90+
* `alerts` (Required) non-empty list of alert types. Right now following alert types are supported, consult documentation for actual list
91+
* `on-update-success` - a pipeline update completes successfully.
92+
* `on-update-failure` - a pipeline update fails with a retryable error.
93+
* `on-update-fatal-failure` - a pipeline update fails with a non-retryable (fatal) error.
94+
* `on-flow-failure` - a single data flow fails.
95+
96+
7597
## Import
7698

7799
The resource job can be imported using the id of the pipeline

pipelines/resource_pipeline.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ type filters struct {
8080
Exclude []string `json:"exclude,omitempty"`
8181
}
8282

83+
type Notification struct {
84+
EmailRecipients []string `json:"email_recipients" tf:"min_items:1"`
85+
Alerts []string `json:"alerts" tf:"min_items:1"`
86+
}
87+
8388
type PipelineSpec struct {
8489
ID string `json:"id,omitempty" tf:"computed"`
8590
Name string `json:"name,omitempty"`
@@ -96,6 +101,7 @@ type PipelineSpec struct {
96101
Photon bool `json:"photon,omitempty"`
97102
Edition string `json:"edition,omitempty" tf:"suppress_diff,default:ADVANCED"`
98103
Channel string `json:"channel,omitempty" tf:"suppress_diff,default:CURRENT"`
104+
Notifications []Notification `json:"notifications,omitempty" tf:"alias:notification"`
99105
}
100106

101107
type createPipelineResponse struct {

0 commit comments

Comments
 (0)