Skip to content

Commit 6cce676

Browse files
nitrocodealexjurkiewiczcloudpossebotrazorsedge
authored
Add certificate_authority_arn for private CAs (#53)
* Ensure domain names & SANs are lower-case If you provide an upper-case domain name, this module fails with the following error: on .terraform/modules/my_certificate/main.tf line 37, in resource "aws_route53_record" "default": 37: name = each.value.name A reference to "each.value" has been used in a context in which it unavailable, such as when the configuration no longer contains the value in its "for_each" expression. Remove this reference to each.value in your configuration to work around this error. * Auto Format * Update Terraform minimum version to 0.13 Variable validation requires 0.13.0. * Auto Format * Fix condition * Add output to allow dependencies to run post validation. * Add certificate_authority_arn * Add certificate_authority_arn * Auto Format * Add to contributors * Auto Format * Auto Format * Added back markdown missing from PR * Auto Format * Bump LICENSE to 2022 Co-authored-by: Alex Jurkiewicz <[email protected]> Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: Michael Arnold <[email protected]>
1 parent 761030e commit 6cce676

File tree

7 files changed

+43
-10
lines changed

7 files changed

+43
-10
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017-2019 Cloud Posse, LLC
189+
Copyright 2017-2022 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ Available targets:
174174
|------|-------------|------|---------|:--------:|
175175
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
176176
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
177+
| <a name="input_certificate_authority_arn"></a> [certificate\_authority\_arn](#input\_certificate\_authority\_arn) | ARN of an ACM PCA | `string` | `null` | no |
177178
| <a name="input_certificate_transparency_logging_preference"></a> [certificate\_transparency\_logging\_preference](#input\_certificate\_transparency\_logging\_preference) | Specifies whether certificate details should be added to a certificate transparency log | `bool` | `true` | no |
178179
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
179180
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
@@ -207,6 +208,7 @@ Available targets:
207208
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the certificate |
208209
| <a name="output_domain_validation_options"></a> [domain\_validation\_options](#output\_domain\_validation\_options) | CNAME records that are added to the DNS zone to complete certificate validation |
209210
| <a name="output_id"></a> [id](#output\_id) | The ID of the certificate |
211+
| <a name="output_validation_id"></a> [validation\_id](#output\_validation\_id) | The ID of the certificate validation |
210212
<!-- markdownlint-restore -->
211213

212214

@@ -355,8 +357,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
355357
### Contributors
356358

357359
<!-- markdownlint-disable -->
358-
| [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]<br/>[Vladimir][SweetOps_homepage] |
359-
|---|---|---|---|
360+
| [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Vladimir][SweetOps_avatar]][SweetOps_homepage]<br/>[Vladimir][SweetOps_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]<br/>[RB][nitrocode_homepage] |
361+
|---|---|---|---|---|
360362
<!-- markdownlint-restore -->
361363

362364
[aknysh_homepage]: https://github.com/aknysh
@@ -367,6 +369,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
367369
[goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png
368370
[SweetOps_homepage]: https://github.com/SweetOps
369371
[SweetOps_avatar]: https://img.cloudposse.com/150x150/https://github.com/SweetOps.png
372+
[nitrocode_homepage]: https://github.com/nitrocode
373+
[nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png
370374

371375
[![README Footer][readme_footer_img]][readme_footer_link]
372376
[![Beacon][beacon]][website]

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ contributors:
8585
github: "goruha"
8686
- name: "Vladimir"
8787
github: "SweetOps"
88+
- name: "RB"
89+
github: "nitrocode"

docs/terraform.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
|------|-------------|------|---------|:--------:|
3434
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
3535
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
36+
| <a name="input_certificate_authority_arn"></a> [certificate\_authority\_arn](#input\_certificate\_authority\_arn) | ARN of an ACM PCA | `string` | `null` | no |
3637
| <a name="input_certificate_transparency_logging_preference"></a> [certificate\_transparency\_logging\_preference](#input\_certificate\_transparency\_logging\_preference) | Specifies whether certificate details should be added to a certificate transparency log | `bool` | `true` | no |
3738
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
3839
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
@@ -66,4 +67,5 @@
6667
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the certificate |
6768
| <a name="output_domain_validation_options"></a> [domain\_validation\_options](#output\_domain\_validation\_options) | CNAME records that are added to the DNS zone to complete certificate validation |
6869
| <a name="output_id"></a> [id](#output\_id) | The ID of the certificate |
70+
| <a name="output_validation_id"></a> [validation\_id](#output\_validation\_id) | The ID of the certificate validation |
6971
<!-- markdownlint-restore -->

main.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1+
locals {
2+
enabled = module.this.enabled
3+
zone_name = var.zone_name == "" ? "${var.domain_name}." : var.zone_name
4+
process_domain_validation_options = local.enabled && var.process_domain_validation_options && var.validation_method == "DNS"
5+
domain_validation_options_set = local.process_domain_validation_options ? aws_acm_certificate.default.0.domain_validation_options : toset([])
6+
}
7+
18
resource "aws_acm_certificate" "default" {
29
count = local.enabled ? 1 : 0
310
domain_name = var.domain_name
411
validation_method = var.validation_method
512
subject_alternative_names = var.subject_alternative_names
13+
certificate_authority_arn = var.certificate_authority_arn
14+
615
options {
716
certificate_transparency_logging_preference = var.certificate_transparency_logging_preference ? "ENABLED" : "DISABLED"
817
}
18+
919
tags = module.this.tags
20+
1021
lifecycle {
1122
create_before_destroy = true
1223
}
1324
}
1425

15-
locals {
16-
enabled = module.this.enabled
17-
zone_name = var.zone_name == "" ? "${var.domain_name}." : var.zone_name
18-
process_domain_validation_options = local.enabled && var.process_domain_validation_options && var.validation_method == "DNS"
19-
domain_validation_options_set = local.process_domain_validation_options ? aws_acm_certificate.default.0.domain_validation_options : toset([])
20-
}
21-
2226
data "aws_route53_zone" "default" {
2327
count = local.process_domain_validation_options ? 1 : 0
2428
zone_id = var.zone_id

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ output "domain_validation_options" {
1212
value = aws_acm_certificate.default.*.domain_validation_options
1313
description = "CNAME records that are added to the DNS zone to complete certificate validation"
1414
}
15+
16+
output "validation_id" {
17+
value = join("", aws_acm_certificate_validation.default.*.id)
18+
description = "The ID of the certificate validation"
19+
}

variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ variable "wait_for_certificate_issued" {
77
variable "domain_name" {
88
type = string
99
description = "A domain name for which the certificate should be issued"
10+
11+
validation {
12+
condition = ! can(regex("[A-Z]", var.domain_name))
13+
error_message = "Domain name must be lower-case."
14+
}
1015
}
1116

1217
variable "validation_method" {
@@ -31,6 +36,11 @@ variable "subject_alternative_names" {
3136
type = list(string)
3237
default = []
3338
description = "A list of domains that should be SANs in the issued certificate"
39+
40+
validation {
41+
condition = length([for name in var.subject_alternative_names : name if can(regex("[A-Z]", name))]) == 0
42+
error_message = "All SANs must be lower-case."
43+
}
3444
}
3545

3646
variable "zone_name" {
@@ -50,3 +60,9 @@ variable "certificate_transparency_logging_preference" {
5060
default = true
5161
description = "Specifies whether certificate details should be added to a certificate transparency log"
5262
}
63+
64+
variable "certificate_authority_arn" {
65+
type = string
66+
default = null
67+
description = "ARN of an ACM PCA"
68+
}

0 commit comments

Comments
 (0)