From 8d99403b2f63ba32d8d669e42f19898683c49f3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz>
Date: Sat, 23 Oct 2021 15:00:12 +0200
Subject: [PATCH] gitLab CI: init terraform before allocating IP

---
 .gitlab-ci.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 40d7b19..e03db1d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -42,6 +42,8 @@ test-single:
     - printf 'terraform {\n  backend "http" {\n  }\n}\n' > gitlab.tf
     # https://github.com/terraform-provider-openstack/terraform-provider-openstack/issues/1160
     - touch ./secure.yml
+    # better to init terraform before allocating public floating IP address (the state could be locked)
+    - terraform init -input=false
     - ip=`openstack floating ip create -c floating_ip_address -f value public-muni-147-251-21-GROUP`
   after_script: &after
     - openstack floating ip delete $ip
@@ -51,7 +53,6 @@ test-single:
     paths:
       - ".terraform/"
   script:
-    - terraform init -input=false
     - args="-auto-approve -var type=hadoop-single -var flavor=standard.large -var n=0 -var domain=terra1 -var image_name=$IMAGE_NAME -var image_visibility=$IMAGE_VISIBILITY -var floating_ip=$ip"
     - terraform apply $args
     - eval $(ssh-agent -s)
@@ -75,7 +76,6 @@ test-cluster:
     paths:
       - ".terraform/"
   script:
-    - terraform init -input=false
     - args="-auto-approve -var type=hadoop -var domain=terra2 -var image_name=$IMAGE_NAME -var image_visibility=$IMAGE_VISIBILITY -var floating_ip=$ip"
     - terraform apply $args
     - eval $(ssh-agent -s)
-- 
GitLab