From d04ff7c526dca2ed14655f1d450eeeceda1ae316 Mon Sep 17 00:00:00 2001 From: Ravi Tripathi <ravi89@uab.edu> Date: Fri, 25 Aug 2023 16:19:20 -0500 Subject: [PATCH] Add job for floating ip swap in staging env --- .gitlab-ci.yml | 33 +++++++++++++++++++++++++++++++++ main.tf | 6 +++++- ohpc-instance/main.tf | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9a15fb7..10946bb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,6 +95,39 @@ tf-apply: TF_SUCCESS=true fi echo "Terraform success: $TF_SUCCESS" + - export instance_floating_ip=$(terraform output -raw floating_ip_ohpc) + - export instance_id=$(terraform output -raw xdmod_instance_id) + - echo "instance_floating_ip=${instance_floating_ip}" | tee -a $CI_PROJECT_DIR/vars.env + - echo "instance_id=${instance_id}" | tee -a $CI_PROJECT_DIR/vars.env + artifacts: + reports: + dotenv: vars.env + + +staging-post-deploy: + environment: + name: staging + stage: build + tags: [build] + script: + - export staging_floating_ip="138.26.49.15" + - export old_instance_id=$(openstack floating ip show $staging_floating_ip -c port_details -f value | awk -F', ' '{print $2}' | awk -F"'" '{print $2}') + - echo "staging_floating_ip=${staging_floating_ip}" + - echo "old_instance_id=${old_instance_id}" + - | + if [[ -n "$old_instance_id" ]]; then + openstack server remove floating ip $old_instance_id $staging_floating_ip + openstack server delete $old_instance_id + fi + - openstack server remove floating ip $instance_id $instance_floating_ip + - openstack server add floating ip $instance_id $staging_floating_ip + - openstack floating ip delete $instance_floating_ip + needs: + - job: tf-apply + artifacts: true + rules: + - if: '$TARGET_ENV == "staging"' + clean-up: stage: cleanup diff --git a/main.tf b/main.tf index d70429e..072b231 100644 --- a/main.tf +++ b/main.tf @@ -108,6 +108,10 @@ output "ohpc-ssh_host" { value = module.create-ohpc-instance.ssh_host } +output "xdmod_instance_id" { + value = module.create-ohpc-instance.xdmod_instance_id +} + # calls the outputs defined in the ood-instance module #output "ood-ssh_host" { # value = module.create-ood-instance.ssh_host @@ -118,7 +122,7 @@ output "ohpc-ssh_host" { # that lead to inconsistent deploy successes. resource "null_resource" "ops" { triggers = { - ohpc_instance = module.create-ohpc-instance.id + ohpc_instance = module.create-ohpc-instance.xdmod_instance_id compute_instances = join(",", module.nodes.id) } diff --git a/ohpc-instance/main.tf b/ohpc-instance/main.tf index b2ea0f1..f968629 100644 --- a/ohpc-instance/main.tf +++ b/ohpc-instance/main.tf @@ -67,7 +67,7 @@ resource "openstack_compute_volume_attach_v2" "volume_attach" { volume_id = var.vol_id } -output "id" { +output "xdmod_instance_id" { value = openstack_compute_instance_v2.ohpc.id } -- GitLab