Skip to content

Commit 00db4c9

Browse files
committed
feat: add support for private ca certs
added example for private CA
1 parent 882e020 commit 00db4c9

File tree

9 files changed

+172
-0
lines changed

9 files changed

+172
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ override.tf.json
2727
# Ignore CLI configuration files
2828
.terraformrc
2929
terraform.rc
30+
.qodo

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ No modules.
213213
| <a name="input_dns_ttl"></a> [dns\_ttl](#input\_dns\_ttl) | The TTL of DNS recursive resolvers to cache information about this record. | `number` | `60` | no |
214214
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | A domain name for which the certificate should be issued | `string` | `""` | no |
215215
| <a name="input_key_algorithm"></a> [key\_algorithm](#input\_key\_algorithm) | Specifies the algorithm of the public and private key pair that your Amazon issued certificate uses to encrypt data | `string` | `null` | no |
216+
| <a name="input_private_authority_arn"></a> [private\_authority\_arn](#input\_private\_authority\_arn) | Private Certificate Authority ARN for issuing private certificates | `string` | `null` | no |
216217
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
217218
| <a name="input_subject_alternative_names"></a> [subject\_alternative\_names](#input\_subject\_alternative\_names) | A list of domains that should be SANs in the issued certificate | `list(string)` | `[]` | no |
218219
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to the resource | `map(string)` | `{}` | no |
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
data "aws_availability_zones" "available" {}
6+
7+
locals {
8+
# Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)
9+
use_existing_route53_zone = var.use_existing_route53_zone
10+
11+
domain = var.domain
12+
13+
# Removing trailing dot from domain - just to be sure :)
14+
domain_name = trimsuffix(local.domain, ".")
15+
16+
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id)
17+
18+
region = "eu-west-1"
19+
name = "ex-${basename(path.cwd)}"
20+
vpc_cidr = "10.0.0.0/16"
21+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
22+
23+
tags = {
24+
Name = local.name
25+
Example = local.name
26+
Repository = "https://github.com/terraform-aws-modules/terraform-aws-acm"
27+
}
28+
}
29+
30+
##########################################################
31+
# Example Private CA
32+
##########################################################
33+
34+
data "aws_route53_zone" "this" {
35+
count = local.use_existing_route53_zone ? 1 : 0
36+
37+
name = local.domain_name
38+
private_zone = true
39+
}
40+
41+
resource "aws_route53_zone" "this" {
42+
count = !local.use_existing_route53_zone ? 1 : 0
43+
44+
name = local.domain_name
45+
}
46+
47+
module "acm" {
48+
source = "../../"
49+
50+
providers = {
51+
aws.acm = aws,
52+
aws.dns = aws
53+
}
54+
55+
domain_name = local.domain_name
56+
zone_id = local.zone_id
57+
58+
subject_alternative_names = [
59+
"*.alerts.${local.domain_name}",
60+
"new.sub.${local.domain_name}",
61+
"*.${local.domain_name}",
62+
"alerts.${local.domain_name}",
63+
]
64+
65+
private_authority_arn = aws_acmpca_certificate_authority.root_ca.arn
66+
67+
tags = {
68+
Name = local.domain_name
69+
}
70+
}
71+
72+
################################################################################
73+
# Supporting resources
74+
################################################################################
75+
76+
77+
78+
module "vpc" {
79+
source = "terraform-aws-modules/vpc/aws"
80+
version = "~> 5.0"
81+
82+
name = local.name
83+
cidr = local.vpc_cidr
84+
85+
azs = local.azs
86+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
87+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
88+
89+
tags = local.tags
90+
}
91+
92+
resource "aws_acmpca_certificate_authority" "root_ca" {
93+
type = "ROOT"
94+
95+
certificate_authority_configuration {
96+
key_algorithm = "RSA_4096"
97+
signing_algorithm = "SHA512WITHRSA"
98+
subject {
99+
common_name = "example.com"
100+
organization = "org"
101+
}
102+
}
103+
104+
permanent_deletion_time_in_days = 7
105+
enabled = true
106+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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_status" {
12+
description = "Status of the certificate."
13+
value = module.acm.acm_certificate_status
14+
}
15+
16+
output "acm_certificate_validation_emails" {
17+
description = "A list of addresses that received a validation E-Mail. Only set if EMAIL-validation was used."
18+
value = module.acm.acm_certificate_validation_emails
19+
}
20+
21+
output "validation_route53_record_fqdns" {
22+
description = "List of FQDNs built using the zone domain and name."
23+
value = module.acm.validation_route53_record_fqdns
24+
}
25+
26+
output "distinct_domain_names" {
27+
description = "List of distinct domains names used for the validation."
28+
value = module.acm.distinct_domain_names
29+
}
30+
31+
output "validation_domains" {
32+
description = "List of distinct domain validation options. This is useful if subject alternative names contain wildcards."
33+
value = module.acm.validation_domains
34+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "use_existing_route53_zone" {
2+
description = "Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "domain" {
8+
description = "Domain to be used for the tests"
9+
type = string
10+
default = "terraform-aws-modules.modules.tf"
11+
}
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.40"
8+
}
9+
}
10+
}

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ resource "aws_acm_certificate" "this" {
2424
validation_method = var.validation_method
2525
key_algorithm = var.key_algorithm
2626

27+
certificate_authority_arn = var.private_authority_arn
28+
2729
options {
2830
certificate_transparency_logging_preference = var.certificate_transparency_logging_preference ? "ENABLED" : "DISABLED"
2931
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ variable "key_algorithm" {
123123
default = null
124124
}
125125

126+
variable "private_authority_arn" {
127+
description = "Private Certificate Authority ARN for issuing private certificates"
128+
type = string
129+
default = null
130+
}
131+
126132
variable "putin_khuylo" {
127133
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
128134
type = bool

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module "wrapper" {
1212
dns_ttl = try(each.value.dns_ttl, var.defaults.dns_ttl, 60)
1313
domain_name = try(each.value.domain_name, var.defaults.domain_name, "")
1414
key_algorithm = try(each.value.key_algorithm, var.defaults.key_algorithm, null)
15+
private_authority_arn = try(each.value.private_authority_arn, var.defaults.private_authority_arn, null)
1516
putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true)
1617
subject_alternative_names = try(each.value.subject_alternative_names, var.defaults.subject_alternative_names, [])
1718
tags = try(each.value.tags, var.defaults.tags, {})

0 commit comments

Comments
 (0)