@@ -226,6 +226,14 @@ if [[ "$MY_SSH_KEY" != "null" && ! "$MY_SSH_KEY" =~ ^[0-9]+$ ]]; then
226226 exit_with_failure " The SSH key ID must be 'null' or an integer!"
227227fi
228228
229+ # Set the volume ID which should be attached to the instance at the creation time (default: null)
230+ # If INPUT_VOLUME is set, use its value; otherwise, use "null".
231+ MY_VOLUME=${INPUT_VOLUME:- " null" }
232+ # Check if MY_VOLUME is an integer
233+ if [[ " $MY_VOLUME " != " null" && ! " $MY_VOLUME " =~ ^[0-9]+$ ]]; then
234+ exit_with_failure " The volume ID must be 'null' or an integer!"
235+ fi
236+
229237#
230238# DELETE
231239#
@@ -369,17 +377,23 @@ if [[ "$MY_PRIMARY_IPV6" != "null" ]]; then
369377 jq " .public_net.ipv6 = $MY_PRIMARY_IPV6 " < create-server-ipv6.json > create-server.json && \
370378 echo " Primary IPv6 ID added to create-server.json."
371379fi
380+ # Add network configuration to the create-server.json file if MY_NETWORK is not "null".
381+ if [[ " $MY_NETWORK " != " null" ]]; then
382+ cp create-server.json create-server-network.json && \
383+ jq " .networks += [$MY_NETWORK ]" < create-server-network.json > create-server.json && \
384+ echo " Network added to create-server.json."
385+ fi
372386# Add SSH key configuration to the create-server.json file if MY_SSH_KEY is not "null".
373387if [[ " $MY_SSH_KEY " != " null" ]]; then
374388 cp create-server.json create-server-ssh.json && \
375389 jq " .ssh_keys += [$MY_SSH_KEY ]" < create-server-ssh.json > create-server.json && \
376390 echo " SSH key added to create-server.json."
377391fi
378- # Add network configuration to the create-server.json file if MY_NETWORK is not "null".
379- if [[ " $MY_NETWORK " != " null" ]]; then
380- cp create-server.json create-server-network .json && \
381- jq " .networks += [$MY_NETWORK ]" < create-server-network .json > create-server.json && \
382- echo " Network added to create-server.json."
392+ # Add volume configuration to the create-server.json file if MY_VOLUME is not "null".
393+ if [[ " $MY_VOLUME " != " null" ]]; then
394+ cp create-server.json create-server-volume .json && \
395+ jq " .volumes += [$MY_VOLUME ]" < create-server-volume .json > create-server.json && \
396+ echo " Volume added to create-server.json."
383397fi
384398
385399# Send a POST request to the Hetzner Cloud API to create a server.
0 commit comments