Skip to content

Commit 14ffb7c

Browse files
committed
tf: Run setup.sh using remote-exec provisioner instead of userdata
This way we avoid a race condition where remote-exec is run before setup.sh has finished running. This can happen because the provisioners are blocked until the provision is complete, but userdata scripts run after the provisions have been marked complete. So depending on how long it takes to create and push the compose.tar.gz tarball we can be trying to execute docker-compose commands before the files have been extracted. This also has the added benefit that output from the execution of setup.sh is visible when running terraform apply. Signed-off-by: Manuel Mendez <[email protected]>
1 parent 7723c26 commit 14ffb7c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

deploy/terraform/main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ resource "metal_device" "tink_provisioner" {
6262
operating_system = "ubuntu_20_04"
6363
billing_cycle = "hourly"
6464
project_id = var.project_id
65-
user_data = file("setup.sh")
6665
}
6766

6867
resource "metal_device_network_type" "tink_provisioner_network_type" {
@@ -99,12 +98,22 @@ resource "null_resource" "setup" {
9998
destination = "/root/compose.tar.gz"
10099
}
101100

101+
provisioner "file" {
102+
source = "setup.sh"
103+
destination = "/tmp/setup.sh"
104+
}
105+
102106
provisioner "remote-exec" {
103107
inline = [
108+
"echo '===== running setup.sh ====='",
109+
"chmod +x /tmp/setup.sh && /tmp/setup.sh",
110+
"echo '===== extracting compose tarball ====='",
104111
"tar -vxz -f /root/compose.tar.gz -C /root/sandbox",
112+
"echo '===== setting up docker-compose .env overrides ====='",
105113
"echo TINKERBELL_CLIENT_MAC=${local.worker_macs[0]} >>/root/sandbox/compose/.env",
106114
"echo TINKERBELL_TEMPLATE_MANIFEST=/manifests/template/ubuntu-equinix-metal.yaml >>/root/sandbox/compose/.env",
107115
"echo TINKERBELL_HARDWARE_MANIFEST=/manifests/hardware/hardware-equinix-metal.json >>/root/sandbox/compose/.env",
116+
"echo '===== bringing up docker-compose stack ====='",
108117
"docker-compose -f /root/sandbox/compose/docker-compose.yml up -d"
109118
]
110119
}

0 commit comments

Comments
 (0)