forked from dominik-dabrowski/terraform-aws-ecs-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_discovery.tf
115 lines (88 loc) · 3.64 KB
/
service_discovery.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Only one of the following resources will be built at any given time.
# This resource is built only when we're using service discovery with
# NEITHER health_check_config nor health_check_custom_config.
resource "aws_service_discovery_service" "default" {
count = length(var.service_discovery) > 0 && length(var.service_discovery_health_check_config) == 0 && length(var.service_discovery_health_check_custom_config) == 0 ? 1 : 0
name = local.namespace_name
dns_config {
namespace_id = local.namespace_id
dns_records {
ttl = local.dns_ttl
type = local.dns_type
}
routing_policy = local.dns_routing_policy
}
}
# This resource is built only when we're using service discovery with
# health_check_custom_config but NOT health_check_config.
resource "aws_service_discovery_service" "health_check_custom" {
count = length(var.service_discovery) > 0 && length(var.service_discovery_health_check_config) == 0 && length(var.service_discovery_health_check_custom_config) > 0 ? 1 : 0
name = local.namespace_name
dns_config {
namespace_id = local.namespace_id
dns_records {
ttl = local.dns_ttl
type = local.dns_type
}
routing_policy = local.dns_routing_policy
}
dynamic "health_check_custom_config" {
for_each = [var.service_discovery_health_check_custom_config]
content {
failure_threshold = lookup(health_check_custom_config.value, "failure_threshold", null)
}
}
}
# This resource is built only when we're using service discovery with
# health_check_config but NOT health_check_custom_config.
resource "aws_service_discovery_service" "health_check" {
count = length(var.service_discovery) > 0 && length(var.service_discovery_health_check_config) > 0 && length(var.service_discovery_health_check_custom_config) == 0 ? 1 : 0
name = local.namespace_name
dns_config {
namespace_id = local.namespace_id
dns_records {
ttl = local.dns_ttl
type = local.dns_type
}
routing_policy = local.dns_routing_policy
}
dynamic "health_check_config" {
for_each = [var.service_discovery_health_check_config]
content {
failure_threshold = lookup(health_check_config.value, "failure_threshold", null)
resource_path = lookup(health_check_config.value, "resource_path", null)
type = lookup(health_check_config.value, "type", null)
}
}
}
# This resource is built only when we're using service discovery with
# BOTH health_check_config AND health_check_custom_config.
#
# NOTE: Amazon does not currently support this combination, and an
# error message will result when this is attempted.
resource "aws_service_discovery_service" "health_check_and_health_check_custom" {
count = length(var.service_discovery) > 0 && length(var.service_discovery_health_check_config) > 0 && length(var.service_discovery_health_check_custom_config) > 0 ? 1 : 0
name = local.namespace_name
dns_config {
namespace_id = local.namespace_id
dns_records {
ttl = local.dns_ttl
type = local.dns_type
}
routing_policy = local.dns_routing_policy
}
dynamic "health_check_config" {
for_each = [var.service_discovery_health_check_config]
content {
failure_threshold = lookup(health_check_config.value, "failure_threshold", null)
resource_path = lookup(health_check_config.value, "resource_path", null)
type = lookup(health_check_config.value, "type", null)
}
}
dynamic "health_check_custom_config" {
for_each = [var.service_discovery_health_check_custom_config]
content {
failure_threshold = lookup(health_check_custom_config.value, "failure_threshold", null)
}
}
}