-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls.tf
77 lines (62 loc) · 1.91 KB
/
tls.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
resource "tls_private_key" "vault-ca" {
algorithm = "RSA"
rsa_bits = "2048"
}
resource "tls_self_signed_cert" "vault-ca" {
key_algorithm = tls_private_key.vault-ca.algorithm
private_key_pem = tls_private_key.vault-ca.private_key_pem
subject {
common_name = "vault-ca.local"
organization = "HashiCorp Vault"
}
validity_period_hours = 8760
is_ca_certificate = true
allowed_uses = [
"cert_signing",
"digital_signature",
"key_encipherment",
]
provisioner "local-exec" {
command = "echo '${self.cert_pem}' > ${var.cert_output_path}/tls/ca.pem && chmod 0600 ${var.cert_output_path}/tls/ca.pem"
}
}
# Create the Vault server certificates
resource "tls_private_key" "vault" {
algorithm = "RSA"
rsa_bits = "2048"
}
# Create the request to sign the cert with our CA
resource "tls_cert_request" "vault" {
key_algorithm = tls_private_key.vault.algorithm
private_key_pem = tls_private_key.vault.private_key_pem
dns_names = [
"vault",
"vault.local",
"vault.default.svc.cluster.local",
]
ip_addresses = [
google_compute_address.vault-ip.address,
]
subject {
common_name = "vault.local"
organization = "HashiCorp Vault"
}
}
# Now sign the cert
resource "tls_locally_signed_cert" "vault" {
cert_request_pem = tls_cert_request.vault.cert_request_pem
ca_key_algorithm = tls_private_key.vault-ca.algorithm
ca_private_key_pem = tls_private_key.vault-ca.private_key_pem
ca_cert_pem = tls_self_signed_cert.vault-ca.cert_pem
validity_period_hours = 8760
allowed_uses = [
"cert_signing",
"client_auth",
"digital_signature",
"key_encipherment",
"server_auth",
]
provisioner "local-exec" {
command = "echo '${self.cert_pem}' > ${var.cert_output_path}/tls/vault.pem && echo '${tls_self_signed_cert.vault-ca.cert_pem}' >> ${var.cert_output_path}/tls/vault.pem && chmod 0600 ${var.cert_output_path}/tls/vault.pem"
}
}