-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
57 lines (45 loc) · 1.8 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
57
data "ncloud_vpc" "vpc" {
count = var.vpc_name != null ? 1 : 0
filter {
name = "name"
values = [var.vpc_name]
}
}
data "ncloud_subnet" "subnets" {
for_each = toset(coalesce(var.subnet_names, []))
vpc_no = one(data.ncloud_vpc.vpc.*.id)
filter {
name = "name"
values = [each.key]
}
}
resource "ncloud_lb" "lb" {
name = var.name
description = var.description
type = var.type
network_type = var.network_type
subnet_no_list = coalesce(var.subnet_no_list, coalesce(var.subnet_ids, values(data.ncloud_subnet.subnets).*.id))
throughput_type = var.throughput_type
idle_timeout = var.idle_timeout
}
data "ncloud_lb_target_group" "target_groups" {
for_each = toset([for listener in var.listeners : listener.target_group_name if can(listener.target_group_name)])
filter {
name = "name"
values = [each.key]
}
}
resource "ncloud_lb_listener" "lb_listeners" {
count = length(var.listeners)
load_balancer_no = ncloud_lb.lb.id
protocol = var.listeners[count.index].protocol
port = var.listeners[count.index].port
target_group_no = (
try(var.listeners[count.index].target_group_no,
try(var.listeners[count.index].target_group_id,
data.ncloud_lb_target_group.target_groups[var.listeners[count.index].target_group_name].id
)))
tls_min_version_type = (var.listeners[count.index].protocol == "TLS") || (var.listeners[count.index].protocol == "HTTPS") ? var.listeners[count.index].tls_min_version_type : null
ssl_certificate_no = (var.listeners[count.index].protocol == "TLS") || (var.listeners[count.index].protocol == "HTTPS") ? var.listeners[count.index].ssl_certificate_no : null
use_http2 = (var.listeners[count.index].protocol == "HTTPS") ? var.listeners[count.index].use_http2 : null
}