2020-09-28 13:22:36 +00:00
|
|
|
# Bootstrapping Nomad ACLs:
|
|
|
|
# We can't both bootstrap the ACLs and use the Nomad TF provider's
|
|
|
|
# resource.nomad_acl_token in the same Terraform run, because there's no way
|
|
|
|
# to get the management token into the provider's environment after we bootstrap.
|
|
|
|
# So we run a bootstrapping script and write our management token into a file
|
|
|
|
# that we read in for the output of $(terraform output environment) later.
|
|
|
|
|
2021-09-16 15:15:41 +00:00
|
|
|
locals {
|
2022-03-18 13:27:28 +00:00
|
|
|
nomad_env = "NOMAD_ADDR=https://${aws_instance.server.0.public_ip}:4646 NOMAD_CACERT=keys/tls_ca.crt NOMAD_CLIENT_CERT=keys/tls_api_client.crt NOMAD_CLIENT_KEY=keys/tls_api_client.key"
|
2021-09-16 15:15:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 13:22:36 +00:00
|
|
|
resource "null_resource" "bootstrap_nomad_acls" {
|
|
|
|
depends_on = [module.nomad_server]
|
|
|
|
triggers = {
|
2020-10-05 13:28:37 +00:00
|
|
|
script = data.template_file.bootstrap_nomad_script.rendered
|
2020-09-28 13:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "local-exec" {
|
2020-10-05 13:28:37 +00:00
|
|
|
command = data.template_file.bootstrap_nomad_script.rendered
|
2020-09-28 13:22:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# write the bootstrap token to the keys/ directory (where the ssh key is)
|
|
|
|
# so that we can read it into the data.local_file later. If not set,
|
|
|
|
# ensure that it's empty.
|
2020-10-05 13:28:37 +00:00
|
|
|
data "template_file" "bootstrap_nomad_script" {
|
2022-03-18 13:27:28 +00:00
|
|
|
template = "${local.nomad_env} ./scripts/bootstrap-nomad.sh"
|
2020-09-28 13:22:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data "local_file" "nomad_token" {
|
|
|
|
depends_on = [null_resource.bootstrap_nomad_acls]
|
|
|
|
filename = "${path.root}/keys/nomad_root_token"
|
|
|
|
}
|