-
Notifications
You must be signed in to change notification settings - Fork 0
/
createHetznerServer.bash
20 lines (17 loc) · 944 Bytes
/
createHetznerServer.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
name=${name:-test}
location=${location:-nbg1}
type=${type:-cax11}
sshKey=${sshKey:-vps}
ubuntuVersion=${ubuntuVersion:-22.04}
if [[ -z "$hetznerToken" ]]; then
echo "Please set hetznerToken"
exit 1
fi
cloudConfig=$(<cloudconfig.yml)
cloudConfig=$(sed -z 's/\\/\\\\/g' <<<"$cloudConfig")
cloudConfig=$(sed -z 's/\"/\\\"/g' <<<"$cloudConfig")
cloudConfig=$(sed -z 's/\n/\\n/g' <<<"$cloudConfig")
json="{\"automount\":false,\"image\":\"ubuntu-$ubuntuVersion\",\"location\":\"$location\",\"name\":\"$name\",\"server_type\":\"$type\",\"ssh_keys\":[\"$sshKey\"],\"start_after_create\":true,\"user_data\":\"$cloudConfig\"}"
curl -X POST -H "Authorization: Bearer $hetznerToken" -H "Content-Type: application/json" -d "$json" 'https://api.hetzner.cloud/v1/servers'
# curl -H "Authorization: Bearer $hetznerToken" 'https://api.hetzner.cloud/v1/ssh_keys'
# curl -H "Authorization: Bearer $hetznerToken" 'https://api.hetzner.cloud/v1/floating_ips'