-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from squaredup/work/ss/alerting-channels
Support for Adding Alert Channels and Alerts
- Loading branch information
Showing
18 changed files
with
2,034 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "squaredup_alerting_channel_types Data Source - terraform-provider-squaredup" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# squaredup_alerting_channel_types (Data Source) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "squaredup_alerting_channel_types" "example" { | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `display_name` (String) Filter Alerting Channel Types by Display Name | ||
|
||
### Read-Only | ||
|
||
- `alerting_channel_types` (Attributes List) Alerting Channel Types are used to configure alert notifications (see [below for nested schema](#nestedatt--alerting_channel_types)) | ||
|
||
<a id="nestedatt--alerting_channel_types"></a> | ||
### Nested Schema for `alerting_channel_types` | ||
|
||
Read-Only: | ||
|
||
- `channel_id` (String) | ||
- `description` (String) | ||
- `display_name` (String) | ||
- `image_preview_supported` (Boolean) | ||
- `protocol` (String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "squaredup_alerting_channel Resource - terraform-provider-squaredup" | ||
subcategory: "" | ||
description: |- | ||
SquaredUp Alerting Channel | ||
--- | ||
|
||
# squaredup_alerting_channel (Resource) | ||
|
||
SquaredUp Alerting Channel | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "squaredup_alerting_channel_types" "example" { | ||
display_name = "Slack API" | ||
} | ||
resource "squaredup_alerting_channel" "slack_api_alert" { | ||
display_name = "Slack Alert - Team DevOps" | ||
channel_type_id = data.squaredup_alerting_channel_types.example.alerting_channel_types[0].channel_id | ||
description = "Channel for DevOps team" | ||
config = jsonencode({ | ||
channel = "devops" | ||
token = "some-token" | ||
}) | ||
enabled = true | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `channel_type_id` (String) The ID of the alerting channel type | ||
- `config` (String, Sensitive) The configuration of the alerting channel | ||
- `display_name` (String) The display name of the alerting channel | ||
- `enabled` (Boolean) Whether the alerting channel is enabled | ||
|
||
### Optional | ||
|
||
- `description` (String) Description for the alerting channel | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the alerting channel | ||
- `last_updated` (String) The last updated time of the alerting channel | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# Alerting Channel can be imported by specifying channel id. | ||
terraform import squaredup_alerting_channel.example channel-123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "squaredup_workspace_alert Resource - terraform-provider-squaredup" | ||
subcategory: "" | ||
description: |- | ||
SquaredUp Workspace Alert | ||
--- | ||
|
||
# squaredup_workspace_alert (Resource) | ||
|
||
SquaredUp Workspace Alert | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "squaredup_datasources" "sample_data" { | ||
data_source_name = "Sample Data" | ||
} | ||
resource "squaredup_datasource" "sample_data_source" { | ||
display_name = "Sample Data" | ||
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name | ||
} | ||
resource "squaredup_workspace" "application_workspace" { | ||
display_name = "Application Team" | ||
description = "Workspace with Dashboards for Application Team" | ||
datasources_links = [squaredup_datasource.sample_data_source.id] | ||
} | ||
data "squaredup_data_streams" "sample_data_logs_dataStreams" { | ||
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id | ||
} | ||
locals { | ||
logs_data_stream = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "logs")] | ||
perf_lambda_errors_data_stream = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "perf-lambda-errors")] | ||
} | ||
resource "squaredup_dashboard" "sample_dashboard" { | ||
dashboard_template = <<EOT | ||
{ | ||
"_type": "layout/grid", | ||
"contents": [ | ||
{ | ||
"w": 2, | ||
"h": 3, | ||
"x": 0, | ||
"y": 0, | ||
"i": "1", | ||
"moved": false, | ||
"static": false, | ||
"config": { | ||
"baseTile": "data-stream-base-tile", | ||
"visualisation": { | ||
"config": { | ||
"data-stream-table": { | ||
"resizedColumns": { | ||
"columnWidths": { | ||
"logs.timestamp": 146 | ||
} | ||
} | ||
} | ||
}, | ||
"type": "data-stream-table" | ||
}, | ||
"title": "CloudWatch Logs", | ||
"description": "", | ||
"_type": "tile/data-stream", | ||
"dataStream": { | ||
"id": "{{cloud_watch_logs_id}}", | ||
"pluginConfigId": "{{sample_data_source_id}}" | ||
}, | ||
"scope": { | ||
"query": "g.V().order().by('__name').hasNot('__canonicalType').has(\"__configId\", \"{{sample_data_source_id}}\").or(__.has(\"sourceType\", within(\"sample-function\",\"sample-server\",\"sample-database\"))).limit(500)", | ||
"bindings": {}, | ||
"queryDetail": {} | ||
} | ||
} | ||
}, | ||
{ | ||
"w": 2, | ||
"h": 3, | ||
"x": 2, | ||
"y": 0, | ||
"i": "a8255dce-5f74-4ff5-b3d3-138f6a0ff130", | ||
"moved": false, | ||
"static": false, | ||
"config": { | ||
"title": "Lambda Errors", | ||
"description": "", | ||
"_type": "tile/data-stream", | ||
"dataStream": { | ||
"id": "{{perf_lambda_errors_id}}", | ||
"pluginConfigId": "{{sample_data_source_id}}", | ||
"group": { | ||
"by": [ | ||
"data.lambdaErrors.label", | ||
"uniqueValues" | ||
], | ||
"aggregate": [ | ||
{ | ||
"names": [ | ||
"data.lambdaErrors.value" | ||
], | ||
"type": "sum" | ||
} | ||
] | ||
}, | ||
"filter": { | ||
"filters": [], | ||
"multiOperation": "and" | ||
} | ||
}, | ||
"visualisation": { | ||
"type": "data-stream-donut-chart" | ||
}, | ||
"scope": { | ||
"query": "g.V().order().by('__name').hasNot('__canonicalType').has(\"__configId\", \"{{sample_data_source_id}}\").or(__.has(\"sourceType\", \"sample-function\")).limit(500)", | ||
"bindings": {}, | ||
"queryDetail": {} | ||
}, | ||
"monitor": { | ||
"_type": "simple", | ||
"tileRollsUp": true, | ||
"monitorType": "threshold", | ||
"frequency": 15, | ||
"aggregation": "top", | ||
"column": "data.lambdaErrors.value_sum", | ||
"condition": { | ||
"columns": [ | ||
"data.lambdaErrors.value_sum" | ||
], | ||
"logic": { | ||
"if": [ | ||
{ | ||
">": [ | ||
{ | ||
"var": "top" | ||
}, | ||
0 | ||
] | ||
}, | ||
"error" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"columns": 4, | ||
"version": 1 | ||
} | ||
EOT | ||
template_bindings = jsonencode({ | ||
sample_data_source_id = squaredup_datasource.sample_data_source.id | ||
cloud_watch_logs_id = local.logs_data_stream.id | ||
perf_lambda_errors_id = local.perf_lambda_errors_data_stream.id | ||
}) | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
display_name = "Sample Dashboard" | ||
timeframe = "last12hours" | ||
} | ||
# Extract ids of tiles | ||
locals { | ||
dashboard_content = jsondecode(squaredup_dashboard.sample_dashboard.dashboard_content) | ||
lambda_errors_tile = [for content in local.dashboard_content.contents : content.i if content.config.title == "Lambda Errors"] | ||
lambda_errors_tile_id = length(local.lambda_errors_tile) > 0 ? local.lambda_errors_tile[0] : null | ||
} | ||
data "squaredup_alerting_channel_types" "example" { | ||
display_name = "Slack API" | ||
} | ||
resource "squaredup_alerting_channel" "slack_api_alert" { | ||
display_name = "Slack Alert - Team DevOps" | ||
channel_type_id = data.squaredup_alerting_channel_types.example.alerting_channel_types[0].channel_id | ||
config = jsonencode({ | ||
channel = "devops" | ||
token = "some-token" | ||
}) | ||
enabled = true | ||
} | ||
// NOTE: Only one workspace alert resource can be created per workspace | ||
resource "squaredup_workspace_alert" "example" { | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
alerting_rules = [ | ||
{ | ||
channel = squaredup_alerting_channel.slack_api_alert.id | ||
notify_on = "workspace_state" | ||
// "workspace_state" does not support "preview_image" | ||
}, | ||
{ | ||
channel = squaredup_alerting_channel.slack_api_alert.id | ||
preview_image = true | ||
notify_on = "all_monitors" | ||
}, | ||
{ | ||
channel = squaredup_alerting_channel.slack_api_alert.id | ||
preview_image = false | ||
notify_on = "selected_monitors" | ||
selected_monitors = [ | ||
{ | ||
dashboard_id = squaredup_dashboard.sample_dashboard.id | ||
tiles_id = [local.lambda_errors_tile_id] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `alerting_rules` (Attributes List) The alerting rules to create (see [below for nested schema](#nestedatt--alerting_rules)) | ||
- `workspace_id` (String) The ID of the workspace to create the alert in | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the workspace | ||
|
||
<a id="nestedatt--alerting_rules"></a> | ||
### Nested Schema for `alerting_rules` | ||
|
||
Required: | ||
|
||
- `channel` (String) The ID of the channel to send the alert to | ||
- `notify_on` (String) Condition to trigger the alert. Must be one of: 'workspace_state', 'all_monitors', or 'selected_monitors' | ||
|
||
Optional: | ||
|
||
- `preview_image` (Boolean) Whether to include a preview image in the alert | ||
- `selected_monitors` (Attributes List) The monitors to trigger the alert on. Required if notify_on is 'selected_monitors' (see [below for nested schema](#nestedatt--alerting_rules--selected_monitors)) | ||
|
||
<a id="nestedatt--alerting_rules--selected_monitors"></a> | ||
### Nested Schema for `alerting_rules.selected_monitors` | ||
|
||
Required: | ||
|
||
- `dashboard_id` (String) The ID of the dashboard where the monitor is configured | ||
- `tiles_id` (List of String) The ID of the tiles to trigger the alert on | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# Workspace Alerts can be imported by specifying workspace id. | ||
terraform import squaredup_workspace_alert.example space-123 | ||
``` |
2 changes: 2 additions & 0 deletions
2
examples/data-sources/squaredup_alerting_channel_types/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
data "squaredup_alerting_channel_types" "example" { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Alerting Channel can be imported by specifying channel id. | ||
terraform import squaredup_alerting_channel.example channel-123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
data "squaredup_alerting_channel_types" "example" { | ||
display_name = "Slack API" | ||
} | ||
|
||
resource "squaredup_alerting_channel" "slack_api_alert" { | ||
display_name = "Slack Alert - Team DevOps" | ||
channel_type_id = data.squaredup_alerting_channel_types.example.alerting_channel_types[0].channel_id | ||
description = "Channel for DevOps team" | ||
config = jsonencode({ | ||
channel = "devops" | ||
token = "some-token" | ||
}) | ||
enabled = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Workspace Alerts can be imported by specifying workspace id. | ||
terraform import squaredup_workspace_alert.example space-123 |
Oops, something went wrong.