From bc1ba942c028f38c5b3b0ec699d46295c60bf9fe Mon Sep 17 00:00:00 2001 From: ENIX NOC Date: Sat, 11 Mar 2023 18:27:41 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Retry=20'terraform=20apply'=203?= =?UTF-8?q?=20times=20if=20it=20fails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some platforms (looking at you OpenStack) can exhibit random transient failures. This helps to work around them. --- prepare-vms/lib/infra/terraform.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/prepare-vms/lib/infra/terraform.sh b/prepare-vms/lib/infra/terraform.sh index 7ccbe904..93cc8667 100644 --- a/prepare-vms/lib/infra/terraform.sh +++ b/prepare-vms/lib/infra/terraform.sh @@ -34,8 +34,15 @@ infra_start() { fi echo prefix = \"$TAG\" >> terraform.tfvars echo how_many_nodes = \"$COUNT\" >> terraform.tfvars - terraform apply -auto-approve - terraform output -raw ip_addresses > ips.txt + for RETRY in 1 2 3; do + if terraform apply -auto-approve; then + terraform output -raw ip_addresses > ips.txt + break + fi + done + if ! [ -f ips.txt ]; then + die "Terraform failed." + fi ) }