Skip to content

Commit

Permalink
Automatically set route53 records when autobalancer is created
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbat00 committed Nov 21, 2021
1 parent 4e6490d commit f5ffc79
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
32 changes: 32 additions & 0 deletions k8s/route53/module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "hosted_zone_name" {
type = string
}

variable "record_name" {
type = string
default = ""
}

data "aws_route53_zone" "current" {
name = var.hosted_zone_name
}

data "aws_lb" "public" {

tags = {
"service.k8s.aws/stack" = "default/mr-service"
}
}

resource "aws_route53_record" "www" {
name = var.record_name == "" ? var.hosted_zone_name : var.record_name
type = "A"
zone_id = data.aws_route53_zone.current.id
allow_overwrite = true

alias {
evaluate_target_health = true
name = data.aws_lb.public.dns_name
zone_id = data.aws_lb.public.zone_id
}
}
19 changes: 19 additions & 0 deletions module.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ variable "region_account" {
default = 602401143452
}

variable "hosted_zone_name" {
type = string
default = ""
}

variable "record_name" {
type = string
default = ""
}

provider "aws" {
profile = "default"
region = var.region
Expand Down Expand Up @@ -128,6 +138,15 @@ module "service" {
depends_on = [module.matchmaker, module.web_client]
}

module "route53" {
source = "./k8s/route53"
depends_on = [module.service]
count = min(length(var.hosted_zone_name), 1)

hosted_zone_name = var.hosted_zone_name
record_name = var.record_name
}

# Comment this out if running for the first time (i.e. when `helm_agones` is not installed).
module "agones" {
source = "./k8s/agones"
Expand Down

0 comments on commit f5ffc79

Please sign in to comment.