Skip to content

Commit 3af7bf2

Browse files
authored
fix: Fixed wildcard in domain names (#71)
1 parent 3ceb5d2 commit 3af7bf2

File tree

7 files changed

+47
-13
lines changed

7 files changed

+47
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
terraform.tfstate
33
*.tfstate*
44
terraform.tfvars
5+
.terraform.lock.hcl

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
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.44.0
3+
rev: v1.45.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -21,6 +21,6 @@ repos:
2121
- '--args=--only=terraform_standard_module_structure'
2222
- '--args=--only=terraform_workspace_remote'
2323
- repo: git://github.com/pre-commit/pre-commit-hooks
24-
rev: v3.3.0
24+
rev: v3.4.0
2525
hooks:
2626
- id: check-merge-conflict

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Terraform module which creates ACM certificates and validates them using Route53
66

77
Terraform 0.12. Pin module version to `~> v2.0`. Submit pull-requests to `master` branch.
88

9-
Terraform 0.11. Pin module version to `~> v1.0`. Submit pull-requests to `terraform011` branch.
9+
Terraform 0.11. Pin module version to `~> v1.0`.
1010

1111
## Usage with Route53 DNS validation (recommended)
1212

@@ -61,7 +61,6 @@ module "acm" {
6161
## Notes
6262

6363
* For use in an automated pipeline consider setting the `wait_for_validation = false` to avoid waiting for validation to complete or error after a 45 minute timeout.
64-
* `domain_name` can not be wildcard, but `subject_alternative_names` can include wildcards.
6564

6665
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6766
## Requirements
@@ -77,6 +76,18 @@ module "acm" {
7776
|------|---------|
7877
| aws | >= 2.53 |
7978

79+
## Modules
80+
81+
No Modules.
82+
83+
## Resources
84+
85+
| Name |
86+
|------|
87+
| [aws_acm_certificate_validation](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/acm_certificate_validation) |
88+
| [aws_acm_certificate](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/acm_certificate) |
89+
| [aws_route53_record](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_record) |
90+
8091
## Inputs
8192

8293
| Name | Description | Type | Default | Required |
@@ -103,7 +114,6 @@ module "acm" {
103114
| this\_acm\_certificate\_validation\_emails | A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used. |
104115
| validation\_domains | List of distinct domain validation options. This is useful if subject alternative names contain wildcards. |
105116
| validation\_route53\_record\_fqdns | List of FQDNs built using the zone domain and name. |
106-
107117
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
108118

109119
## Authors

examples/complete-dns-validation/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ Note that this example may create resources which cost money. Run `terraform des
3232
|------|---------|
3333
| aws | >= 2.53 |
3434

35+
## Modules
36+
37+
| Name | Source | Version |
38+
|------|--------|---------|
39+
| acm | ../../ | |
40+
41+
## Resources
42+
43+
| Name |
44+
|------|
45+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/data-sources/route53_zone) |
46+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_zone) |
47+
3548
## Inputs
3649

3750
No input.
@@ -46,5 +59,4 @@ No input.
4659
| this\_acm\_certificate\_validation\_emails | A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used. |
4760
| validation\_domains | List of distinct domain validation options. This is useful if subject alternative names contain wildcards. |
4861
| validation\_route53\_record\_fqdns | List of FQDNs built using the zone domain and name. |
49-
5062
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/complete-dns-validation/main.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data "aws_route53_zone" "this" {
1616
}
1717

1818
resource "aws_route53_zone" "this" {
19-
count = ! local.use_existing_route53_zone ? 1 : 0
19+
count = !local.use_existing_route53_zone ? 1 : 0
2020
name = local.domain_name
2121
}
2222

@@ -28,10 +28,8 @@ module "acm" {
2828

2929
subject_alternative_names = [
3030
"*.alerts.${local.domain_name}",
31-
"*.something.${local.domain_name}",
32-
"*.news.${local.domain_name}",
33-
"*.info.${local.domain_name}",
3431
"new.sub.${local.domain_name}",
32+
"*.${local.domain_name}",
3533
]
3634

3735
wait_for_validation = true

examples/complete-email-validation/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ Note that this example may create resources which cost money. Run `terraform des
4545
|------|---------|
4646
| aws | >= 2.53 |
4747

48+
## Modules
49+
50+
| Name | Source | Version |
51+
|------|--------|---------|
52+
| acm | ../../ | |
53+
54+
## Resources
55+
56+
| Name |
57+
|------|
58+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_zone) |
59+
4860
## Inputs
4961

5062
| Name | Description | Type | Default | Required |
@@ -58,5 +70,4 @@ Note that this example may create resources which cost money. Run `terraform des
5870
| this\_acm\_certificate\_arn | The ARN of the certificate |
5971
| this\_acm\_certificate\_domain\_validation\_options | A list of attributes to feed into other resources to complete certificate validation. Can have more than one element, e.g. if SANs are defined. Only set if DNS-validation was used. |
6072
| this\_acm\_certificate\_validation\_emails | A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used. |
61-
6273
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
locals {
22
# Get distinct list of domains and SANs
3-
distinct_domain_names = distinct(concat([var.domain_name], [for s in var.subject_alternative_names : replace(s, "*.", "")]))
3+
distinct_domain_names = distinct(
4+
[for s in concat([var.domain_name], var.subject_alternative_names) : replace(s, "*.", "")]
5+
)
46

57
# Copy domain_validation_options for the distinct domain names
68
validation_domains = var.create_certificate ? [for k, v in aws_acm_certificate.this[0].domain_validation_options : tomap(v) if contains(local.distinct_domain_names, replace(v.domain_name, "*.", ""))] : []
@@ -25,7 +27,7 @@ resource "aws_acm_certificate" "this" {
2527
}
2628

2729
resource "aws_route53_record" "validation" {
28-
count = var.create_certificate && var.validation_method == "DNS" && var.validate_certificate ? length(local.distinct_domain_names) + 1 : 0
30+
count = var.create_certificate && var.validation_method == "DNS" && var.validate_certificate ? length(local.distinct_domain_names) : 0
2931

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

0 commit comments

Comments
 (0)