-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to use terraform 0.13 syntax, add an only A example.
- Loading branch information
Showing
11 changed files
with
134 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
# 1.1 | ||
# 1.2.0 | ||
|
||
This role now requires terraform 0.13 syntax. It has also been updated to internally use a module per zone which will cause records to be recreated. | ||
|
||
BREAKING: | ||
|
||
* Now requires terraform => 0.13 to function. | ||
|
||
# 1.1.0 | ||
|
||
BREAKING | ||
|
||
* `domains` replaces `zone_name` and `zone_records` enabling us to set records across many zones. | ||
|
||
# 1.0 | ||
# 1.0.0 | ||
|
||
Initial Release |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
variable "zone" { | ||
type = string | ||
description = "A zone." | ||
} | ||
|
||
variable "hosts" { | ||
type = set(string) | ||
description = "A set of hosts." | ||
} | ||
|
||
variable "alias_hosted_zone_id" { | ||
description = "The hosted_zone_id to alias" | ||
} | ||
|
||
variable "alias_domain_name" { | ||
description = "The domain_name on the hosted_zone_id to alias" | ||
} | ||
|
||
variable "record_types" { | ||
type = list(string) | ||
description = "The types of records to set. Default is A and AAAA" | ||
} | ||
|
||
locals { | ||
mappings = flatten([ | ||
for record_type in var.record_types : [ | ||
for host in var.hosts : { | ||
type = record_type, | ||
host = host | ||
} | ||
] | ||
]) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
data "aws_route53_zone" "zone" { | ||
name = var.zone | ||
} | ||
|
||
resource "aws_route53_record" "record" { | ||
count = length(local.mappings) | ||
|
||
zone_id = data.aws_route53_zone.zone.id | ||
|
||
name = local.mappings[count.index]["host"] | ||
type = local.mappings[count.index]["type"] | ||
|
||
alias { | ||
name = var.alias_domain_name | ||
zone_id = var.alias_hosted_zone_id | ||
evaluate_target_health = false | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Only IPv4 Example | ||
|
||
This example shows overriding record_types and only setting A records pointing to an S3 bucket. | ||
|
||
```hcl | ||
module "alias" { | ||
source = "mediapop/route53-alias/aws" | ||
alias_hosted_zone_id = aws_s3_bucket.bucket.hosted_zone_id | ||
alias_domain_name = aws_s3_bucket.bucket.bucket_domain_name | ||
record_types = ["A"] | ||
domains = { | ||
"uatdomains.com." = [ | ||
"terraform-aws-route53-alias-ipv4.uatdomains.com", | ||
] | ||
} | ||
} | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
provider "aws" { | ||
region = "ap-southeast-1" | ||
} | ||
|
||
resource "aws_s3_bucket" "bucket" { | ||
# TODO Why can't I use the bucket_regional_domain_name as the alias_domain_name? | ||
website { | ||
index_document = "index.html" | ||
} | ||
} | ||
|
||
module "alias" { | ||
source = "../../" | ||
alias_hosted_zone_id = aws_s3_bucket.bucket.hosted_zone_id | ||
alias_domain_name = aws_s3_bucket.bucket.website_domain | ||
|
||
record_types = ["A"] | ||
|
||
domains = { | ||
"uatdomains.com." = [ | ||
"terraform-aws-route53-alias-ipv4.uatdomains.com", | ||
] | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
data "aws_route53_zone" "zone" { | ||
count = "${length(local.zones)}" | ||
name = "${local.zones[count.index]}" | ||
} | ||
|
||
resource "aws_route53_record" "record" { | ||
count = "${length(local.records) * length(var.record_types)}" | ||
|
||
// We lookup the zone name from the record, then the zone_id from zone_name | ||
zone_id = "${ | ||
element(matchkeys( | ||
data.aws_route53_zone.zone.*.id, | ||
data.aws_route53_zone.zone.*.name, | ||
local.record_map[element(local.records, floor(count.index / local.type_count))] | ||
), 0) | ||
}" | ||
|
||
name = "${element(local.records, floor(count.index / local.type_count))}" | ||
type = "${element(var.record_types, count.index % local.type_count)}" | ||
|
||
alias { | ||
name = "${var.alias_domain_name}" | ||
zone_id = "${var.alias_hosted_zone_id}" | ||
evaluate_target_health = false | ||
} | ||
module "zone_alias" { | ||
for_each = var.domains | ||
source = "./aws-route53-zone-alias" | ||
alias_domain_name = var.alias_domain_name | ||
alias_hosted_zone_id = var.alias_hosted_zone_id | ||
zone = each.key | ||
hosts = each.value | ||
record_types = var.record_types | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} |