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 support for notifications in databricks_pipeline resource #2218

Merged
merged 2 commits into from
Apr 14, 2023
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
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 @@ -81,6 +81,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 @@ -97,6 +102,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