-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (80 loc) · 2.82 KB
/
hetzner_create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Hetzner Setup
run-name: Create hetzner infra
on: workflow_dispatch
env:
BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
terraform:
name: Create Hetzner Infra
runs-on: ubuntu-latest
steps:
- run: echo "Job is running on ${{ runner.os }}"
- run: echo "Branch name is ${{ github.ref }} and repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- name: HashiCorp - Setup Terraform
uses: hashicorp/[email protected]
- name: Terraform init
id: init
run: terraform init -backend-config="bucket=$BUCKET_TF_STATE"
working-directory: hetzner
- name: Terraform validate
id: validate
run: terraform validate
working-directory: hetzner
- name: Terraform plan
id: plan
run: terraform plan -no-color -input=false -var "hcloud_token=${{ secrets.HCLOUD_TOKEN }}" -var "tailscale_key=${{ secrets.TAILSCALE_KEY }}"
continue-on-error: true
working-directory: hetzner
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
run: terraform apply -auto-approve -input=false -var "hcloud_token=${{ secrets.HCLOUD_TOKEN }}" -var "tailscale_key=${{ secrets.TAILSCALE_KEY }}"
working-directory: hetzner
- name: Sleep for 2 minutes while server reboots
run: sleep 2m
shell: bash
- run: echo "Job is ${{ job.status }}."
ansible:
name: Setup Nomad & Consul
needs: terraform
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y ansible
python -m pip install --upgrade pip
- name: Tailscale
uses: tailscale/github-action@v1
with:
authkey: ${{ secrets.TAILSCALE_EPHEMERAL_KEY }}
- name: Check out repository code
uses: actions/checkout@v3
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/server.key
chmod 600 ~/.ssh/server.key
cat >>~/.ssh/config <<END
Host axion-1
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/server.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
- name: Run Ansible Playbook
run: |
ansible-playbook ansible/setup-server.yml -i ansible/inventory.ini