From da74d8c54967bbae50fc8b7002c89fe56f46adab Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 12 Jan 2021 11:55:41 -0500 Subject: [PATCH] move config files to terraform --- .../packer/ubuntu-bionic-amd64.pkr.hcl | 5 --- .../packer/ubuntu-bionic-amd64/setup.sh | 1 - .../packer/windows-2016-amd64.pkr.hcl | 5 --- e2e/terraform/provision-nomad/main.tf | 32 +++++++++---------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/e2e/terraform/packer/ubuntu-bionic-amd64.pkr.hcl b/e2e/terraform/packer/ubuntu-bionic-amd64.pkr.hcl index 3712b8206..790c359f6 100644 --- a/e2e/terraform/packer/ubuntu-bionic-amd64.pkr.hcl +++ b/e2e/terraform/packer/ubuntu-bionic-amd64.pkr.hcl @@ -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" { diff --git a/e2e/terraform/packer/ubuntu-bionic-amd64/setup.sh b/e2e/terraform/packer/ubuntu-bionic-amd64/setup.sh index a20ba5a88..f1157001d 100755 --- a/e2e/terraform/packer/ubuntu-bionic-amd64/setup.sh +++ b/e2e/terraform/packer/ubuntu-bionic-amd64/setup.sh @@ -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 diff --git a/e2e/terraform/packer/windows-2016-amd64.pkr.hcl b/e2e/terraform/packer/windows-2016-amd64.pkr.hcl index 942a9d1e6..e9e66126d 100644 --- a/e2e/terraform/packer/windows-2016-amd64.pkr.hcl +++ b/e2e/terraform/packer/windows-2016-amd64.pkr.hcl @@ -37,11 +37,6 @@ build { ] } - provisioner "file" { - destination = "/opt" - source = "../config" - } - provisioner "file" { destination = "/opt/provision.ps1" source = "./windows-2016-amd64/provision.ps1" diff --git a/e2e/terraform/provision-nomad/main.tf b/e2e/terraform/provision-nomad/main.tf index a53a124fb..0bb9dae78 100644 --- a/e2e/terraform/provision-nomad/main.tf +++ b/e2e/terraform/provision-nomad/main.tf @@ -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" + } + }