open-nomad/e2e/terraform/provisioning.tf
Tim Gross 2edbdfc8be
e2e: update framework to allow deploying Nomad (#6969)
The e2e framework instantiates clients for Nomad/Consul but the
provisioning of the actual Nomad cluster is left to Terraform. The
Terraform provisioning process uses `remote-exec` to deploy specific
versions of Nomad so that we don't have to bake an AMI every time we
want to test a new version. But Terraform treats the resulting
instances as immutable, so we can't use the same tooling to update the
version of Nomad in-place. This is a prerequisite for upgrade testing.

This changeset extends the e2e framework to provide the option of
deploying Nomad (and, in the future, Consul/Vault) with specific
versions to running infrastructure. This initial implementation is
focused on deploying to a single cluster via `ssh` (because that's our
current need), but provides interfaces to hook the test run at the
start of the run, the start of each suite, or the start of a given
test case.

Terraform work includes:
* provides Terraform output that written to JSON used by the framework
  to configure provisioning via `terraform output provisioning`.
* provides Terraform output that can be used by test operators to
  configure their shell via `$(terraform output environment)`
* drops `remote-exec` provisioning steps from Terraform
* makes changes to the deployment scripts to ensure they can be run
  multiple times w/ different versions against the same host.
2020-01-22 08:48:52 -05:00

94 lines
3.1 KiB
HCL

# outputs used for E2E testing and provisioning
output "environment" {
description = "get connection config by running: $(terraform output environment)"
value = <<EOM
export NOMAD_ADDR=http://${aws_instance.server[0].public_ip}:4646
export CONSUL_HTTP_ADDR=http://${aws_instance.server[0].public_ip}:8500
export NOMAD_E2E=1
EOM
}
output "provisioning" {
description = "output to a file to be use w/ E2E framework -provision.terraform"
value = jsonencode(
{
"servers" : [for server in aws_instance.server.* :
{
"runner" : {
"key" : abspath(module.keys.private_key_filepath),
"user" : "ubuntu",
"host" : "${server.public_ip}",
"port" : 22
},
"deployment" : {
"nomad_sha" : var.nomad_sha,
"platform" : "linux_amd64",
"remote_binary_path" : "/usr/local/bin/nomad",
"bundles" : [
{
"source" : abspath("./shared"),
"destination" : "/ops/shared"
}
],
"steps" : [
"sudo chmod +x /ops/shared/config/provision-server.sh",
"sudo /ops/shared/config/provision-server.sh aws ${var.server_count} 'indexed/server-${index(aws_instance.server, server)}.hcl'"
],
}
}
],
"clients" : concat([for client in aws_instance.client_linux.* :
{
"runner" : {
"key" : abspath(module.keys.private_key_filepath),
"user" : "ubuntu",
"host" : "${client.public_ip}",
"port" : 22
},
"deployment" : {
"nomad_sha" : var.nomad_sha,
"platform" : "linux_amd64",
"remote_binary_path" : "/usr/local/bin/nomad",
"bundles" : [
{
"source" : abspath("./shared"),
"destination" : "/ops/shared"
}
],
"steps" : [
"sudo chmod +x /ops/shared/config/provision-client.sh",
"sudo /ops/shared/config/provision-client.sh aws 'indexed/client-${index(aws_instance.client_linux, client)}.hcl'"
],
}
}
],
[for client in aws_instance.client_windows.* :
{
"runner" : {
"key" : abspath(module.keys.private_key_filepath),
"user" : "Administrator",
"host" : "${client.public_ip}",
"port" : 22
},
"deployment" : {
"nomad_sha" : var.nomad_sha,
"platform" : "windows_amd64",
# need to use the / here for golang filepath handling to work
# on the Unix test runner environment
"remote_binary_path" : "C:/opt/nomad.exe",
"bundles" : [
{
"source" : abspath("./shared"),
"destination" : "C:/ops/shared"
}
],
"steps" : [
"& C:\\ops\\shared\\config\\provision-windows-client.ps1 -Cloud aws -Index 1"
]
}
}
])
})
}