Skip to content

Commit 2cfa73c

Browse files
committed
start with volume
1 parent 5545b71 commit 2cfa73c

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ jobs:
162162
| `server_type` | | Name of the Server type this Server should be created with. | `cx22` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
163163
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
164164
| `ssh_key` | | SSH key ID (integer) which should be injected into the Server at creation time. | `null` |
165+
| `volume` | | Volume ID which should be attached to the Server at the creation time. Volume must be in the same Location. | `null` |
165166

166167
## Outputs
167168

@@ -291,6 +292,20 @@ hcloud network list --output "columns=ID,NAME,IP_RANGE,SERVERS"
291292
hcloud ssh-key list --output "columns=ID,NAME"
292293
```
293294

295+
**List Volumes:**
296+
297+
```bash
298+
hcloud volume list --output "columns=ID,NAME,LOCATION"
299+
```
300+
301+
**Create Volume:**
302+
303+
To create a 10GB volume named `volume-test` in the Nuremberg DC Park 1 (`nbg1`) location, use the following command:
304+
305+
```bash
306+
hcloud volume create --name "volume-test" --size "10" --location "nbg1"
307+
```
308+
294309
## Security
295310

296311
> We recommend that you only use self-hosted runners with private repositories.

action.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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!"
227227
fi
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."
371379
fi
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".
373387
if [[ "$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."
377391
fi
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."
383397
fi
384398

385399
# Send a POST request to the Hetzner Cloud API to create a server.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ inputs:
112112
SSH key ID (integer) or name which should be injected into the Server at creation time.
113113
required: false
114114
default: 'null'
115+
volume:
116+
description: >-
117+
Volume ID (integer) which should be attached to the Server at the creation time.
118+
required: false
119+
default: 'null'
115120

116121
outputs:
117122
label:
@@ -154,3 +159,4 @@ runs:
154159
INPUT_SERVER_TYPE: ${{ inputs.server_type }}
155160
INPUT_SERVER_WAIT: ${{ inputs.server_wait }}
156161
INPUT_SSH_KEY: ${{ inputs.ssh_key }}
162+
INPUT_VOLUME: ${{ inputs.volume }}

create-server.template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
},
1818
"start_after_create": true,
1919
"ssh_keys": [],
20+
"volumes": [],
2021
"user_data": $cloud_init_yml,
2122
}

0 commit comments

Comments
 (0)