forked from dcos-terraform/terraform-aws-elb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
68 lines (61 loc) · 2.35 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
58
59
60
61
62
63
64
65
66
67
68
/**
* [![Build Status](https://jenkins-terraform.mesosphere.com/service/dcos-terraform-jenkins/job/dcos-terraform/job/terraform-aws-elb/job/master/badge/icon)](https://jenkins-terraform.mesosphere.com/service/dcos-terraform-jenkins/job/dcos-terraform/job/terraform-aws-elb/job/master/)
* AWS ELB
* ============
* This module create AWS ELBs for DC/OS
*
* EXAMPLE
* -------
*
*```hcl
* module "dcos-elbs" {
* source = "terraform-dcos/elb/aws"
* version = "~> 0.1.0"
*
* cluster_name = "production"
*
* subnet_ids = ["subnet-12345678"]
* security_groups_external_masters = ["sg-12345678"]
* security_groups_external_public_agents = ["sg-12345678"]
* master_instances = ["i-00123456789e960f8"]
* public_agent_instances = ["i-00123456789e960f8"]
*
* aws_external_masters_acm_cert_arn = "arn:aws:acm:us-east-1:123456789123:certificate/ooc4NeiF-1234-5678-9abc-vei5Eeniipo4"
* }
*```
*/
provider "aws" {}
// Only 32 characters allowed for name. So we have to use substring
locals {
elb_name = "${format(var.elb_name_format,var.cluster_name)}"
default_listeners = [
{
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
},
{
instance_port = 443
instance_protocol = "${var.https_acm_cert_arn == "" ? "tcp" : "https"}"
lb_port = 443
lb_protocol = "${var.https_acm_cert_arn == "" ? "tcp" : "https"}"
ssl_certificate_id = "${var.https_acm_cert_arn}"
},
]
}
resource "aws_elb" "loadbalancer" {
name = "${substr(local.elb_name,0, length(local.elb_name) >= 32 ? 32 : length(local.elb_name) )}"
subnets = ["${var.subnet_ids}"]
security_groups = ["${var.security_groups}"]
internal = "${var.internal}"
listener = ["${coalescelist(var.listener, concat(local.default_listeners,var.additional_listener))}"]
health_check = ["${var.health_check}"]
instances = ["${var.instances}"]
cross_zone_load_balancing = "${var.cross_zone_load_balancing}"
idle_timeout = "${var.idle_timeout}"
connection_draining = "${var.connection_draining}"
wait_for_ready_timeout = "10m"
tags = "${merge(var.tags, map("Name", format(var.elb_name_format,var.cluster_name),
"Cluster", var.cluster_name))}"
}