Last active
December 20, 2017 00:54
-
-
Save tom-butler/42f97deacb8911bc4008a37d1c36c6a1 to your computer and use it in GitHub Desktop.
blue / green route53 switch.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "ap-southeast-2" | |
} | |
terraform { | |
required_version = ">= 0.11.0" | |
backend "s3" { | |
encrypt = true | |
} | |
} | |
variable "release_stack" { | |
default = "blue" | |
} | |
variable "environment" { | |
default = "dev" | |
} | |
variable "zone" { | |
default = "app.com." | |
} | |
data "aws_route53_zone" "selected" { | |
name = "${var.zone}" | |
} | |
locals { | |
other_stack = "${var.release_stack == "blue" ? "green" : "blue"}" | |
} | |
resource "aws_route53_record" "release" { | |
zone_id = "${data.aws_route53_zone.selected.zone_id}" | |
name = "" | |
type = "A" | |
alias { | |
name = "${var.release_stack}.${var.zone}" | |
zone_id = "${data.aws_route53_zone.selected.zone_id}" | |
evaluate_target_health = false | |
} | |
} | |
resource "aws_route53_record" "staging" { | |
zone_id = "${data.aws_route53_zone.selected.zone_id}" | |
name = "staging" | |
type = "A" | |
alias { | |
name = "${local.other_stack}.${var.zone}" | |
zone_id = "${data.aws_route53_zone.selected.zone_id}" | |
evaluate_target_health = false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment