|
1 | 1 | locals {
|
2 | 2 | # Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)
|
3 |
| - use_existing_route53_zone = true |
| 3 | + use_existing_route53_zone = var.use_existing_route53_zone |
4 | 4 |
|
5 |
| - domain = "terraform-aws-modules.modules.tf" |
| 5 | + domain = var.domain |
| 6 | + extra_domain = var.extra_domain |
6 | 7 |
|
7 | 8 | # Removing trailing dot from domain - just to be sure :)
|
8 | 9 | domain_name = trimsuffix(local.domain, ".")
|
@@ -103,3 +104,46 @@ module "route53_records_only" {
|
103 | 104 |
|
104 | 105 | acm_certificate_domain_validation_options = module.acm_only.acm_certificate_domain_validation_options
|
105 | 106 | }
|
| 107 | + |
| 108 | +############################################################################### |
| 109 | +# Example 3: |
| 110 | +# Single certificate with multiple domains from different Route53 hosted zones. |
| 111 | +# Useful when using the certificate for CloudFront, which only support a |
| 112 | +# single certificate per distribution. |
| 113 | +############################################################################### |
| 114 | + |
| 115 | +data "aws_route53_zone" "extra" { |
| 116 | + count = local.use_existing_route53_zone ? 1 : 0 |
| 117 | + |
| 118 | + name = local.extra_domain |
| 119 | + private_zone = false |
| 120 | +} |
| 121 | + |
| 122 | +resource "aws_route53_zone" "extra" { |
| 123 | + count = !local.use_existing_route53_zone ? 1 : 0 |
| 124 | + |
| 125 | + name = local.extra_domain |
| 126 | +} |
| 127 | + |
| 128 | +module "acm_multi_domain" { |
| 129 | + source = "../../" |
| 130 | + |
| 131 | + domain_name = local.domain_name |
| 132 | + zone_id = local.zone_id |
| 133 | + |
| 134 | + subject_alternative_names = [ |
| 135 | + "*.alerts.${local.domain_name}", |
| 136 | + "new.sub.${local.domain_name}", |
| 137 | + local.extra_domain, |
| 138 | + "*.alerts.${local.extra_domain}", |
| 139 | + "new.sub.${local.extra_domain}", |
| 140 | + ] |
| 141 | + |
| 142 | + validation_method = "DNS" |
| 143 | + |
| 144 | + zones = { |
| 145 | + (local.extra_domain) = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id), |
| 146 | + "alerts.${local.extra_domain}" = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id), |
| 147 | + "new.sub.${local.extra_domain}" = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id) |
| 148 | + } |
| 149 | +} |
0 commit comments