move config files to terraform
This commit is contained in:
parent
661f7df7be
commit
0af1509a77
|
@ -36,11 +36,6 @@ build {
|
|||
source = "./ubuntu-bionic-amd64"
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
destination = "/tmp/config"
|
||||
source = "../config"
|
||||
}
|
||||
|
||||
// cloud-init modifies the apt sources, so we need to wait
|
||||
// before running our setup
|
||||
provisioner "shell-local" {
|
||||
|
|
|
@ -77,7 +77,6 @@ mkdir_for_root $NOMAD_PLUGIN_DIR
|
|||
sudo mv /tmp/linux/nomad.service /etc/systemd/system/nomad.service
|
||||
|
||||
echo "Install Nomad"
|
||||
sudo mv /tmp/config /opt/
|
||||
sudo mv /tmp/linux/provision.sh /opt/provision.sh
|
||||
sudo chmod +x /opt/provision.sh
|
||||
/opt/provision.sh --nomad_version $NOMADVERSION --nostart
|
||||
|
|
|
@ -37,11 +37,6 @@ build {
|
|||
]
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
destination = "/opt"
|
||||
source = "../config"
|
||||
}
|
||||
|
||||
provisioner "file" {
|
||||
destination = "/opt/provision.ps1"
|
||||
source = "./windows-2016-amd64/provision.ps1"
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
locals {
|
||||
provision_script = var.platform == "windows_amd64" ? "C:/opt/provision.ps1" : "/opt/provision.sh"
|
||||
|
||||
custom_path = dirname("${path.root}/config/custom/")
|
||||
config_path = dirname("${path.root}/config/")
|
||||
|
||||
custom_config_files = compact(setunion(
|
||||
fileset(local.custom_path, "nomad/*.hcl"),
|
||||
fileset(local.custom_path, "nomad/${var.role}/*.hcl"),
|
||||
fileset(local.custom_path, "nomad/${var.role}/indexed/*${var.index}.hcl"),
|
||||
fileset(local.custom_path, "consul/*.json"),
|
||||
fileset(local.custom_path, "consul/${var.role}/*.json"),
|
||||
fileset(local.custom_path, "consul${var.role}indexed/*${var.index}*.json"),
|
||||
fileset(local.custom_path, "vault/*.hcl"),
|
||||
fileset(local.custom_path, "vault${var.role}*.hcl"),
|
||||
fileset(local.custom_path, "vault${var.role}indexed/*${var.index}.hcl"),
|
||||
config_files = compact(setunion(
|
||||
fileset(local.config_path, "**"),
|
||||
))
|
||||
|
||||
update_config_command = var.platform == "windows_amd64" ? "if (test-path /opt/config) { Remove-Item -Path /opt/config -Force -Recurse }; cp -r /tmp/config /opt/config" : "sudo rm -rf /opt/config; sudo mv /tmp/config /opt/config"
|
||||
|
||||
# abstract-away platform-specific parameter expectations
|
||||
_arg = var.platform == "windows_amd64" ? "-" : "--"
|
||||
}
|
||||
|
@ -22,7 +16,7 @@ locals {
|
|||
resource "null_resource" "provision_nomad" {
|
||||
|
||||
depends_on = [
|
||||
null_resource.upload_custom_configs,
|
||||
null_resource.upload_configs,
|
||||
null_resource.upload_nomad_binary
|
||||
]
|
||||
|
||||
|
@ -85,7 +79,7 @@ data "template_file" "arg_index" {
|
|||
resource "null_resource" "upload_nomad_binary" {
|
||||
|
||||
count = var.nomad_local_binary != "" ? 1 : 0
|
||||
depends_on = [null_resource.upload_custom_configs]
|
||||
depends_on = [null_resource.upload_configs]
|
||||
triggers = {
|
||||
nomad_binary_sha = filemd5(var.nomad_local_binary)
|
||||
}
|
||||
|
@ -105,11 +99,10 @@ resource "null_resource" "upload_nomad_binary" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "null_resource" "upload_custom_configs" {
|
||||
resource "null_resource" "upload_configs" {
|
||||
|
||||
count = var.profile == "custom" ? 1 : 0
|
||||
triggers = {
|
||||
hashes = join(",", [for file in local.custom_config_files : filemd5("${local.custom_path}/${file}")])
|
||||
hashes = join(",", [for file in local.config_files : filemd5("${local.config_path}/${file}")])
|
||||
}
|
||||
|
||||
connection {
|
||||
|
@ -122,7 +115,12 @@ resource "null_resource" "upload_custom_configs" {
|
|||
}
|
||||
|
||||
provisioner "file" {
|
||||
source = local.custom_path
|
||||
source = local.config_path
|
||||
destination = "/tmp/"
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "until ssh -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${var.connection.private_key} -p ${var.connection.port} ${var.connection.user}@${var.connection.host} '${local.update_config_command}'; do sleep 5; done"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue