Skip to content

Commit e994b94

Browse files
authored
Merge pull request #1 from patoarvizu/create_module
First version of 'kms-tls-certs' module
2 parents 374a314 + 3970c11 commit e994b94

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

modules/kms-tls-certs/data.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "aws_kms_alias" "vault_packer" {
2+
name = "alias/${var.alias_name}"
3+
}

modules/kms-tls-certs/main.tf

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module "tls_certs" {
2+
source = "github.com/hashicorp/terraform-aws-vault//modules/private-tls-cert?ref=v0.11.3"
3+
ca_public_key_file_path = "${var.output_directory}/ca.crt.pem"
4+
public_key_file_path = "${var.output_directory}/vault.crt.pem"
5+
private_key_file_path = "${var.output_directory}/vault.key.pem"
6+
owner = "${var.owner}"
7+
organization_name = "${var.organization_name}"
8+
ca_common_name = "${var.ca_common_name}"
9+
common_name = "${var.common_name}"
10+
dns_names = "${var.dns_names}"
11+
ip_addresses = "${var.ip_addresses}"
12+
validity_period_hours = "${var.validity_period_hours}"
13+
}
14+
15+
data "local_file" "ca_public_key_file" {
16+
depends_on = [ "module.tls_certs" ]
17+
filename = "${module.tls_certs.ca_public_key_file_path}"
18+
}
19+
20+
data "local_file" "public_key_file" {
21+
depends_on = [ "module.tls_certs" ]
22+
filename = "${module.tls_certs.public_key_file_path}"
23+
}
24+
25+
data "local_file" "private_key_file" {
26+
depends_on = [ "module.tls_certs" ]
27+
filename = "${module.tls_certs.private_key_file_path}"
28+
}
29+
30+
data "aws_kms_ciphertext" "encrypted_ca_public_key" {
31+
key_id = "${data.aws_kms_alias.vault_packer.target_key_id}"
32+
plaintext = "${data.local_file.ca_public_key_file.content}"
33+
}
34+
35+
data "aws_kms_ciphertext" "encrypted_public_key" {
36+
key_id = "${data.aws_kms_alias.vault_packer.target_key_id}"
37+
plaintext = "${data.local_file.public_key_file.content}"
38+
}
39+
40+
data "aws_kms_ciphertext" "encrypted_private_key" {
41+
key_id = "${data.aws_kms_alias.vault_packer.target_key_id}"
42+
plaintext = "${data.local_file.private_key_file.content}"
43+
}

modules/kms-tls-certs/outputs.tf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "ca_public_key" {
2+
value = "\nEncrypted string: ${data.aws_kms_ciphertext.encrypted_ca_public_key.ciphertext_blob}\n\n(File also saved to: ${module.tls_certs.ca_public_key_file_path})\n"
3+
}
4+
5+
output "public_key" {
6+
value = "\nEncrypted string: ${data.aws_kms_ciphertext.encrypted_public_key.ciphertext_blob}\n\n(File also saved to: ${module.tls_certs.public_key_file_path})\n"
7+
}
8+
9+
output "private_key" {
10+
value = "\nEncrypted string: ${data.aws_kms_ciphertext.encrypted_private_key.ciphertext_blob}\n\n(File also saved to: ${module.tls_certs.private_key_file_path})\n"
11+
}

modules/kms-tls-certs/variables.tf

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "owner" {
2+
type = "string"
3+
description = "The OS user who should be given ownership over the certificate files."
4+
}
5+
6+
variable "alias_name" {
7+
type = "string"
8+
}
9+
10+
variable "organization_name" {
11+
type = "string"
12+
}
13+
14+
variable "ca_common_name" {
15+
type = "string"
16+
}
17+
18+
variable "common_name" {
19+
type = "string"
20+
}
21+
22+
variable "validity_period_hours" {
23+
type = "string"
24+
}
25+
26+
variable "output_directory" {
27+
type = "string"
28+
default = "/tmp"
29+
}
30+
31+
variable "dns_names" {
32+
type = "list"
33+
default = []
34+
}
35+
36+
variable "ip_addresses" {
37+
type = "list"
38+
default = []
39+
}

0 commit comments

Comments
 (0)