Skip to content

Commit 202afef

Browse files
authored
feat: adding a simple uptime check sub-module (#67)
1 parent 8fe4b14 commit 202afef

File tree

14 files changed

+1893
-0
lines changed

14 files changed

+1893
-0
lines changed

build/int.cloudbuild.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ steps:
3939
- id: destroy
4040
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
4141
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
42+
- id: create-uptime
43+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
44+
args: ['/bin/bash', '-c', 'cft test run TestUptimeCheckModule --stage init --verbose']
45+
- id: apply-uptime
46+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
47+
args: ['/bin/bash', '-c', 'cft test run TestUptimeCheckModule --stage apply --verbose']
48+
- id: verify-uptime
49+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
50+
args: ['/bin/bash', '-c', 'cft test run TestUptimeCheckModule --stage verify --verbose']
51+
- id: destroy-uptime
52+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
53+
args: ['/bin/bash', '-c', 'cft test run TestUptimeCheckModule --stage destroy --verbose']
4254
tags:
4355
- 'ci'
4456
- 'integration'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# HTTPS Uptime URL Check Example
2+
3+
This example illustrates how to use the `simple-uptime-check` module for a simple HTTPS Uptime URL check.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| email | Email address to alert if uptime check fails. | `string` | `"example-email@gmail.com"` | no |
11+
| hostname | The base hostname for the uptime check. | `string` | `"example-hostname.com"` | no |
12+
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |
13+
| uptime\_check\_display\_name | The ID of the project in which to provision resources. | `string` | `"example-uptime-check-name"` | no |
14+
15+
## Outputs
16+
17+
| Name | Description |
18+
|------|-------------|
19+
| alert\_policy\_id | The id of the alert policy. |
20+
| notification\_channel\_ids | The ids of the notification channels |
21+
| uptime\_check\_id | The id of the uptime check. |
22+
23+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
24+
25+
To provision this example, run the following from within this directory:
26+
- `terraform init` to get the plugins
27+
- `terraform plan` to see the infrastructure plan
28+
- `terraform apply` to apply the infrastructure build
29+
- `terraform destroy` to destroy the built infrastructure
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "uptime-check" {
18+
source = "./../../modules/simple-uptime-check"
19+
20+
project_id = var.project_id
21+
uptime_check_display_name = var.uptime_check_display_name
22+
protocol = "HTTPS"
23+
monitored_resource = {
24+
monitored_resource_type = "uptime_url"
25+
labels = {
26+
"project_id" = var.project_id
27+
"host" = var.hostname
28+
}
29+
}
30+
31+
notification_channels = [
32+
{
33+
display_name = "Email Notification Channel"
34+
type = "email"
35+
labels = { email_address = var.email }
36+
},
37+
# {
38+
# display_name = "SMS Notification Channel"
39+
# type = "sms"
40+
# labels = { number = var.sms }
41+
# }
42+
]
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
output "uptime_check_id" {
17+
description = "The id of the uptime check."
18+
value = module.uptime-check.uptime_check_id
19+
}
20+
21+
output "alert_policy_id" {
22+
description = "The id of the alert policy."
23+
value = module.uptime-check.alert_policy_id
24+
}
25+
26+
output "notification_channel_ids" {
27+
description = "The ids of the notification channels"
28+
value = module.uptime-check.notification_channel_ids
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The ID of the project in which to provision resources."
19+
type = string
20+
}
21+
22+
variable "uptime_check_display_name" {
23+
description = "The ID of the project in which to provision resources."
24+
type = string
25+
default = "example-uptime-check-name"
26+
}
27+
28+
variable "hostname" {
29+
description = "The base hostname for the uptime check."
30+
type = string
31+
default = "example-hostname.com"
32+
}
33+
34+
variable "email" {
35+
description = "Email address to alert if uptime check fails."
36+
type = string
37+
default = "example-email@gmail.com"
38+
}
39+
40+
# Uncomment if you'd like to add an SMS notification channel
41+
# variable "sms" {
42+
# description = "Phone number (including country code) to alert if uptime check fails."
43+
# type = string
44+
# default = "example-number"
45+
# }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Simple Uptime Check
2+
3+
This module is used to create a single uptime check along with an alert policy and new and/or existing notification channel(s) to notify if the uptime check fails.
4+
5+
This module does not support multiple alert policies or multiple conditions for a single alert policy. For alert policies, conditions does not support `condition_absent`, `condition_monitoring_query_language` or `condition_matched_log` blocks.
6+
7+
## Usage
8+
9+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
10+
## Inputs
11+
12+
| Name | Description | Type | Default | Required |
13+
|------|-------------|------|---------|:--------:|
14+
| accepted\_response\_status\_classes | Check will only pass if the HTTP response status code is in this set of status classes (combined with the set of status values). Possible values: STATUS\_CLASS\_1XX, STATUS\_CLASS\_2XX, STATUS\_CLASS\_3XX, STATUS\_CLASS\_4XX, STATUS\_CLASS\_5XX, STATUS\_CLASS\_ANY | `set(string)` | `[]` | no |
15+
| accepted\_response\_status\_values | Check will only pass if the HTTP response status code is in this set of status values (combined with the set of status classes). | `set(number)` | `[]` | no |
16+
| aggregations | Specifies the alignment of data points in individual time series as well as how to combine the retrieved time series together. | <pre>object({<br> alignment_period = string<br> per_series_aligner = string<br> group_by_fields = list(string)<br> cross_series_reducer = string<br> })</pre> | <pre>{<br> "alignment_period": "1200s",<br> "cross_series_reducer": "REDUCE_COUNT_FALSE",<br> "group_by_fields": [<br> "resource.label.*"<br> ],<br> "per_series_aligner": "ALIGN_NEXT_OLDER"<br>}</pre> | no |
17+
| alert\_policy\_combiner | Determines how to combine multiple conditions. One of: AND, OR, or AND\_WITH\_MATCHING\_RESOURCE. | `string` | `"OR"` | no |
18+
| alert\_policy\_display\_name | Display name for the alert policy. Defaults to "var.uptime\_check\_display\_name Uptime Failure Alert Policy" if left empty. | `string` | `""` | no |
19+
| alert\_policy\_user\_labels | This field is intended to be used for organizing and identifying the AlertPolicy objects. | `map(string)` | `{}` | no |
20+
| auth\_info | Optional username and password to authenticate. | <pre>object({<br> username = string<br> password = string<br> })</pre> | `null` | no |
21+
| auto\_close | Open incidents will close if an alert policy that was active has no data for this long (in seconds, must be at least 30 minutes). For example "18000s". | `string` | `null` | no |
22+
| body | The request body associated with the HTTP POST request. | `string` | `null` | no |
23+
| checker\_type | One of: STATIC\_IP\_CHECKERS, VPC\_CHECKERS | `string` | `"STATIC_IP_CHECKERS"` | no |
24+
| condition\_display\_name | A unique name to identify condition in dashboards, notifications, and incidents. If left empty, defaults to Failure of uptime check\_id | `string` | `""` | no |
25+
| condition\_threshold\_comparison | The comparison to apply between the time series (indicated by filter and aggregation) and the threshold (indicated by threshold\_value). | `string` | `"COMPARISON_GT"` | no |
26+
| condition\_threshold\_duration | The amount of time that a time series must violate the threshold to be considered failing, in seconds. Must be a multiple of 60 seconds. | `string` | `"60s"` | no |
27+
| condition\_threshold\_filter | A filter that identifies which time series should be compared with the threshold. Defaults to uptime check failure filter if left as empty string. | `string` | `""` | no |
28+
| condition\_threshold\_trigger | Defines the percent and number of time series that must fail the predicate for the condition to be triggered | <pre>object({<br> percent = number<br> count = number<br> })</pre> | <pre>{<br> "count": 1,<br> "percent": null<br>}</pre> | no |
29+
| condition\_threshold\_value | A value against which to compare the time series. | `number` | `1` | no |
30+
| content | String or regex content to match. | `string` | `null` | no |
31+
| content\_type | Content type to use for the http(s) check. Can be one of: TYPE\_UNSPECIFIED, URL\_ENCODED | `string` | `null` | no |
32+
| enabled | Whether or not the policy is enabled (defaults to true) | `bool` | `true` | no |
33+
| existing\_notification\_channels | List of existing notification channel IDs to use for alerting if the uptime check fails. | `list(string)` | `[]` | no |
34+
| headers | The list of headers to send as part of the uptime check request. | `map(string)` | `{}` | no |
35+
| json\_path\_matcher | If matcher is MATCHES\_JSON\_PATH or NOT\_MATCHES\_JSON\_PATH, the json matcher and path to use. The json matcher must be either EXACT\_MATCH or REGEX\_MATCH. | <pre>object({<br> json_path = string<br> json_matcher = string<br> })</pre> | `null` | no |
36+
| mask\_headers | Whether to encrypt the header information. | `bool` | `false` | no |
37+
| matcher | Type of content matcher. One of: CONTAINS\_STRING, NOT\_CONTAINS\_STRING, MATCHES\_REGEX, NOT\_MATCHES\_REGEX, MATCHES\_JSON\_PATH, NOT\_MATCHES\_JSON\_PATH | `string` | `"CONTAINS_STRING"` | no |
38+
| monitored\_resource | Monitored resource type and labels. One of: uptime\_url, gce\_instance, gae\_app, aws\_ec2\_instance, aws\_elb\_load\_balancer, k8s\_service, servicedirectory\_service. See https://cloud.google.com/monitoring/api/resources for a list of labels. | <pre>object({<br> monitored_resource_type = string<br> labels = map(string)<br> })</pre> | `null` | no |
39+
| notification\_channel\_strategy | Control over how the notification channels in notification\_channels are notified when this alert fires, on a per-channel basis. | <pre>object({<br> notification_channel_names = list(string)<br> renotify_interval = number<br> })</pre> | `null` | no |
40+
| notification\_channels | List of all the notification channels to create for alerting if the uptime check fails. See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.notificationChannelDescriptors/list for a list of types and labels. | <pre>list(object({<br> display_name = string<br> type = string<br> labels = map(string)<br> }))</pre> | `[]` | no |
41+
| notification\_rate\_limit\_period | Not more than one notification per specified period (in seconds), for example "30s". | `string` | `null` | no |
42+
| path | Path to the page to run the check against. The path to the page to run the check against. Will be combined with the host in monitored\_resource block to construct the entire URL. | `string` | `"/"` | no |
43+
| period | How frequently uptime check is run. Must be one of the following: 60s, 300s, 600s, 900s | `string` | `"60s"` | no |
44+
| port | The port to the page to run the check against. If left null, defaults to 443 for HTTPS and 80 for HTTP. | `number` | `null` | no |
45+
| project\_id | The project ID to host the uptime check in (required). | `string` | n/a | yes |
46+
| protocol | Protocol for uptime check. One of: HTTPS, HTTP, or TCP (required). | `string` | n/a | yes |
47+
| request\_method | HTTP request method to use for the check. One of: METHOD\_UNSPECIFIED, GET, POST | `string` | `"GET"` | no |
48+
| resource\_group | Group resource associated with configuration. Resource types must be one of: RESOURCE\_TYPE\_UNSPECIFIED, INSTANCE, AWS\_ELB\_LOAD\_BALANCER | <pre>object({<br> resource_type = string<br> group_id = string<br> })</pre> | `null` | no |
49+
| selected\_regions | Regions from which to run the uptime check from. Defaults to all regions. | `list(string)` | `[]` | no |
50+
| timeout | The maximum amount of time to wait for the request to complete. | `string` | `"10s"` | no |
51+
| uptime\_check\_display\_name | The display name for the uptime check (required). | `string` | n/a | yes |
52+
| validate\_ssl | If https, whether to validate SSL certificates. | `string` | `true` | no |
53+
54+
## Outputs
55+
56+
| Name | Description |
57+
|------|-------------|
58+
| alert\_policy\_id | The id of the alert policy. |
59+
| notification\_channel\_ids | The ids of the notification channels |
60+
| uptime\_check\_id | The id of the uptime check. |
61+
62+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)