diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9a15fb778fbe3a2408a3b103a0b31ff8947bbb9b..10946bbfce12da47d478c2ab9a9015bb78e8b08f 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 d70429e1cc58a05406be46939d72590efb06b920..072b2315c29d2d1bbbec3eaa225f16ba56ff6c74 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 b2ea0f1d02990238b2e9c919af0c1dae15823c52..f9686296cefca24b84a3e31793768d8f62ed2f5a 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 }