-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
56 lines (46 loc) · 1.71 KB
/
main.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
data "ncloud_vpc" "vpc" {
count = var.vpc_name != null ? 1 : 0
filter {
name = "name"
values = [var.vpc_name]
}
}
resource "ncloud_lb_target_group" "target_group" {
name = var.name
description = var.description
vpc_no = coalesce(var.vpc_no, one(data.ncloud_vpc.vpc.*.id))
protocol = var.protocol
port = var.port
algorithm_type = var.algorithm_type
use_sticky_session = var.use_sticky_session
use_proxy_protocol = var.use_proxy_protocol
target_type = var.target_type
health_check {
protocol = var.health_check.protocol
port = var.health_check.port
cycle = var.health_check.cycle
up_threshold = var.health_check.up_threshold
down_threshold = var.health_check.down_threshold
http_method = (var.health_check.protocol == "HTTP" || var.health_check.protocol == "HTTPS") ? var.health_check.http_method : null
url_path = (var.health_check.protocol == "HTTP" || var.health_check.protocol == "HTTPS") ? var.health_check.url_path : null
}
}
data "ncloud_server" "servers" {
for_each = toset(coalesce(var.target_instance_names, []))
filter {
name = "name"
values = [each.key]
}
}
locals {
tg_attachment = (
try(length(var.target_no_list) > 0 , false) ||
try(length(var.target_instance_ids) > 0 , false) ||
try(length(var.target_instance_names) > 0 ,false)
)
}
resource "ncloud_lb_target_group_attachment" "target_group_attachment" {
count = local.tg_attachment ? 1 : 0
target_group_no = ncloud_lb_target_group.target_group.id
target_no_list = coalesce(var.target_no_list, coalesce(var.target_instance_ids, values(data.ncloud_server.servers).*.id))
}