Skip to content

Commit

Permalink
cloudflare_notification_policy: add incident_alert type
Browse files Browse the repository at this point in the history
  • Loading branch information
broswen committed Nov 1, 2023
1 parent f9b4798 commit a4aa795
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .changelog/todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_notification_policy: Add support for `incident_alert` type
```
3 changes: 2 additions & 1 deletion docs/resources/notification_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ resource "cloudflare_notification_policy" "example" {
### Required

- `account_id` (String) The account identifier to target for the resource.
- `alert_type` (String) The event type that will trigger the dispatch of a notification. See the developer documentation for descriptions of [available alert types](https://developers.cloudflare.com/fundamentals/notifications/notification-available/). Available values: `advanced_http_alert_error`, `access_custom_certificate_expiration_type`, `advanced_ddos_attack_l4_alert`, `advanced_ddos_attack_l7_alert`, `bgp_hijack_notification`, `billing_usage_alert`, `block_notification_block_removed`, `block_notification_new_block`, `block_notification_review_rejected`, `clickhouse_alert_fw_anomaly`, `clickhouse_alert_fw_ent_anomaly`, `custom_ssl_certificate_event_type`, `dedicated_ssl_certificate_event_type`, `dos_attack_l4`, `dos_attack_l7`, `expiring_service_token_alert`, `failing_logpush_job_disabled_alert`, `fbm_auto_advertisement`, `fbm_dosd_attack`, `fbm_volumetric_attack`, `health_check_status_notification`, `hostname_aop_custom_certificate_expiration_type`, `http_alert_edge_error`, `http_alert_origin_error`, `load_balancing_health_alert`, `load_balancing_pool_enablement_alert`, `real_origin_monitoring`, `scriptmonitor_alert_new_code_change_detections`, `scriptmonitor_alert_new_hosts`, `scriptmonitor_alert_new_malicious_hosts`, `scriptmonitor_alert_new_malicious_scripts`, `scriptmonitor_alert_new_malicious_url`, `scriptmonitor_alert_new_max_length_resource_url`, `scriptmonitor_alert_new_resources`, `secondary_dns_all_primaries_failing`, `secondary_dns_primaries_failing`, `secondary_dns_zone_successfully_updated`, `secondary_dns_zone_validation_warning`, `sentinel_alert`, `stream_live_notifications`, `tunnel_health_event`, `tunnel_update_event`, `universal_ssl_event_type`, `web_analytics_metrics_update`, `weekly_account_overview`, `workers_alert`, `zone_aop_custom_certificate_expiration_type`.
- `alert_type` (String) The event type that will trigger the dispatch of a notification. See the developer documentation for descriptions of [available alert types](https://developers.cloudflare.com/fundamentals/notifications/notification-available/). Available values: `advanced_http_alert_error`, `access_custom_certificate_expiration_type`, `advanced_ddos_attack_l4_alert`, `advanced_ddos_attack_l7_alert`, `bgp_hijack_notification`, `billing_usage_alert`, `block_notification_block_removed`, `block_notification_new_block`, `block_notification_review_rejected`, `clickhouse_alert_fw_anomaly`, `clickhouse_alert_fw_ent_anomaly`, `custom_ssl_certificate_event_type`, `dedicated_ssl_certificate_event_type`, `dos_attack_l4`, `dos_attack_l7`, `expiring_service_token_alert`, `failing_logpush_job_disabled_alert`, `fbm_auto_advertisement`, `fbm_dosd_attack`, `fbm_volumetric_attack`, `health_check_status_notification`, `hostname_aop_custom_certificate_expiration_type`, `http_alert_edge_error`, `http_alert_origin_error`, `incident_alert`, `load_balancing_health_alert`, `load_balancing_pool_enablement_alert`, `pages_event_alert`, `real_origin_monitoring`, `scriptmonitor_alert_new_code_change_detections`, `scriptmonitor_alert_new_hosts`, `scriptmonitor_alert_new_malicious_hosts`, `scriptmonitor_alert_new_malicious_scripts`, `scriptmonitor_alert_new_malicious_url`, `scriptmonitor_alert_new_max_length_resource_url`, `scriptmonitor_alert_new_resources`, `secondary_dns_all_primaries_failing`, `secondary_dns_primaries_failing`, `secondary_dns_zone_successfully_updated`, `secondary_dns_zone_validation_warning`, `sentinel_alert`, `stream_live_notifications`, `tunnel_health_event`, `tunnel_update_event`, `universal_ssl_event_type`, `web_analytics_metrics_update`, `weekly_account_overview`, `workers_alert`, `zone_aop_custom_certificate_expiration_type`.
- `enabled` (Boolean) The status of the notification policy.
- `name` (String) The name of the notification policy.

Expand Down Expand Up @@ -112,6 +112,7 @@ Optional:
- `event_type` (Set of String) Stream event type to alert on.
- `group_by` (Set of String) Alert grouping.
- `health_check_id` (Set of String) Identifier health check. Required when using `filters.0.status`.
- `incident_impact` (Set of String) The incident impact level that will trigger the dispatch of a notification. Available values: `INCIDENT_IMPACT_NONE`, `INCIDENT_IMPACT_MINOR`, `INCIDENT_IMPACT_MAJOR`, `INCIDENT_IMPACT_CRITICAL`.
- `input_id` (Set of String) Stream input id to alert on.
- `limit` (Set of String) A numerical limit. Example: `100`.
- `megabits_per_second` (Set of String) Megabits per second threshold for dos alert.
Expand Down
176 changes: 74 additions & 102 deletions internal/sdkv2provider/schema_cloudflare_notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,71 @@ package sdkv2provider
import (
"fmt"

"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/cloudflare/terraform-provider-cloudflare/internal/consts"
)

var notificationPolicyAlertTypes = []string{
"advanced_http_alert_error",
"access_custom_certificate_expiration_type",
"advanced_ddos_attack_l4_alert",
"advanced_ddos_attack_l7_alert",
"bgp_hijack_notification",
"billing_usage_alert",
"block_notification_block_removed",
"block_notification_new_block",
"block_notification_review_rejected",
"clickhouse_alert_fw_anomaly",
"clickhouse_alert_fw_ent_anomaly",
"custom_ssl_certificate_event_type",
"dedicated_ssl_certificate_event_type",
"dos_attack_l4",
"dos_attack_l7",
"expiring_service_token_alert",
"failing_logpush_job_disabled_alert",
"fbm_auto_advertisement",
"fbm_dosd_attack",
"fbm_volumetric_attack",
"health_check_status_notification",
"hostname_aop_custom_certificate_expiration_type",
"http_alert_edge_error",
"http_alert_origin_error",
"incident_alert",
"load_balancing_health_alert",
"load_balancing_pool_enablement_alert",
"pages_event_alert",
"real_origin_monitoring",
"scriptmonitor_alert_new_code_change_detections",
"scriptmonitor_alert_new_hosts",
"scriptmonitor_alert_new_malicious_hosts",
"scriptmonitor_alert_new_malicious_scripts",
"scriptmonitor_alert_new_malicious_url",
"scriptmonitor_alert_new_max_length_resource_url",
"scriptmonitor_alert_new_resources",
"secondary_dns_all_primaries_failing",
"secondary_dns_primaries_failing",
"secondary_dns_zone_successfully_updated",
"secondary_dns_zone_validation_warning",
"sentinel_alert",
"stream_live_notifications",
"tunnel_health_event",
"tunnel_update_event",
"universal_ssl_event_type",
"web_analytics_metrics_update",
"weekly_account_overview",
"workers_alert",
"zone_aop_custom_certificate_expiration_type",
}

var notificationPolicyIncidentImpactLevels = []string{
"INCIDENT_IMPACT_NONE",
"INCIDENT_IMPACT_MINOR",
"INCIDENT_IMPACT_MAJOR",
"INCIDENT_IMPACT_CRITICAL",
}

func resourceCloudflareNotificationPolicySchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
consts.AccountIDSchemaKey: {
Expand All @@ -31,107 +91,10 @@ func resourceCloudflareNotificationPolicySchema() map[string]*schema.Schema {
Description: "The status of the notification policy.",
},
"alert_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"advanced_http_alert_error",
"access_custom_certificate_expiration_type",
"advanced_ddos_attack_l4_alert",
"advanced_ddos_attack_l7_alert",
"bgp_hijack_notification",
"billing_usage_alert",
"block_notification_block_removed",
"block_notification_new_block",
"block_notification_review_rejected",
"clickhouse_alert_fw_anomaly",
"clickhouse_alert_fw_ent_anomaly",
"custom_ssl_certificate_event_type",
"dedicated_ssl_certificate_event_type",
"dos_attack_l4",
"dos_attack_l7",
"expiring_service_token_alert",
"failing_logpush_job_disabled_alert",
"fbm_auto_advertisement",
"fbm_dosd_attack",
"fbm_volumetric_attack",
"health_check_status_notification",
"hostname_aop_custom_certificate_expiration_type",
"http_alert_edge_error",
"http_alert_origin_error",
"load_balancing_health_alert",
"load_balancing_pool_enablement_alert",
"pages_event_alert",
"real_origin_monitoring",
"scriptmonitor_alert_new_code_change_detections",
"scriptmonitor_alert_new_hosts",
"scriptmonitor_alert_new_malicious_hosts",
"scriptmonitor_alert_new_malicious_scripts",
"scriptmonitor_alert_new_malicious_url",
"scriptmonitor_alert_new_max_length_resource_url",
"scriptmonitor_alert_new_resources",
"secondary_dns_all_primaries_failing",
"secondary_dns_primaries_failing",
"secondary_dns_zone_successfully_updated",
"secondary_dns_zone_validation_warning",
"sentinel_alert",
"stream_live_notifications",
"tunnel_health_event",
"tunnel_update_event",
"universal_ssl_event_type",
"web_analytics_metrics_update",
"weekly_account_overview",
"workers_alert",
"zone_aop_custom_certificate_expiration_type",
}, false),
Description: fmt.Sprintf("The event type that will trigger the dispatch of a notification. See the developer documentation for descriptions of [available alert types](https://developers.cloudflare.com/fundamentals/notifications/notification-available/). %s", renderAvailableDocumentationValuesStringSlice([]string{
"advanced_http_alert_error",
"access_custom_certificate_expiration_type",
"advanced_ddos_attack_l4_alert",
"advanced_ddos_attack_l7_alert",
"bgp_hijack_notification",
"billing_usage_alert",
"block_notification_block_removed",
"block_notification_new_block",
"block_notification_review_rejected",
"clickhouse_alert_fw_anomaly",
"clickhouse_alert_fw_ent_anomaly",
"custom_ssl_certificate_event_type",
"dedicated_ssl_certificate_event_type",
"dos_attack_l4",
"dos_attack_l7",
"expiring_service_token_alert",
"failing_logpush_job_disabled_alert",
"fbm_auto_advertisement",
"fbm_dosd_attack",
"fbm_volumetric_attack",
"health_check_status_notification",
"hostname_aop_custom_certificate_expiration_type",
"http_alert_edge_error",
"http_alert_origin_error",
"load_balancing_health_alert",
"load_balancing_pool_enablement_alert",
"real_origin_monitoring",
"scriptmonitor_alert_new_code_change_detections",
"scriptmonitor_alert_new_hosts",
"scriptmonitor_alert_new_malicious_hosts",
"scriptmonitor_alert_new_malicious_scripts",
"scriptmonitor_alert_new_malicious_url",
"scriptmonitor_alert_new_max_length_resource_url",
"scriptmonitor_alert_new_resources",
"secondary_dns_all_primaries_failing",
"secondary_dns_primaries_failing",
"secondary_dns_zone_successfully_updated",
"secondary_dns_zone_validation_warning",
"sentinel_alert",
"stream_live_notifications",
"tunnel_health_event",
"tunnel_update_event",
"universal_ssl_event_type",
"web_analytics_metrics_update",
"weekly_account_overview",
"workers_alert",
"zone_aop_custom_certificate_expiration_type",
})),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(notificationPolicyAlertTypes, false),
Description: fmt.Sprintf("The event type that will trigger the dispatch of a notification. See the developer documentation for descriptions of [available alert types](https://developers.cloudflare.com/fundamentals/notifications/notification-available/). %s", renderAvailableDocumentationValuesStringSlice(notificationPolicyAlertTypes)),
},
"filters": notificationPolicyFilterSchema(),
"created": {
Expand Down Expand Up @@ -395,6 +358,15 @@ func notificationPolicyFilterSchema() *schema.Schema {
Optional: true,
Description: "Megabits per second threshold for dos alert.",
},
"incident_impact": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
ValidateFunc: validation.StringInSlice(notificationPolicyIncidentImpactLevels, false),
Description: fmt.Sprintf("The incident impact level that will trigger the dispatch of a notification. %s", renderAvailableDocumentationValuesStringSlice(notificationPolicyIncidentImpactLevels)),
},
},
},
}
Expand Down

0 comments on commit a4aa795

Please sign in to comment.