Skip to content

Commit 988d1ed

Browse files
committed
feat:add new variables to acm module
1 parent 092b70e commit 988d1ed

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

examples/generate-certificate-dns/example.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ provider "aws" {
33
}
44

55
locals {
6-
domain = "clouddrove.com"
6+
domain = "ld.clouddrove.ca"
77
}
88

99
##-----------------------------------------------------------------------------
@@ -12,8 +12,11 @@ locals {
1212
module "acm" {
1313
source = "./../../"
1414

15-
name = "certificate"
16-
environment = "test"
17-
domain_name = "clouddrove.com"
18-
subject_alternative_names = ["www.${local.domain}", "*.${local.domain}"]
19-
}
15+
name = "certificate"
16+
environment = "test"
17+
enable_dns_validation = true
18+
domain_name = "ld.clouddrove.ca"
19+
subject_alternative_names = ["www.${local.domain}", "*.${local.domain}"]
20+
key_algorithm = "RSA_2048"
21+
transparency_logging_enabled = false
22+
}

examples/generate-certificate-dns/outputs.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ output "validation_route53_record_fqdns" {
2323
description = "List of FQDNs built using the zone domain and name."
2424
}
2525

26-
26+
output "certificate_transparency_logging_preference" {
27+
value = module.acm
28+
description = "Certificate transparency logging preference."
29+
}

main.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ resource "aws_acm_certificate" "cert" {
4545
domain_name = var.domain_name
4646
validation_method = var.validation_method
4747
subject_alternative_names = var.subject_alternative_names
48+
key_algorithm = var.key_algorithm
4849
tags = module.labels.tags
4950

5051
dynamic "validation_option" {
@@ -56,6 +57,14 @@ resource "aws_acm_certificate" "cert" {
5657
}
5758
}
5859

60+
dynamic "options" {
61+
for_each = var.transparency_logging_enabled != null ? [1] : []
62+
content {
63+
certificate_transparency_logging_preference = var.transparency_logging_enabled ? "ENABLED" : "DISABLED"
64+
}
65+
}
66+
67+
5968
lifecycle {
6069
create_before_destroy = true
6170
}
@@ -65,7 +74,7 @@ resource "aws_acm_certificate" "cert" {
6574
## Most commonly, this resource is used together with aws_route53_record and aws_acm_certificate to request a DNS validated certificate, deploy the required validation records and wait for validation to complete.
6675
##----------------------------------------------------------------------------------
6776
resource "aws_acm_certificate_validation" "cert" {
68-
count = var.enable && var.validate_certificate ? 1 : 0
77+
count = var.enable && var.enable_dns_validation && var.validate_certificate ? 1 : 0
6978
certificate_arn = join("", aws_acm_certificate.cert[*].arn)
7079
validation_record_fqdns = flatten([aws_route53_record.default[*].fqdn, var.validation_record_fqdns])
7180

@@ -84,13 +93,13 @@ data "aws_route53_zone" "default" {
8493
## A Route 53 record contains authoritative DNS information for a specified DNS name. DNS records are most commonly used to map a name to an IP Address..
8594
##----------------------------------------------------------------------------------
8695
resource "aws_route53_record" "default" {
87-
for_each = {
96+
for_each = var.enable_dns_validation ? {
8897
for record in aws_acm_certificate.cert[0].domain_validation_options[*] : record.domain_name => {
8998
name = record.resource_record_name
9099
record = record.resource_record_value
91100
type = record.resource_record_type
92101
}
93-
}
102+
} : {}
94103

95104
allow_overwrite = var.allow_overwrite
96105
name = each.value.name

outputs.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ output "acm_certificate_status" {
2626
description = "Status of the certificate."
2727
}
2828

29-
3029
output "validation_route53_record_fqdns" {
3130
value = [for record in aws_route53_record.default : record.fqdn]
3231
description = "List of FQDNs built using the zone domain and name."
32+
}
33+
34+
output "certificate_transparency_logging_preference" {
35+
value = try(aws_acm_certificate.cert[0].options[0].certificate_transparency_logging_preference, null)
36+
description = "Certificate transparency logging preference."
3337
}

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,15 @@ variable "private_zone" {
128128
description = "Used with name field to get a private Hosted Zone."
129129
}
130130

131+
variable "key_algorithm" {
132+
type = string
133+
default = null
134+
description = "used to generate the public/private key pair for the certificate. Valid values: RSA_2048, RSA_4096, EC_prime256v1, EC_secp384r1, EC_secp521r1."
135+
}
136+
137+
variable "transparency_logging_enabled" {
138+
type = bool
139+
default = false
140+
description = "Whether to enable certificate transparency logging. Defaults to true. Set to false to disable."
141+
}
131142

0 commit comments

Comments
 (0)