forked from telia-oss/terraform-aws-loadbalancer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
53 lines (47 loc) · 1.38 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
# ------------------------------------------------------------------------------
# Resources
# ------------------------------------------------------------------------------
locals {
name_prefix = "${var.name_prefix}-${var.type == "network" ? "nlb" : "alb"}"
}
resource "aws_lb" "main" {
name = local.name_prefix
load_balancer_type = var.type
internal = var.internal
subnets = var.subnet_ids
security_groups = aws_security_group.main.*.id
idle_timeout = var.idle_timeout
access_logs {
bucket = lookup(var.access_logs, "bucket", "")
prefix = lookup(var.access_logs, "prefix", null)
enabled = lookup(var.access_logs, "enabled", false)
}
tags = merge(
var.tags,
{
"Name" = local.name_prefix
},
)
}
resource "aws_security_group" "main" {
count = var.type == "network" ? 0 : 1
name = "${local.name_prefix}-sg"
description = "Terraformed security group."
vpc_id = var.vpc_id
tags = merge(
var.tags,
{
"Name" = "${local.name_prefix}-sg"
},
)
}
resource "aws_security_group_rule" "egress" {
count = var.type == "network" ? 0 : 1
security_group_id = aws_security_group.main[0].id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}