Skip to content

Commit

Permalink
Allow to set for location, which is also the default now.
Browse files Browse the repository at this point in the history
  • Loading branch information
stonemaster committed Jun 24, 2024
1 parent 7131800 commit c35460d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ inputs:
description: 'Name of Hetzner instance type to be created e.g. cx11. See https://docs.hetzner.cloud/#server-types-get-all-server-types'
required: true
hetzner-location:
description: 'Location ID where cloud instance should be created'
default: 'fsn1'
description: 'Location ID where cloud instance should be created. In case of `auto` the Hetzner API will decide'
default: 'auto'
hetzner-ssh-key-id:
description: If set deploys this SSH key ID to the server for debugging purposes
required: false
Expand Down
9 changes: 7 additions & 2 deletions create-hetzner-instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ssh_key_id=${6:-}
template_file=$(dirname $0)/hetzner-server-create-template.jq

temp_json=$(mktemp)
jq -n --arg location ${location} \
jq -n \
--arg server_type ${instance_type} \
--arg name "$name_prefix-$RANDOM" \
--rawfile cloud_init_yml $cloud_init_yml_file \
Expand All @@ -29,11 +29,16 @@ if [ "$ssh_key_id" != "" ]; then
mv $temp_json2 $temp_json
fi

if [ "$location" != "auto" ]; then
temp_json2=$(mktemp)
cat $temp_json | jq ".location = \"$location\"" > $temp_json2
mv $temp_json2 $temp_json
fi

curl \
-X POST \
--fail-with-body \
-H "Authorization: Bearer ${hetzner_api_key}" \
-H "Content-Type: application/json" \
-d @$temp_json \
'https://api.hetzner.cloud/v1/servers'

1 change: 0 additions & 1 deletion hetzner-server-create-template.jq
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
image: "ubuntu-22.04",
location: $location,
server_type: $server_type,
name: $name,
public_net: {
Expand Down

0 comments on commit c35460d

Please sign in to comment.