- Save state in Gitlab?
Set up silly alias, to this really quickly and easy
tee -a ~/.bash_aliases <<EOF
alias htz_up="terraform -chdir=/home/rihards/Code/cloud_project/cloud_project_terraform_hetzner/ apply -target=hcloud_server.htz1 -auto-approve"
alias htz_down="terraform -chdir=/home/rihards/Code/cloud_project/cloud_project_terraform_hetzner/ destroy -target=hcloud_server.htz1 -auto-approve"
alias htz_ssh="ssh rudenspavasaris.id.lv -o StrictHostKeyChecking=no -o 'UserKnownHostsFile=/dev/null'"
alias htz_ansible="ansible-playbook -i $(terraform -chdir=/home/rihards/Code/cloud_project/cloud_project_terraform_hetzner/ output -raw ip), \
-e node_ip_address=$(terraform -chdir=/home/rihards/Code/cloud_project/cloud_project_terraform_hetzner/ output -raw ip) \
-u rihards --diff -e ansible_python_interpreter=/usr/bin/python3 -e ansible_port=22 \
/home/rihards/Code/cloud_project/cloud_project_ansible/htz1.yml"
EOF
Create token in Hetzner Cloud -> Security -> Tokens
Create terraform.tfvars
file with the Hetzner token. Like this:
hcloud_token = "TOKEN_GOES_HERE"
Run terraform init -upgrade
to get latest provider version that takes the correct server sizes
Create dependencies - firewall and ssh key, as I'm going to do as one shouldn't: using targets. Eh
terraform -chdir=/home/rihards/Code/cloud_project/cloud_project_terraform_hetzner/ apply -target=hcloud_ssh_key.hetzner_key -target=hcloud_firewall.firewall -auto-approve
Provision with ansible manually, when something fails
SERVER_IP=rudenspavasaris.id.lv
export ANSIBLE_HOST_KEY_CHECKING=False && export ANSIBLE_SSH_RETRIES=5 && \
ansible-playbook -i ${SERVER_IP}, \
-e node_ip_address=${SERVER_IP} \
--diff -e ansible_python_interpreter=/usr/bin/python3 -e ansible_port=22 \
/home/rihards/Code/cloud_project/cloud_project_ansible/htz1.yml
Needed to update the provider, as I hadn't ran this is in a long time.
terraform state replace-provider registry.terraform.io/-/hcloud hetznercloud/hcloud
Needed to also add the terraform
required_providers
block.
cd ~/Code/cloud_project/cloud_project_terraform_hetzner
terraform apply -target=hcloud_firewall.firewall
terraform apply -target=hcloud_server.node1
cd ~/Code/cloud_project/cloud_project_terraform_hetzner
terraform apply -target=hcloud_server_network.htz2_srv_net -target=hcloud_server.htz2
terraform destroy -target=hcloud_server.htz2 -target=hcloud_server_network.htz2_srv_net
cd ~/Code/cloud_project/cloud_project_terraform_hetzner terraform apply -auto-approve -target=hcloud_server.minecraft
cd ~/Code/cloud_project/cloud_project_terraform_hetzner terraform destroy -auto-approve -target=hcloud_server.minecraft
curl
-H "Authorization: Bearer $API_TOKEN"
'https://api.hetzner.cloud/v1/images'
First get IDs via API. Reference:
https://docs.hetzner.cloud/
curl -H "Authorization: Bearer $(cat terraform.tfvars | grep -oP '"\K[^"]+')" \
"https://api.hetzner.cloud/v1/firewalls"
curl -H "Authorization: Bearer $(cat terraform.tfvars | grep -oP '"\K[^"]+')" \
"https://api.hetzner.cloud/v1/ssh_keys"
terraform import hcloud_firewall.firewall 1238619
terraform import hcloud_ssh_key.hetzner_key 19311507