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

feat(fastly_alert): implement resource and documentation #810

Merged
merged 4 commits into from
Feb 14, 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
80 changes: 80 additions & 0 deletions docs/resources/alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
layout: "fastly"
page_title: "Fastly: alert"
sidebar_current: "docs-fastly-resource-alert"
description: |-
Provides a Fastly Alert. Alerts send notifications to custom integrations (e.g., Slack channels, PagerDuty, Microsoft Teams and New Relic) when an observed metric either exceeds or falls below a threshold.
---

# fastly_alert

Provides a Fastly Alert. Alerts send notifications to custom integrations (e.g., Slack channels, PagerDuty, Microsoft Teams and New Relic) when an observed metric either exceeds or falls below a threshold.

## Example Usage

```terraform
resource "fastly_service_vcl" "example" {
name = "my_vcl_service"
# ...
}

resource "fastly_alert" "example" {
name = "my_vcl_service errors"
service_id = fastly_service_vcl.example.id
source = "stats"
metric = "status_5xx"

evaluation_strategy {
type = "above_threshold"
period = "5m"
threshold = 10
}
}
```

## Import

Fastly Alerts can be imported using their ID, e.g.

```sh
$ terraform import fastly_alert.example xxxxxxxxxxxxxxxxxxxx
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `evaluation_strategy` (Block List, Min: 1, Max: 1) Criteria on how to alert. (see [below for nested schema](#nestedblock--evaluation_strategy))
- `metric` (String) The metric name to alert on for a specific source: [domains](https://developer.fastly.com/reference/api/metrics-stats/domain-inspector/historical), [origins](https://developer.fastly.com/reference/api/metrics-stats/origin-inspector/historical), or [stats](https://developer.fastly.com/reference/api/metrics-stats/historical-stats).
- `name` (String) The name of the alert.
- `service_id` (String) The service which the alert monitors.
- `source` (String) The source where the metric comes from. One of: `domains`, `origins`, `stats`.

### Optional

- `description` (String) Additional text that is included in the alert notification.
- `dimensions` (Block List, Max: 1) More filters depending on the source type. (see [below for nested schema](#nestedblock--dimensions))
- `integration_ids` (Set of String) List of integrations used to notify when alert fires.

### Read-Only

- `id` (String) The ID of this resource.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darin-nee There is also object = "definition" that is returned in the response, also read-only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's in the API response and elided in the Terraform schema.


<a id="nestedblock--evaluation_strategy"></a>
### Nested Schema for `evaluation_strategy`

Required:

- `period` (String) The length of time to evaluate whether the conditions have been met. The data is polled every minute. One of: `5m`, `15m`, `30m`.
- `threshold` (Number) Threshold used to alert.
- `type` (String) Type of strategy to use to evaluate. One of: `above_threshold`, `below_threshold`.


<a id="nestedblock--dimensions"></a>
### Nested Schema for `dimensions`

Optional:

- `domains` (Set of String) Names of a subset of domains that the alert monitors.
- `origins` (Set of String) Addresses of a subset of backends that the alert monitors.
17 changes: 17 additions & 0 deletions examples/resources/alert_basic_usage.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "fastly_service_vcl" "example" {
name = "my_vcl_service"
# ...
}

resource "fastly_alert" "example" {
name = "my_vcl_service errors"
service_id = fastly_service_vcl.example.id
source = "stats"
metric = "status_5xx"

evaluation_strategy {
type = "above_threshold"
period = "5m"
threshold = 10
}
}
1 change: 1 addition & 0 deletions examples/resources/components/alert_import_cmd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ terraform import fastly_alert.example xxxxxxxxxxxxxxxxxxxx
1 change: 1 addition & 0 deletions fastly/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func Provider() *schema.Provider {
"fastly_waf_rules": dataSourceFastlyWAFRules(),
},
ResourcesMap: map[string]*schema.Resource{
"fastly_alert": resourceFastlyAlert(),
"fastly_configstore": resourceFastlyConfigStore(),
"fastly_configstore_entries": resourceFastlyConfigStoreEntries(),
"fastly_kvstore": resourceFastlyKVStore(),
Expand Down
Loading
Loading