Skip to content

Commit a93a897

Browse files
committed
Make creating acm validation records optional
1 parent 45ee40a commit a93a897

6 files changed

Lines changed: 27 additions & 8 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module "ingress" {
2121
2222
alarm_actions = [data.aws_sns_topic.cloudwatch_alarms]
2323
alternate_domain_names = ["example.com", "api.example.com"]
24+
create_validation_records = true
2425
description = "My example application"
2526
hosted_zone_name = "example.com"
2627
name = "example-ingress"
@@ -71,6 +72,9 @@ module "ingress" {
7172
# Disable issuing of certificates entirely.
7273
issue_certificates = false
7374
75+
# Disable creation of Route 53 validation records when they already exist.
76+
create_validation_records = false
77+
7478
# If you have multiple DNS hosted zones, you can set the hosted zone name for
7579
# each domain name:
7680
additional_hosted_zones = {
@@ -145,6 +149,7 @@ the combination of hosted zone, record name, and record type.
145149
| <a name="input_certificate_domain_name"></a> [certificate\_domain\_name](#input\_certificate\_domain\_name) | Override the domain name for the ACM certificate (defaults to primary domain) | `string` | `null` | no |
146150
| <a name="input_certificate_types"></a> [certificate\_types](#input\_certificate\_types) | Types of certificates to look for (default: AMAZON\_ISSUED) | `list(string)` | <pre>[<br> "AMAZON_ISSUED"<br>]</pre> | no |
147151
| <a name="input_create_aliases"></a> [create\_aliases](#input\_create\_aliases) | Set to false to disable creation of Route 53 aliases | `bool` | `true` | no |
152+
| <a name="input_create_validation_records"></a> [create\_validation\_records](#input\_create\_validation\_records) | Create Route53 DNS validation records for ACM certificates managed by this module | `bool` | `true` | no |
148153
| <a name="input_description"></a> [description](#input\_description) | Human description for this load balancer | `string` | n/a | yes |
149154
| <a name="input_enable_stickiness"></a> [enable\_stickiness](#input\_enable\_stickiness) | Set to true to use a cookie for load balancer stickiness | `bool` | `false` | no |
150155
| <a name="input_failure_threshold"></a> [failure\_threshold](#input\_failure\_threshold) | Percentage of failed requests considered an anomaly | `number` | `5` | no |

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ module "acm_certificate" {
5252
providers = { aws.certificate = aws.cluster, aws.route53 = aws.route53 }
5353
source = "./modules/acm-certificate"
5454

55-
allow_overwrite = var.allow_overwrite
56-
domain_name = each.value
55+
allow_overwrite = var.allow_overwrite
56+
create_validation_records = var.create_validation_records
57+
domain_name = each.value
5758

5859
hosted_zone_name = (
5960
var.validate_certificates ?

modules/acm-certificate/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ No modules.
3333
|------|-------------|------|---------|:--------:|
3434
| <a name="input_allow_overwrite"></a> [allow\_overwrite](#input\_allow\_overwrite) | Allow overwriting of existing DNS records | `bool` | `false` | no |
3535
| <a name="input_alternative_names"></a> [alternative\_names](#input\_alternative\_names) | Other domains which should be included in the certificate | `list(string)` | `[]` | no |
36+
| <a name="input_create_validation_records"></a> [create\_validation\_records](#input\_create\_validation\_records) | Create Route53 DNS validation records for the certificate | `bool` | `true` | no |
3637
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Domain for which an SSL certificate should be created | `string` | n/a | yes |
3738
| <a name="input_hosted_zone_name"></a> [hosted\_zone\_name](#input\_hosted\_zone\_name) | Zone for AWS Route53 for verifying certificates | `string` | `null` | no |
3839
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to be applied to created resources | `map(string)` | `{}` | no |

modules/acm-certificate/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ locals {
2626
resource "aws_route53_record" "validation" {
2727
provider = aws.route53
2828

29-
count = var.hosted_zone_name == null ? 0 : 1
29+
count = var.hosted_zone_name == null || !var.create_validation_records ? 0 : 1
3030

3131
allow_overwrite = var.allow_overwrite
3232
name = local.domain_validation_options[0].resource_record_name
@@ -39,7 +39,7 @@ resource "aws_route53_record" "validation" {
3939
resource "aws_route53_record" "alternative_validation" {
4040
provider = aws.route53
4141

42-
count = var.hosted_zone_name == null ? 0 : length(var.alternative_names)
42+
count = var.hosted_zone_name == null || !var.create_validation_records ? 0 : length(var.alternative_names)
4343

4444
allow_overwrite = var.allow_overwrite
4545
name = local.domain_validation_options[count.index].resource_record_name
@@ -54,10 +54,10 @@ resource "aws_acm_certificate_validation" "this" {
5454

5555
certificate_arn = aws_acm_certificate.this.arn
5656

57-
validation_record_fqdns = concat(
58-
aws_route53_record.validation.*.fqdn,
59-
aws_route53_record.alternative_validation.*.fqdn
60-
)
57+
validation_record_fqdns = var.create_validation_records ? concat(
58+
aws_route53_record.validation[*].fqdn,
59+
aws_route53_record.alternative_validation[*].fqdn
60+
) : null
6161
}
6262

6363
data "aws_route53_zone" "this" {

modules/acm-certificate/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ variable "alternative_names" {
1010
default = []
1111
}
1212

13+
variable "create_validation_records" {
14+
type = bool
15+
description = "Create Route53 DNS validation records for the certificate"
16+
default = true
17+
}
18+
1319
variable "domain_name" {
1420
type = string
1521
description = "Domain for which an SSL certificate should be created"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ variable "create_aliases" {
6565
default = true
6666
}
6767

68+
variable "create_validation_records" {
69+
description = "Create Route53 DNS validation records for ACM certificates managed by this module"
70+
type = bool
71+
default = true
72+
}
73+
6874
variable "description" {
6975
description = "Human description for this load balancer"
7076
type = string

0 commit comments

Comments
 (0)