Skip to content

Commit

Permalink
terraform/platforms/aws: add option for creating a Route53 record to …
Browse files Browse the repository at this point in the history
…front the ELB
  • Loading branch information
Quentin-M committed Feb 10, 2018
1 parent 6890e6c commit 2fe9552
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions terraform/platforms/aws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ associate_public_ips = "true"
subnets_ids = ["subnet-f438f793", "subnet-d4bea38c"]
# ID of the VPC where the subnets are defined.
vpc_id = "vpc-19f019"
# Optional Route53 Zone ID under which an 'etcd' record should be created for client connections.
route53_zone_id = ""
# Defines whether the load balancer for etcd will be internet facing or internal.
load_balancer_internal = "false"
# List of the security group IDs to apply to the load balancer (ingress TCP 2379) (if empty, defaults to open to all).
Expand Down Expand Up @@ -88,6 +90,7 @@ module "eco" {
associate_public_ip_address = "true"
subnets_ids = ["subnet-f438f793", "subnet-d4bea38c"]
vpc_id = "vpc-19f019"
route53_zone_id = ""
load_balancer_internal = "false"
load_balancer_security_group_ids = []
metrics_security_group_ids = []
Expand Down
2 changes: 1 addition & 1 deletion terraform/platforms/aws/aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ locals {
snapshot_provider = "s3"
unseen_instance_ttl = "60s"
snapshot_bucket = "${aws_s3_bucket.backups.bucket}"
advertise_address = "${aws_elb.clients.dns_name}"
advertise_address = "${var.route53_zone_id != "" ? aws_route53_record.elb.name : aws_elb.clients.dns_name }"
}
2 changes: 1 addition & 1 deletion terraform/platforms/aws/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
// limitations under the License.

output "etcd_address" {
value = "${var.eco_enable_tls == true ? "https" : "http"}://${aws_elb.clients.dns_name}:2379"
value = "${var.eco_enable_tls == true ? "https" : "http"}://${var.route53_zone_id != "" ? join("", aws_route53_record.elb.*.name) : aws_elb.clients.dns_name}:2379"
}
17 changes: 17 additions & 0 deletions terraform/platforms/aws/route53.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data "aws_route53_zone" "main" {
zone_id = "${var.route53_zone_id}"
}

resource "aws_route53_record" "elb" {
count = "${var.route53_zone_id != "" ? 1 : 0 }"

zone_id = "${data.aws_route53_zone.main.zone_id}"
name = "etcd.${data.aws_route53_zone.main.name}"
type = "A"

alias {
name = "${aws_elb.clients.dns_name}"
zone_id = "${aws_elb.clients.zone_id}"
evaluate_target_health = true
}
}
4 changes: 4 additions & 0 deletions terraform/platforms/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ variable "vpc_id" {
description = "ID of the VPC where the subnets are defined."
}

variable "route53_zone_id" {
description = "Optional Route53 Zone ID under which an 'etcd' record should be created for client connections"
}

variable "load_balancer_internal" {
description = "Defines whether the load balancer for etcd should be internet facing or internal"
}
Expand Down

0 comments on commit 2fe9552

Please sign in to comment.