1
1
# Create a new load balancer
2
2
3
3
locals {
4
- enable_custom_domain = " ${ var . dns_zone == " " ? false : true } "
4
+ enable_custom_domain = var. dns_zone == " " ? false : true
5
5
custom_endpoint = " ${ coalesce (var. hostname , " vault" )} .${ var . dns_zone } "
6
- vault_url_protocol = " ${ local . enable_custom_domain ? " https" : " http" } "
7
- vault_url_hostname = " ${ local . enable_custom_domain ? local . custom_endpoint : aws_alb . vault . dns_name } "
6
+ vault_url_protocol = local. enable_custom_domain ? " https" : " http"
7
+ vault_url_hostname = local. enable_custom_domain ? local. custom_endpoint : aws_alb. vault . dns_name
8
8
vault_url = " ${ local . vault_url_protocol } ://${ local . vault_url_hostname } "
9
9
}
10
10
11
11
resource "aws_alb" "vault" {
12
12
name_prefix = " vault-"
13
- security_groups = [" ${ aws_security_group . lb-vault-sg . id } " ]
13
+ security_groups = [aws_security_group . lb-vault-sg . id ]
14
14
internal = false
15
- subnets = [ " ${ var . subnets } " ]
15
+ subnets = var. subnets
16
16
17
- tags {
18
- Environment = " ${ var . env } "
19
- VPC = " ${ local . vpc_name } "
17
+ tags = {
18
+ Environment = var.env
19
+ VPC = local.vpc_name
20
20
}
21
21
22
22
access_logs {
23
- bucket = " ${ var . alb_log_bucket } "
23
+ bucket = var. alb_log_bucket
24
24
prefix = " logs/elb/${ local . vpc_name } /vault"
25
25
}
26
26
}
27
27
28
28
# DNS Alias for the LB
29
29
resource "aws_route53_record" "vault" {
30
- count = " ${ local . enable_custom_domain ? 1 : 0 } "
31
- zone_id = " ${ data . aws_route53_zone . zone . zone_id } "
32
- name = " ${ coalesce (var. hostname , " vault" )} .${ data . aws_route53_zone . zone . name } "
30
+ count = local. enable_custom_domain ? 1 : 0
31
+ zone_id = data. aws_route53_zone . zone [ 0 ] . zone_id
32
+ name = " ${ coalesce (var. hostname , " vault" )} .${ data . aws_route53_zone . zone [ 0 ] . name } "
33
33
type = " A"
34
34
35
35
alias {
36
- name = " ${ aws_alb . vault . dns_name } "
37
- zone_id = " ${ aws_alb . vault . zone_id } "
36
+ name = aws_alb. vault . dns_name
37
+ zone_id = aws_alb. vault . zone_id
38
38
evaluate_target_health = false
39
39
}
40
40
}
@@ -43,8 +43,8 @@ resource "aws_route53_record" "vault" {
43
43
resource "aws_alb_target_group" "vault_ui" {
44
44
port = 8200
45
45
protocol = " HTTP"
46
- deregistration_delay = " ${ var . lb_deregistration_delay } "
47
- vpc_id = " ${ data . aws_vpc . vpc . id } "
46
+ deregistration_delay = var. lb_deregistration_delay
47
+ vpc_id = data. aws_vpc . vpc . id
48
48
49
49
health_check {
50
50
path = " /v1/sys/health?standbyok=true"
@@ -56,35 +56,36 @@ resource "aws_alb_target_group" "vault_ui" {
56
56
enabled = true
57
57
}
58
58
59
- tags {
60
- Environment = " ${ var . env } "
61
- VPC = " ${ local . vpc_name } "
59
+ tags = {
60
+ Environment = var.env
61
+ VPC = local.vpc_name
62
62
}
63
63
}
64
64
65
65
# Create a new alb listener
66
66
resource "aws_alb_listener" "vault_https" {
67
- count = " ${ local . enable_custom_domain ? 1 : 0 } "
68
- load_balancer_arn = " ${ aws_alb . vault . arn } "
67
+ count = local. enable_custom_domain ? 1 : 0
68
+ load_balancer_arn = aws_alb. vault . arn
69
69
port = " 443"
70
70
protocol = " HTTPS"
71
71
ssl_policy = " ELBSecurityPolicy-2015-05"
72
- certificate_arn = " ${ data . aws_acm_certificate . cert . arn } " # edit needed
72
+ certificate_arn = data. aws_acm_certificate . cert [ 0 ] . arn # edit needed
73
73
74
74
default_action {
75
- target_group_arn = " ${ aws_alb_target_group . vault_ui . arn } "
75
+ target_group_arn = aws_alb_target_group. vault_ui . arn
76
76
type = " forward"
77
77
}
78
78
}
79
79
80
80
resource "aws_alb_listener" "vault_http" {
81
- count = " ${ local . enable_custom_domain ? 0 : 1 } "
82
- load_balancer_arn = " ${ aws_alb . vault . arn } "
81
+ count = local. enable_custom_domain ? 0 : 1
82
+ load_balancer_arn = aws_alb. vault . arn
83
83
port = " 80"
84
84
protocol = " HTTP"
85
85
86
86
default_action {
87
- target_group_arn = " ${ aws_alb_target_group . vault_ui . arn } "
87
+ target_group_arn = aws_alb_target_group. vault_ui . arn
88
88
type = " forward"
89
89
}
90
90
}
91
+
0 commit comments