github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/e2e/terraform/nomad-acls.tf (about)

     1  # Bootstrapping Nomad ACLs:
     2  # We can't both bootstrap the ACLs and use the Nomad TF provider's
     3  # resource.nomad_acl_token in the same Terraform run, because there's no way
     4  # to get the management token into the provider's environment after we bootstrap.
     5  # So we run a bootstrapping script and write our management token into a file
     6  # that we read in for the output of $(terraform output environment) later.
     7  
     8  resource "null_resource" "bootstrap_nomad_acls" {
     9    depends_on = [module.nomad_server]
    10    triggers = {
    11      script = data.template_file.bootstrap_nomad_script.rendered
    12    }
    13  
    14    provisioner "local-exec" {
    15      command = data.template_file.bootstrap_nomad_script.rendered
    16    }
    17  }
    18  
    19  # write the bootstrap token to the keys/ directory (where the ssh key is)
    20  # so that we can read it into the data.local_file later. If not set,
    21  # ensure that it's empty.
    22  data "template_file" "bootstrap_nomad_script" {
    23    template = var.nomad_acls ? "NOMAD_ADDR=http://${aws_instance.server.0.public_ip}:4646 ./scripts/bootstrap-nomad.sh" : "mkdir -p ${path.root}/keys; echo > ${path.root}/keys/nomad_root_token"
    24  }
    25  
    26  data "local_file" "nomad_token" {
    27    depends_on = [null_resource.bootstrap_nomad_acls]
    28    filename   = "${path.root}/keys/nomad_root_token"
    29  }