Skip to content

Commit 0825e18

Browse files
authored
feat!: Added validation_option configuration and upgraded AWS provider to v4 (#106)
1 parent 3e88a71 commit 0825e18

File tree

9 files changed

+152
-5
lines changed

9 files changed

+152
-5
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module "acm" {
8686
- [Complete example with DNS validation (recommended)](https://github.com/terraform-aws-modules/terraform-aws-acm/tree/master/examples/complete-dns-validation)
8787
- [Complete example with DNS validation via external DNS provider (CloudFlare)](https://github.com/terraform-aws-modules/terraform-aws-acm/tree/master/examples/complete-dns-validation-with-cloudflare)
8888
- [Complete example with EMAIL validation](https://github.com/terraform-aws-modules/terraform-aws-acm/tree/master/examples/complete-email-validation)
89+
- [Complete example with EMAIL validation and validation domain override](https://github.com/terraform-aws-modules/terraform-aws-acm/tree/master/examples/complete-email-validation-with-validation-domain)
8990

9091
## Conditional creation and validation
9192

@@ -121,14 +122,14 @@ module "acm" {
121122

122123
| Name | Version |
123124
|------|---------|
124-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
125-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.53 |
125+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
126+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.12.0 |
126127

127128
## Providers
128129

129130
| Name | Version |
130131
|------|---------|
131-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.53 |
132+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.12.0 |
132133

133134
## Modules
134135

@@ -157,6 +158,7 @@ No modules.
157158
| <a name="input_validate_certificate"></a> [validate\_certificate](#input\_validate\_certificate) | Whether to validate certificate by creating Route53 record | `bool` | `true` | no |
158159
| <a name="input_validation_allow_overwrite_records"></a> [validation\_allow\_overwrite\_records](#input\_validation\_allow\_overwrite\_records) | Whether to allow overwrite of Route53 records | `bool` | `true` | no |
159160
| <a name="input_validation_method"></a> [validation\_method](#input\_validation\_method) | Which method to use for validation. DNS or EMAIL are valid, NONE can be used for certificates that were imported into ACM and then into Terraform. | `string` | `"DNS"` | no |
161+
| <a name="input_validation_option"></a> [validation\_option](#input\_validation\_option) | The domain name that you want ACM to use to send you validation emails. This domain name is the suffix of the email addresses that you want ACM to use. | `map(string)` | `{}` | no |
160162
| <a name="input_validation_record_fqdns"></a> [validation\_record\_fqdns](#input\_validation\_record\_fqdns) | When validation is set to DNS and the DNS validation records are set externally, provide the fqdns for the validation | `list(string)` | `[]` | no |
161163
| <a name="input_wait_for_validation"></a> [wait\_for\_validation](#input\_wait\_for\_validation) | Whether to wait for the validation to complete | `bool` | `true` | no |
162164
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | The ID of the hosted zone to contain this record. Required when validating via Route53 | `string` | `""` | no |
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Complete ACM example with EMAIL validation with validation_domain configured
2+
3+
Configuration in this directory creates new Route53 zone and ACM certificate (valid for the domain name and wildcard).
4+
5+
ACM certificate will be created with EMAIL validation method, which means that emails will be send to domain owners and it is not possible to automate using Terraform!
6+
The validation domain option is set, which overrides the domain to which validation emails will be sent.
7+
8+
If you want to use EMAIL validation method make sure that you have access to at least one of these emails in your domain:
9+
10+
```
11+
hostmaster@VALIDATION_DOMAIN
12+
postmaster@VALIDATION_DOMAIN
13+
admin@VALIDATION_DOMAIN
14+
administrator@VALIDATION_DOMAIN
15+
webmaster@VALIDATION_DOMAIN
16+
```
17+
18+
## Usage
19+
20+
To run this example you need to execute:
21+
22+
```bash
23+
$ terraform init
24+
$ terraform plan -var 'domain_name=foo.bar.com' -var 'validation_domain=bar.com'
25+
$ terraform apply -var 'domain_name=foo.bar.com' -var 'validation_domain=bar.com'
26+
```
27+
28+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
29+
30+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
31+
## Requirements
32+
33+
| Name | Version |
34+
|------|---------|
35+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
36+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.12.0 |
37+
38+
## Providers
39+
40+
| Name | Version |
41+
|------|---------|
42+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.12.0 |
43+
44+
## Modules
45+
46+
| Name | Source | Version |
47+
|------|--------|---------|
48+
| <a name="module_acm"></a> [acm](#module\_acm) | ../../ | n/a |
49+
50+
## Resources
51+
52+
| Name | Type |
53+
|------|------|
54+
| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource |
55+
56+
## Inputs
57+
58+
| Name | Description | Type | Default | Required |
59+
|------|-------------|------|---------|:--------:|
60+
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Domain name to use as Route53 zone and ACM certificate | `string` | n/a | yes |
61+
| <a name="input_validation_domain"></a> [validation\_domain](#input\_validation\_domain) | Domain name to use for verifying var.domain\_name | `string` | n/a | yes |
62+
63+
## Outputs
64+
65+
| Name | Description |
66+
|------|-------------|
67+
| <a name="output_acm_certificate_arn"></a> [acm\_certificate\_arn](#output\_acm\_certificate\_arn) | The ARN of the certificate |
68+
| <a name="output_acm_certificate_domain_validation_options"></a> [acm\_certificate\_domain\_validation\_options](#output\_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. |
69+
| <a name="output_acm_certificate_validation_emails"></a> [acm\_certificate\_validation\_emails](#output\_acm\_certificate\_validation\_emails) | A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used. |
70+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "aws_route53_zone" "this" {
2+
name = var.domain_name
3+
}
4+
5+
module "acm" {
6+
source = "../../"
7+
8+
domain_name = var.domain_name
9+
zone_id = aws_route53_zone.this.zone_id
10+
11+
# The key is the domain name which you want to change the validation domain for.
12+
# Validation emails will be send to a fixed list of recipients:
13+
# admin@VALIDATION_DOMAIN, administrator@VALIDATION_DOMAIN, hostmaster@VALIDATION_DOMAIN, postmaster@VALIDATION_DOMAIN, webmaster@VALIDATION_DOMAIN
14+
# validation_domain has to be a top-level domain of the actual domain
15+
validation_option = {
16+
(var.domain_name) = {
17+
validation_domain = var.validation_domain
18+
}
19+
}
20+
21+
validation_method = "EMAIL"
22+
wait_for_validation = false
23+
24+
tags = {
25+
Name = var.domain_name
26+
}
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "acm_certificate_arn" {
2+
description = "The ARN of the certificate"
3+
value = module.acm.acm_certificate_arn
4+
}
5+
6+
output "acm_certificate_domain_validation_options" {
7+
description = "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."
8+
value = module.acm.acm_certificate_domain_validation_options
9+
}
10+
11+
output "acm_certificate_validation_emails" {
12+
description = "A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used."
13+
value = module.acm.acm_certificate_validation_emails
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "domain_name" {
2+
description = "Domain name to use as Route53 zone and ACM certificate"
3+
type = string
4+
}
5+
6+
variable "validation_domain" {
7+
description = "Domain name to use for verifying var.domain_name"
8+
type = string
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.12.0"
8+
}
9+
}
10+
}

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ resource "aws_acm_certificate" "this" {
2626
certificate_transparency_logging_preference = var.certificate_transparency_logging_preference ? "ENABLED" : "DISABLED"
2727
}
2828

29+
dynamic "validation_option" {
30+
for_each = var.validation_option
31+
32+
content {
33+
domain_name = try(validation_option.value["domain_name"], validation_option.key)
34+
validation_domain = validation_option.value["validation_domain"]
35+
}
36+
}
37+
2938
tags = var.tags
3039

3140
lifecycle {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ variable "validation_method" {
5151
}
5252
}
5353

54+
variable "validation_option" {
55+
description = "The domain name that you want ACM to use to send you validation emails. This domain name is the suffix of the email addresses that you want ACM to use."
56+
type = map(string)
57+
default = {}
58+
}
59+
5460
variable "create_route53_records" {
5561
description = "When validation is set to DNS, define whether to create the DNS records internally via Route53 or externally using any DNS provider"
5662
type = bool

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 2.53"
7+
version = ">= 4.12.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)