From 5306e92d4a3b4e694fca34fe1cc45faf2e8496fe Mon Sep 17 00:00:00 2001 From: Darin Nee Date: Tue, 13 Feb 2024 16:37:34 -0800 Subject: [PATCH] feat(fastly_alert): align descriptions with API docs, add to interface test --- docs/resources/alert.md | 24 ++++++++++++------------ fastly/resource_fastly_alert.go | 22 +++++++++++----------- templates/resources/alert.md.tmpl | 2 +- tests/interface/main.tf | 12 ++++++++++++ 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/docs/resources/alert.md b/docs/resources/alert.md index ad9afaca9..216c48354 100644 --- a/docs/resources/alert.md +++ b/docs/resources/alert.md @@ -34,7 +34,7 @@ resource "fastly_alert" "example" { ## Import -Fastly Alerts can be imported using their Definition ID, e.g. +Fastly Alerts can be imported using their ID, e.g. ```sh $ terraform import fastly_alert.example xxxxxxxxxxxxxxxxxxxx @@ -45,17 +45,17 @@ $ terraform import fastly_alert.example xxxxxxxxxxxxxxxxxxxx ### Required -- `evaluation_strategy` (Block List, Min: 1, Max: 1) Evaluation strategy for the Alert. (see [below for nested schema](#nestedblock--evaluation_strategy)) -- `metric` (String) The name of the metric to monitor for Alert evaluation. For detailed information on metrics available for monitoring, see [Fastly Alerts API Documentation](https://developer.fastly.com/reference/api/observability/alerts/definition/). -- `name` (String) Summary text of the Alert. -- `service_id` (String) ID of the Fastly Service that the Alert monitors. -- `source` (String) The metric source. One of: `stats`, `origins`, `domains`. +- `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) Text body included in Alert notifications. -- `dimensions` (Block List, Max: 1) Dimension filters applied to the metric. (see [below for nested schema](#nestedblock--dimensions)) -- `integration_ids` (Set of String) Set of IDs of integrations that Alert notifications will be sent to. +- `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 @@ -67,7 +67,7 @@ $ terraform import fastly_alert.example xxxxxxxxxxxxxxxxxxxx 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 trigger. +- `threshold` (Number) Threshold used to alert. - `type` (String) Type of strategy to use to evaluate. One of: `above_threshold`, `below_threshold`. @@ -76,5 +76,5 @@ Required: Optional: -- `domains` (Set of String) Names of a subset of domains defined on the service that the Alert monitors. -- `origins` (Set of String) Addresses of a subset of backends defined on the service that the Alert monitors. +- `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. diff --git a/fastly/resource_fastly_alert.go b/fastly/resource_fastly_alert.go index c09634f81..c7137a7e3 100644 --- a/fastly/resource_fastly_alert.go +++ b/fastly/resource_fastly_alert.go @@ -23,26 +23,26 @@ func resourceFastlyAlert() *schema.Resource { "description": { Type: schema.TypeString, Optional: true, - Description: "Text body included in Alert notifications.", + Description: "Additional text that is included in the alert notification.", }, "dimensions": { Type: schema.TypeList, Optional: true, MaxItems: 1, - Description: "Dimension filters applied to the metric.", + Description: "More filters depending on the source type.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "domains": { Type: schema.TypeSet, Optional: true, - Description: "Names of a subset of domains defined on the service that the Alert monitors.", + Description: "Names of a subset of domains that the alert monitors.", Elem: &schema.Schema{Type: schema.TypeString}, }, "origins": { Type: schema.TypeSet, Optional: true, - Description: "Addresses of a subset of backends defined on the service that the Alert monitors.", + Description: "Addresses of a subset of backends that the alert monitors.", Elem: &schema.Schema{Type: schema.TypeString}, }, }, @@ -52,7 +52,7 @@ func resourceFastlyAlert() *schema.Resource { "evaluation_strategy": { Type: schema.TypeList, Required: true, - Description: "Evaluation strategy for the Alert.", + Description: "Criteria on how to alert.", MinItems: 1, MaxItems: 1, Elem: &schema.Resource{ @@ -65,7 +65,7 @@ func resourceFastlyAlert() *schema.Resource { "threshold": { Type: schema.TypeFloat, Required: true, - Description: "Threshold used to trigger.", + Description: "Threshold used to alert.", }, "type": { Type: schema.TypeString, @@ -79,34 +79,34 @@ func resourceFastlyAlert() *schema.Resource { "integration_ids": { Type: schema.TypeSet, Optional: true, - Description: "Set of IDs of integrations that Alert notifications will be sent to.", + Description: "List of integrations used to notify when alert fires.", Elem: &schema.Schema{Type: schema.TypeString}, }, "metric": { Type: schema.TypeString, Required: true, - Description: "The name of the metric to monitor for Alert evaluation. For detailed information on metrics available for monitoring, see [Fastly Alerts API Documentation](https://developer.fastly.com/reference/api/observability/alerts/definition/).", + Description: "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": { Type: schema.TypeString, Required: true, - Description: "Summary text of the Alert.", + Description: "The name of the alert.", }, "service_id": { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "ID of the Fastly Service that the Alert monitors.", + Description: "The service which the alert monitors.", }, "source": { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "The metric source. One of: `stats`, `origins`, `domains`.", + Description: "The source where the metric comes from. One of: `domains`, `origins`, `stats`.", }, }, } diff --git a/templates/resources/alert.md.tmpl b/templates/resources/alert.md.tmpl index 6acabf166..2bc42b113 100644 --- a/templates/resources/alert.md.tmpl +++ b/templates/resources/alert.md.tmpl @@ -16,7 +16,7 @@ Provides a Fastly Alert. Alerts send notifications to custom integrations (e.g., ## Import -Fastly Alerts can be imported using their Definition ID, e.g. +Fastly Alerts can be imported using their ID, e.g. {{ codefile "sh" "examples/resources/components/alert_import_cmd.txt" }} diff --git a/tests/interface/main.tf b/tests/interface/main.tf index 9df6e6f7d..2e5d49c3c 100644 --- a/tests/interface/main.tf +++ b/tests/interface/main.tf @@ -217,3 +217,15 @@ resource "fastly_service_vcl" "interface-test-project" { response_object = "test_response_object_waf" } } + +resource "fastly_alert" "interface-test-alert" { + name = "test_alert" + service_id = fastly_service_vcl.interface-test-project.id + source = "stats" + metric = "status_5xx" + + evaluation_strategy { + type = "above_threshold" + period = "5m" + threshold = 10 + }