Skip to content

Commit 8991abc

Browse files
committed
fixed create bastion to allow for non active bastions and to ignore
terminated VM's
1 parent 97ada55 commit 8991abc

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

IoTSonnenUploader/OCISetup/CreateBastionSession.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ echo "Using OCI config profile $OCI_CLI_PROFILE"
77
IOT_COMPARTMENT_OCID=`get_oci_compartment_ocid.sh $COMPARTMENT_PATH`
88

99

10-
BASTION_OCID=`oci bastion bastion list --compartment-id "$IOT_COMPARTMENT_OCID" --name "$BASTION_NAME" --all --query "data[0].id" --raw-output`
11-
12-
10+
BASTION_OCID=`oci bastion bastion list --compartment-id "$IOT_COMPARTMENT_OCID" --name "$BASTION_NAME" --all | jq -r '.data[]| select (."lifecycle-state" == "ACTIVE") | ."id"'`
11+
if [ -z "$BASTION_OCID" ] ; then
12+
echo "Error: Could not find Bastion $BASTION_NAME."
13+
exit 1
14+
fi
1315
echo "Bastion $BASTION_NAME in compartment $IOT_COMPARTMENT_OCID has $BASTION_OCID ocid"
14-
# Retrieve Target Instance OCID by Name
15-
VM_OCID=`oci compute instance list --compartment-id "$IOT_COMPARTMENT_OCID" --display-name "$VM_NAME" --query "data[0].id" --raw-output`
16+
# Retrieve Target Instance OCID by Name select(.lifecycleState | IN("STOPPED", "RUNNING", "STARTING", "STOPPING"))
17+
#VM_OCID=`oci compute instance list --compartment-id "$IOT_COMPARTMENT_OCID" --display-name "$VM_NAME" --query "data[0].id" --raw-output`
18+
VM_OCID=`oci compute instance list --compartment-id "$IOT_COMPARTMENT_OCID" --display-name "$VM_NAME" --all | jq -r '.data[]| select (."lifecycle-state" | IN("STOPPED", "RUNNING", "STARTING", "STOPPING")) | ."id"'`
1619

1720
echo "Compute instance $VM_NAME in compartment $IOT_COMPARTMENT_OCID has $VM_OCID ocid"
1821

19-
if [ -z "$BASTION_OCID" ] || [ -z "$VM_OCID" ]; then
20-
echo "Error: Could not find Bastion or Target Instance."
22+
if [ -z "$VM_OCID" ]; then
23+
echo "Error: Could not find Target Instance."
2124
exit 1
2225
fi
2326

0 commit comments

Comments
 (0)