Skip to content

Commit dcad414

Browse files
committed
Updated example with multiple SANs after PR #32
1 parent 43a87c2 commit dcad414

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.20.0
3+
rev: v1.21.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs

examples/complete-dns-validation/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ $ terraform apply
1919
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
2020

2121
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22-
## Inputs
23-
24-
| Name | Description | Type | Default | Required |
25-
|------|-------------|:----:|:-----:|:-----:|
26-
| domain\_name | Domain name to use as Route53 zone and ACM certificate | string | `"my-domain-name.com"` | no |
27-
2822
## Outputs
2923

3024
| Name | Description |
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1-
variable "domain_name" {
2-
description = "Domain name to use as Route53 zone and ACM certificate"
3-
default = "my-domain-name.com"
1+
locals {
2+
# Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)
3+
use_existing_route53_zone = true
4+
5+
domain = "terraform-aws-modules.modules.tf"
6+
7+
# Removing trailing dot from domain - just to be sure :)
8+
domain_name = trimsuffix(local.domain, ".")
9+
}
10+
11+
data "aws_route53_zone" "this" {
12+
count = local.use_existing_route53_zone ? 1 : 0
13+
14+
name = local.domain_name
15+
private_zone = false
416
}
517

618
resource "aws_route53_zone" "this" {
7-
name = var.domain_name
19+
count = ! local.use_existing_route53_zone ? 1 : 0
20+
name = local.domain_name
821
}
922

1023
module "acm" {
1124
source = "../../"
1225

13-
domain_name = var.domain_name
14-
zone_id = aws_route53_zone.this.zone_id
26+
domain_name = local.domain_name
27+
zone_id = coalescelist(data.aws_route53_zone.this.*.zone_id, aws_route53_zone.this.*.zone_id)[0]
1528

1629
subject_alternative_names = [
17-
"*.${var.domain_name}",
18-
"new.sub.${var.domain_name}",
30+
"*.alerts.${local.domain_name}",
31+
"*.something.${local.domain_name}",
32+
"*.news.${local.domain_name}",
33+
"*.info.${local.domain_name}",
34+
"new.sub.${local.domain_name}",
1935
]
2036

21-
wait_for_validation = false # true
37+
wait_for_validation = true
2238

2339
tags = {
24-
Name = var.domain_name
40+
Name = local.domain_name
2541
}
2642
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "aws_acm_certificate" "this" {
2121
}
2222

2323
resource "aws_route53_record" "validation" {
24-
count = var.create_certificate && var.validation_method == "DNS" && var.validate_certificate ? length(local.distinct_domain_names)+1 : 0
24+
count = var.create_certificate && var.validation_method == "DNS" && var.validate_certificate ? length(local.distinct_domain_names) + 1 : 0
2525

2626
zone_id = var.zone_id
2727
name = element(local.validation_domains, count.index)["resource_record_name"]

0 commit comments

Comments
 (0)