From 4b53c40bfb6cdf1c0b1fbe2c730ceaa51aa07c2b Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Fri, 3 May 2024 11:05:22 -0500
Subject: [PATCH] re-using  code to attach volumes

---
 ohpc-instance/main.tf | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/ohpc-instance/main.tf b/ohpc-instance/main.tf
index c6e428d..f7825e8 100644
--- a/ohpc-instance/main.tf
+++ b/ohpc-instance/main.tf
@@ -9,7 +9,6 @@ required_version = ">= 0.14.0"
   }
 }
 
-
 variable "ohpc_instance_name" {}
 variable "image_ohpc" {}
 variable "flavor" {}
@@ -76,16 +75,13 @@ resource "openstack_compute_floatingip_associate_v2" "ohpc" {
   instance_id = openstack_compute_instance_v2.ohpc.id
 }
 
-# Attach specific volumes
-resource "openstack_compute_volume_attach_v2" "attach_prod_volume" {
+# Attach volumes
+resource "openstack_compute_volume_attach_v2" "volume_attach" {
+  count       = length(var.vol_ids)
   instance_id = openstack_compute_instance_v2.ohpc.id
-  volume_id   = var.data_volume
+  volume_id   = var.vol_ids[count.index]
 }
 
-resource "openstack_compute_volume_attach_v2" "attach_prod_queue_volume" {
-  instance_id = openstack_compute_instance_v2.ohpc.id
-  volume_id   = var.prod_volume_id
-}
 output "xdmod_instance_id" {
   value = openstack_compute_instance_v2.ohpc.id
 }
@@ -96,7 +92,8 @@ output "ssh_host" {
 
 output "device" {
   value = [
-    openstack_compute_volume_attach_v2.attach_prod_volume.device,
-    openstack_compute_volume_attach_v2.attach_prod_queue_volume.device
+    openstack_compute_volume_attach_v2.volume_attach[0].device,
+    openstack_compute_volume_attach_v2.volume_attach[1].device,
   ]
 }
+
-- 
GitLab