generated from terraform-modules/template_aws_submodules
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
155 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # tf-apply $(grep ^[rd] ca-cert.tf |awk '{print "-target=" $2 "." $3}' |sed -e 's/"//g') | ||
| # terraform taint null_resource.ca_cert[0] | ||
| # # (wait for submitted cert to be ready) | ||
| # tf-apply $(grep ^[rd] ca-cert.tf |awk '{print "-target=" $2 "." $3}' |sed -e 's/"//g') | ||
| # tf-apply $(grep ^[rd] ca-cert.tf |awk '{print "-target=" $2 "." $3}' |sed -e 's/"//g') | ||
|
|
||
| #--- | ||
| # ca | ||
| #--- | ||
| locals { | ||
| ca_dns_name = format("pki.%v.%v", var.cluster_name, var.vpc_domain_name) | ||
| # ca_ou = format("ou=%v,ou=EKS,ou=%v,ou=PKI",var.cluster_name,var.vpc_full_name) | ||
| ca_ou = format("eks-%v-%v-PKI", var.cluster_name, var.vpc_full_name) | ||
| ca_cert_download = false | ||
| ca_cert_san = [local.ca_dns_name] | ||
|
|
||
| ca_key_filename = format("${path.root}/certs/%v.key", local.ca_dns_name) | ||
| ca_key_exists = fileexists(local.ca_key_filename) | ||
| ca_cert_filename = format("${path.root}/certs/%v.crt", local.ca_dns_name) | ||
| ca_cert_exists = fileexists(local.ca_cert_filename) | ||
| ca_root_filename = "${path.root}/certs/ca-root.crt" | ||
| ca_root_exists = fileexists(local.ca_root_filename) | ||
| ca_bundle_contents = local.ca_cert_exists && local.ca_root_exists ? format("%v%v", file(local.ca_cert_filename), file(local.ca_root_filename)) : "" | ||
| ca_bundle_filename = format("${path.root}/certs/%v.bundle.crt", local.ca_dns_name) | ||
| } | ||
|
|
||
| module "cert" { | ||
| source = "git@github.e.it.census.gov:terraform-modules/aws-tls-certificate" | ||
|
|
||
| certificate_cn = local.ca_dns_name | ||
| certificate_san = [local.ca_dns_name] | ||
| certificate_download = true | ||
| enable_acm_certificate = false | ||
| certificate_subject_overrides = { ou = local.ca_ou } | ||
| certificate_csr_message = <<EOM | ||
| Now submit file to TCO for signing and return the result as below: | ||
| dns = ${local.ca_dns_name} | ||
| csr = certs/${local.ca_dns_name}.csr | ||
| Ask for the certificate to be signed with the Linux (v2) PKI CA with the command: | ||
| % ./sign-subordinate-ca-cert.sh ${local.ca_dns_name}.csr 'c=US,o=U.S. Census Bureau,OU=PKI,ou=EKS,ou=${var.vpc_full_name},ou=${var.cluster_name},cn=${local.ca_dns_name}' 730" | ||
| EOM | ||
| } | ||
|
|
||
| ## resource "tls_private_key" "ca" { | ||
| ## algorithm = "RSA" | ||
| ## rsa_bits = 4096 | ||
| ## } | ||
| ## | ||
| ## resource "tls_cert_request" "ca" { | ||
| ## key_algorithm = "RSA" | ||
| ## private_key_pem = tls_private_key.ca.private_key_pem | ||
| ## | ||
| ## dns_names = local.ca_cert_san | ||
| ## subject { | ||
| ## common_name = local.ca_dns_name | ||
| ## organizational_unit = local.ca_ou | ||
| ## organization = "U.S. Census Bureau" | ||
| ## country = "US" | ||
| ## } | ||
| ## } | ||
| ## | ||
| ## resource "null_resource" "ca_root_cert" { | ||
| ## provisioner "local-exec" { | ||
| ## command = "test -d certs || mkdir certs" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "curl -o ${local.ca_root_filename} http://ca.apps.tco.census.gov/certs/ca" | ||
| ## } | ||
| ## } | ||
| ## | ||
| ## resource "null_resource" "ca_files" { | ||
| ## triggers = { | ||
| ## ca_key_public = sha256(tls_private_key.ca.public_key_pem) | ||
| ## ca_csr = sha256(tls_cert_request.ca.cert_request_pem) | ||
| ## } | ||
| ## | ||
| ## # get key | ||
| ## provisioner "local-exec" { | ||
| ## command = "test -d certs || mkdir certs" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo '${tls_private_key.ca.private_key_pem}' > certs/${local.ca_dns_name}.key" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo '${tls_private_key.ca.public_key_pem}' > certs/${local.ca_dns_name}.public_key" | ||
| ## } | ||
| ## # get csr | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo '${tls_cert_request.ca.cert_request_pem}' > certs/${local.ca_dns_name}.csr" | ||
| ## } | ||
| ## | ||
| ## # detail how to get certs | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo 'add the key file to .gitignore, add it to git-secret, and hide it. Then add the .secret to git'" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo 'now submit file to TCO for signing and return the result as below:\n csr = certs/${local.ca_dns_name}.csr\n cert = certs/${local.ca_dns_name}.crt\n'" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo command = ./sign-subordinate-ca-cert.sh ${local.ca_dns_name}.csr 'c=US,o=U.S. Census Bureau,OU=PKI,ou=EKS,ou=${var.vpc_full_name},ou=${var.cluster_name},cn=${local.ca_dns_name}' 730" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## command = "echo 'curl -O http://ca.apps.tco.census.gov/certs/server?host=${local.ca_dns_name}&format=crt&download=1'" | ||
| ## } | ||
| ## } | ||
| ## | ||
| ## resource "null_resource" "ca_cert" { | ||
| ## count = local.ca_cert_download ? 1 : 0 | ||
| ## # get cert | ||
| ## provisioner "local-exec" { | ||
| ## command = "curl -o ${path.root}/certs/${local.ca_dns_name}.crt 'http://ca.apps.tco.census.gov/certs/server?host=${local.ca_dns_name}&format=crt&download=1'" | ||
| ## } | ||
| ## } | ||
| ## | ||
| ## resource "local_file" "ca_bundle_cert" { | ||
| ## count = local.ca_cert_download && local.ca_cert_exists && local.ca_root_exists && length(local.ca_bundle_contents) > 0 ? 1 : 0 | ||
| ## | ||
| ## content = local.ca_bundle_contents | ||
| ## filename = local.ca_bundle_filename | ||
| ## file_permission = "0644" | ||
| ## } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.