Skip to content

Commit

Permalink
Add support for notifications in databricks_pipeline resource (data…
Browse files Browse the repository at this point in the history
…bricks#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 <259697+nfx@users.noreply.github.com>

---------

Co-authored-by: Serge Smertin <259697+nfx@users.noreply.github.com>
  • Loading branch information
2 people authored and cbochman committed Apr 24, 2023
1 parent 82c7c00 commit 62ac9d0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions common/reflect_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ func typeToSchema(v reflect.Value, t reflect.Type, path []string) map[string]*sc
continue
}
scm[fieldName].MaxItems = maxItems
case "min_items":
minItems, err := strconv.Atoi(tfValue)
if err != nil {
continue
}
scm[fieldName].MinItems = minItems
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/reflect_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type testPtr struct {
}

type testStruct struct {
Integer int `json:"integer,omitempty" tf:"default:10,max_items:invalid"`
Integer int `json:"integer,omitempty" tf:"default:10,min_items:invalid,max_items:invalid"`
Float float64 `json:"float,omitempty"`
Bool bool `json:"bool,omitempty"`
NonOptional string `json:"non_optional"`
Expand Down Expand Up @@ -201,7 +201,7 @@ type Dummy struct {
Enabled bool `json:"enabled" tf:"conflicts:workers"`
Workers int `json:"workers,omitempty" tf:"suppress_diff"`
Description string `json:"description,omitempty"`
Addresses []Address `json:"addresses,omitempty" tf:"max_items:10"`
Addresses []Address `json:"addresses,omitempty" tf:"min_items:1,max_items:10"`
Unique []Address `json:"unique,omitempty" tf:"slice_set"`
Things []string `json:"things,omitempty" tf:"slice_set"`
Tags map[string]string `json:"tags,omitempty" tf:"max_items:5"`
Expand Down
22 changes: 22 additions & 0 deletions docs/resources/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ resource "databricks_pipeline" "this" {
}
continuous = false
notification {
email_recipients = ["user@domain.com", "user1@domain.com"]
alerts = [
"on-update-failure",
"on-update-fatal-failure",
"on-update-success",
"on-flow-failure"
]
}
}
```

Expand All @@ -72,6 +82,18 @@ The following arguments are supported:
* `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).
* `channel` - optional name of the release channel for Spark version used by DLT pipeline. Supported values are: `current` (default) and `preview`.

### notification block

DLT allows to specify one or more notification blocks to get notifications about pipeline's execution. This block consists of following attributes:

* `email_recipients` (Required) non-empty list of emails to notify.
* `alerts` (Required) non-empty list of alert types. Right now following alert types are supported, consult documentation for actual list
* `on-update-success` - a pipeline update completes successfully.
* `on-update-failure` - a pipeline update fails with a retryable error.
* `on-update-fatal-failure` - a pipeline update fails with a non-retryable (fatal) error.
* `on-flow-failure` - a single data flow fails.


## Import

The resource job can be imported using the id of the pipeline
Expand Down
6 changes: 6 additions & 0 deletions pipelines/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ type filters struct {
Exclude []string `json:"exclude,omitempty"`
}

type Notification struct {
EmailRecipients []string `json:"email_recipients" tf:"min_items:1"`
Alerts []string `json:"alerts" tf:"min_items:1"`
}

type PipelineSpec struct {
ID string `json:"id,omitempty" tf:"computed"`
Name string `json:"name,omitempty"`
Expand All @@ -96,6 +101,7 @@ type PipelineSpec struct {
Photon bool `json:"photon,omitempty"`
Edition string `json:"edition,omitempty" tf:"suppress_diff,default:ADVANCED"`
Channel string `json:"channel,omitempty" tf:"suppress_diff,default:CURRENT"`
Notifications []Notification `json:"notifications,omitempty" tf:"alias:notification"`
}

type createPipelineResponse struct {
Expand Down

0 comments on commit 62ac9d0

Please sign in to comment.