Skip to content

Commit 1b0a57a

Browse files
authored
feat: Example for Alert Rules (#198)
* CXF-112290: Add example for alert rules * CXF-112290: Add newline * CXF-112290: Rename folder * CXF-112290: Add versions * CXF-112290: Add outputs * CXF-112290: Improve outputs * CXF-112290: Improve variables.tf * CXF-112290: Integrate module * CXF-112290: Add extra line * CXF-112290: Update outputs.tf * CXF-112290: Add datasources * CXF-112290: Minor changes * CXF-112290: Remove extra line * CXF-112290: Address PR comments * CXF-112290: Address PR comments * CXF-112290: Update README.md
1 parent d444b02 commit 1b0a57a

6 files changed

Lines changed: 304 additions & 5 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Fabric Stream Alert Rules
2+
3+
This example shows how to leverage the [Fabric Stream Module](https://registry.terraform.io/modules/equinix/fabric/equinix/latest/submodules/streaming-observability)
4+
to create a Fabric Stream and Splunk Fabric Stream Subscription.
5+
It also shows how to leverage the [Fabric Port Connection Module](https://registry.terraform.io/modules/equinix/fabric/equinix/latest/submodules/port-connection)
6+
to create a port to port connection. It creates a Fabric Stream Attachment on top of the created connection.
7+
8+
It leverages the Equinix Terraform Provider, Fabric Stream Module, Fabric Port Connection Module, equinix_fabric_stream_attachment resource
9+
and equinix_fabric_stream_alert_rule resource to setup the stream alert rule based on the parameters you have provided to this example.
10+
11+
Additionally, the patterns found in this example can be followed in your own custom Terraform configurations for more complex solutions.
12+
13+
See example usage below for details on how to use this example.
14+
15+
<!-- BEGIN_TF_DOCS -->
16+
<!-- END_TF_DOCS -->
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
provider "equinix" {
2+
client_id = var.equinix_client_id
3+
client_secret = var.equinix_client_secret
4+
}
5+
6+
module "stream_splunk_subscription" {
7+
source = "../../modules/streaming-observability"
8+
9+
stream_name = var.stream_name
10+
stream_description = var.stream_description
11+
12+
splunk_enabled = var.splunk_enabled
13+
splunk_access_token = var.splunk_access_token
14+
splunk_name = var.splunk_name
15+
splunk_description = var.splunk_description
16+
splunk_uri = var.splunk_uri
17+
splunk_event_exceptions = var.splunk_event_exceptions
18+
splunk_event_selections = var.splunk_event_exceptions
19+
splunk_metric_exceptions = var.splunk_metric_exceptions
20+
splunk_metric_selections = var.splunk_metric_selections
21+
splunk_source = var.splunk_source
22+
splunk_event_index = var.splunk_event_index
23+
splunk_metric_index = var.splunk_metric_index
24+
}
25+
26+
module "create_port_2_port_connection" {
27+
source = "../../modules/port-connection"
28+
29+
connection_name = var.connection_name
30+
connection_type = var.connection_type
31+
notifications_type = var.notifications_type
32+
notifications_emails = var.notifications_emails
33+
bandwidth = var.bandwidth
34+
purchase_order_number = var.purchase_order_number
35+
36+
# A-side
37+
aside_port_name = var.aside_port_name
38+
aside_vlan_tag = var.aside_vlan_tag
39+
40+
# Z-side
41+
zside_ap_type = var.zside_ap_type
42+
zside_port_name = var.zside_port_name
43+
zside_vlan_tag = var.zside_vlan_tag
44+
zside_location = var.zside_location
45+
}
46+
47+
resource "equinix_fabric_stream_attachment" "attachment" {
48+
depends_on = [
49+
module.stream_splunk_subscription,
50+
module.create_port_2_port_connection
51+
]
52+
53+
asset_id = module.create_port_2_port_connection.primary_connection_id
54+
asset = var.asset_type
55+
stream_id = module.stream_splunk_subscription.first_stream.id
56+
}
57+
58+
resource "equinix_fabric_stream_alert_rule" "alert_rule" {
59+
depends_on = [
60+
equinix_fabric_stream_attachment.attachment
61+
]
62+
type = "METRIC_ALERT"
63+
stream_id = module.stream_splunk_subscription.first_stream.id
64+
name = var.alert_rule_name
65+
description = var.alert_rule_description
66+
operand = var.operand
67+
window_size = var.window_size
68+
warning_threshold = var.warning_threshold
69+
critical_threshold = var.critical_threshold
70+
metric_name = var.metric_name
71+
resource_selector = {
72+
"include" = [
73+
"*/${equinix_fabric_stream_attachment.attachment.asset}/${module.create_port_2_port_connection.primary_connection_id}"
74+
]
75+
}
76+
}
77+
78+
data "equinix_fabric_stream_alert_rule" "alert_rule" {
79+
depends_on = [
80+
module.stream_splunk_subscription,
81+
equinix_fabric_stream_alert_rule.alert_rule
82+
]
83+
stream_id = module.stream_splunk_subscription.first_stream.id
84+
alert_rule_id = equinix_fabric_stream_alert_rule.alert_rule.id
85+
}
86+
87+
data "equinix_fabric_stream_alert_rules" "alert_rules" {
88+
depends_on = [
89+
module.stream_splunk_subscription,
90+
equinix_fabric_stream_alert_rule.alert_rule
91+
]
92+
stream_id = module.stream_splunk_subscription.first_stream.id
93+
pagination = {
94+
limit = var.limit
95+
offset = var.offset
96+
}
97+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
output "stream_id" {
2+
value = module.stream_splunk_subscription.first_stream.id
3+
}
4+
output "connection_id" {
5+
value = module.create_port_2_port_connection.primary_connection_id
6+
}
7+
output "stream_alert_rule_id" {
8+
value = equinix_fabric_stream_alert_rule.alert_rule.uuid
9+
}
10+
output "stream_alert_rule_state" {
11+
value = equinix_fabric_stream_alert_rule.alert_rule.state
12+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
variable "equinix_client_id" {
2+
description = "Equinix client ID (consumer key), obtained after registering app in the developer platform"
3+
type = string
4+
sensitive = true
5+
}
6+
variable "equinix_client_secret" {
7+
description = "Equinix client secret ID (consumer secret), obtained after registering app in the developer platform"
8+
type = string
9+
sensitive = true
10+
}
11+
variable "stream_name" {
12+
description = "Stream name"
13+
type = string
14+
}
15+
variable "stream_description" {
16+
description = "Stream description"
17+
type = string
18+
}
19+
variable "splunk_enabled" {
20+
description = "Boolean value indicating enablement of the Splunk Subscription"
21+
type = bool
22+
default = true
23+
}
24+
variable "splunk_access_token" {
25+
description = "Credential for Splunk Sink Subscription"
26+
type = string
27+
default = ""
28+
sensitive = true
29+
}
30+
variable "splunk_name" {
31+
description = "Name of the Splunk Equinix Subscription Resource"
32+
type = string
33+
default = ""
34+
}
35+
variable "splunk_description" {
36+
description = "Description of the Splunk Equinix Subscription Resource"
37+
type = string
38+
default = ""
39+
}
40+
41+
variable "splunk_uri" {
42+
description = "URI for the streaming messages to be sent to for Splunk"
43+
type = string
44+
default = ""
45+
}
46+
variable "splunk_event_exceptions" {
47+
description = "Events to exclude from the possibilities available to the stream for the Subscription"
48+
type = list(string)
49+
default = []
50+
}
51+
variable "splunk_event_selections" {
52+
description = "Events to include from the possibilities available to the stream for the Subscription"
53+
type = list(string)
54+
default = []
55+
}
56+
variable "splunk_metric_exceptions" {
57+
description = "Metrics to exclude from the possibilities available to the stream for the Subscription"
58+
type = list(string)
59+
default = []
60+
}
61+
variable "splunk_metric_selections" {
62+
description = "Metrics to include from the possibilities available to the stream for the Subscription"
63+
type = list(string)
64+
default = []
65+
}
66+
variable "splunk_source" {
67+
description = "Name of the created Splunk Source for the destination of the streaming messages"
68+
type = string
69+
default = ""
70+
}
71+
variable "splunk_event_index" {
72+
description = "Event index for the Splunk Sink Source"
73+
type = string
74+
default = ""
75+
}
76+
variable "splunk_metric_index" {
77+
description = "Metric index for Splunk Sink Source"
78+
type = string
79+
default = ""
80+
}
81+
variable "connection_name" {
82+
description = "Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores"
83+
type = string
84+
}
85+
variable "connection_type" {
86+
description = "Defines the connection type like VG_VC, EVPL_VC, EPL_VC, EC_VC, IP_VC, ACCESS_EPL_VC"
87+
type = string
88+
}
89+
variable "notifications_type" {
90+
description = "Notification Type - ALL is the only type currently supported"
91+
type = string
92+
default = "ALL"
93+
}
94+
variable "notifications_emails" {
95+
description = "Array of contact emails"
96+
type = list(string)
97+
}
98+
variable "bandwidth" {
99+
description = "Connection bandwidth in Mbps"
100+
type = number
101+
}
102+
variable "purchase_order_number" {
103+
description = "Purchase order number"
104+
type = string
105+
default = ""
106+
}
107+
variable "aside_port_name" {
108+
description = "Equinix A-Side Port Name"
109+
type = string
110+
}
111+
variable "aside_vlan_tag" {
112+
description = "Vlan tag for DOT1Q or QINQ connections"
113+
type = string
114+
}
115+
variable "zside_ap_type" {
116+
description = "Access point type - COLO, VD, VG, SP, IGW, SUBNET, GW"
117+
type = string
118+
}
119+
variable "zside_port_name" {
120+
description = "Equinix Port Name"
121+
type = string
122+
}
123+
variable "zside_vlan_tag" {
124+
description = "Vlan tag for DOT1Q or QINQ connections"
125+
type = string
126+
}
127+
variable "zside_location" {
128+
description = "Access point metro code"
129+
type = string
130+
}
131+
variable "asset_type" {
132+
description = "Asset type"
133+
type = string
134+
}
135+
variable "alert_rule_name" {
136+
description = "Alert rule name"
137+
type = string
138+
}
139+
variable "alert_rule_description" {
140+
description = "Alert rule description"
141+
type = string
142+
}
143+
variable "operand" {
144+
description = "Operand for the alert rule"
145+
type = string
146+
}
147+
variable "window_size" {
148+
description = "Alert rule window size"
149+
type = string
150+
}
151+
variable "warning_threshold" {
152+
description = "Warning threshold for the alert rule"
153+
type = string
154+
}
155+
variable "critical_threshold" {
156+
description = "Critical threshold for the alert rule"
157+
type = string
158+
}
159+
variable "metric_name" {
160+
description = "Metric Name for the alert rule"
161+
type = string
162+
}
163+
variable "limit" {
164+
description = "Limit for pagination of alert rules"
165+
type = number
166+
}
167+
variable "offset" {
168+
description = "Offset for pagination of alert rules"
169+
type = number
170+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = ">= 1.5.4"
3+
required_providers {
4+
equinix = {
5+
source = "equinix/equinix"
6+
version = ">= 3.10.0"
7+
}
8+
}
9+
}

modules/streaming-observability/main.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ resource "equinix_fabric_stream_subscription" "splunk" {
3030
description = var.splunk_description
3131
stream_id = equinix_fabric_stream.stream1.id
3232
enabled = var.splunk_enabled
33-
filters = var.splunk_filters != [] ? var.splunk_filters : null
3433
event_selector = {
3534
include = var.splunk_event_selections != [] ? var.splunk_event_selections : null
3635
except = var.splunk_event_exceptions != [] ? var.splunk_event_exceptions : null
@@ -62,7 +61,6 @@ resource "equinix_fabric_stream_subscription" "slack" {
6261
description = var.slack_description
6362
stream_id = equinix_fabric_stream.stream1.id
6463
enabled = var.slack_enabled
65-
filters = var.slack_filters != [] ? var.slack_filters : null
6664
event_selector = {
6765
include = var.slack_event_selections != [] ? var.slack_event_selections : null
6866
except = var.slack_event_exceptions != [] ? var.slack_event_exceptions : null
@@ -85,7 +83,6 @@ resource "equinix_fabric_stream_subscription" "pagerduty" {
8583
description = var.pagerduty_description
8684
stream_id = equinix_fabric_stream.stream1.id
8785
enabled = var.pagerduty_enabled
88-
filters = var.pagerduty_filters != [] ? var.pagerduty_filters : null
8986
event_selector = {
9087
include = var.pagerduty_event_selections != [] ? var.pagerduty_event_selections : null
9188
except = var.pagerduty_event_exceptions != [] ? var.pagerduty_event_exceptions : null
@@ -116,7 +113,6 @@ resource "equinix_fabric_stream_subscription" "datadog" {
116113
description = var.datadog_description
117114
stream_id = local.second_stream ? equinix_fabric_stream.stream2[0].id : equinix_fabric_stream.stream1.id
118115
enabled = var.datadog_enabled
119-
filters = var.datadog_filters != [] ? var.datadog_filters : null
120116
event_selector = {
121117
include = var.datadog_event_selections != [] ? var.datadog_event_selections : null
122118
except = var.datadog_event_exceptions != [] ? var.datadog_event_exceptions : null
@@ -149,7 +145,6 @@ resource "equinix_fabric_stream_subscription" "msteams" {
149145
description = var.msteams_description
150146
stream_id = local.second_stream ? equinix_fabric_stream.stream2[0].id : equinix_fabric_stream.stream1.id
151147
enabled = var.msteams_enabled
152-
filters = var.msteams_filters != [] ? var.msteams_filters : null
153148
event_selector = {
154149
include = var.msteams_event_selections != [] ? var.msteams_event_selections : null
155150
except = var.msteams_event_exceptions != [] ? var.msteams_event_exceptions : null

0 commit comments

Comments
 (0)