Commit def53274 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

feat: Added fix for records with terragrunt (#42)

parent 736dcb71
......@@ -2,6 +2,8 @@
Configuration in this directory creates Route53 zones and records for various types of resources - S3 bucket, CloudFront distribution, static records.
Also, there is a solution for Terragrunt users.
## Usage
To run this example you need to execute:
......@@ -35,6 +37,7 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_cloudfront"></a> [cloudfront](#module\_cloudfront) | terraform-aws-modules/cloudfront/aws | |
| <a name="module_disabled_records"></a> [disabled\_records](#module\_disabled\_records) | ../../modules/records | |
| <a name="module_records"></a> [records](#module\_records) | ../../modules/records | |
| <a name="module_records_with_terragrunt"></a> [records\_with\_terragrunt](#module\_records\_with\_terragrunt) | ../../modules/records | |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | |
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | |
......
......@@ -130,6 +130,34 @@ module "records" {
depends_on = [module.zones]
}
module "records_with_terragrunt" {
source = "../../modules/records"
zone_name = keys(module.zones.route53_zone_zone_id)[0]
# Terragrunt has a bug (https://github.com/gruntwork-io/terragrunt/issues/1211) that requires `records` to be wrapped with `jsonencode()`
records = jsonencode([
{
name = "new"
type = "A"
ttl = 3600
records = [
"10.10.10.10",
]
},
{
name = "s3-bucket-new"
type = "A"
alias = {
name = module.s3_bucket.s3_bucket_website_domain
zone_id = module.s3_bucket.s3_bucket_hosted_zone_id
}
}
])
depends_on = [module.zones]
}
module "disabled_records" {
source = "../../modules/records"
......
locals {
# terragrunt users have to provide `records` as jsonencode()'d string.
# See details: https://github.com/gruntwork-io/terragrunt/issues/1211
records = try(jsondecode(var.records), var.records)
# convert from list to map with unique keys
recordsets = { for rs in var.records : join(" ", compact(["${rs.name} ${rs.type}", lookup(rs, "set_identifier", "")])) => rs }
recordsets = { for rs in local.records : join(" ", compact(["${rs.name} ${rs.type}", lookup(rs, "set_identifier", "")])) => rs }
}
data "aws_route53_zone" "this" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment