generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
healthcheck.tf
56 lines (50 loc) · 2.72 KB
/
healthcheck.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
locals {
healthchecks = module.this.enabled && var.healthchecks != null ? {
for healthcheck in flatten(var.healthchecks) :
format("%s-%s-%s",
lookup(healthcheck, "name", module.this.id),
healthcheck.type,
healthcheck.address
) => healthcheck
} : {}
}
resource "time_sleep" "wait_for_records_creation" {
count = module.this.enabled ? 1 : 0
create_duration = "60s"
depends_on = [
cloudflare_record.default
]
}
resource "cloudflare_healthcheck" "default" {
for_each = local.healthchecks
zone_id = local.zone_id
name = lookup(each.value, "name", null) == null ? each.key : each.value.name
description = lookup(each.value, "description", null) == null ? "Managed by Terraform" : each.value.description
address = each.value.address
suspended = lookup(each.value, "suspended", null) == null ? false : each.value.suspended
check_regions = lookup(each.value, "check_regions", null)
type = each.value.type
port = lookup(each.value, "suspended", null) == null ? 80 : each.value.port
timeout = lookup(each.value, "timeout", null) == null ? 5 : each.value.timeout
retries = lookup(each.value, "retries", null) == null ? 3 : each.value.retries
interval = lookup(each.value, "interval", null) == null ? 60 : each.value.interval
consecutive_fails = lookup(each.value, "consecutive_fails", null) == null ? 1 : each.value.consecutive_fails
consecutive_successes = lookup(each.value, "consecutive_successes", null) == null ? 1 : each.value.consecutive_successes
method = lookup(each.value, "method", null) == null ? (each.value.type == "TCP" ? "connection_established" : "GET") : each.value.method
path = lookup(each.value, "path", null) == null ? (each.value.type == "TCP" ? null : "/") : each.value.path
expected_body = lookup(each.value, "expected_body", null)
expected_codes = lookup(each.value, "expected_codes", null) == null ? (each.value.type == "TCP" ? null : ["200"]) : each.value.expected_codes
follow_redirects = lookup(each.value, "follow_redirects", null) == null ? (each.value.type == "TCP" ? null : false) : each.value.follow_redirects
allow_insecure = lookup(each.value, "allow_insecure", null) == null ? (each.value.type == "HTTPS" ? false : null) : each.value.allow_insecure
dynamic "header" {
for_each = lookup(each.value, "header", null) == null ? [] : [lookup(each.value, "header", {})]
content {
header = header.value.header
values = header.value.values
}
}
depends_on = [
cloudflare_record.default,
time_sleep.wait_for_records_creation
]
}