-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (65 loc) · 2.33 KB
/
main.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
name: CREATE_ENV
on:
workflow_dispatch:
inputs:
action:
type: choice
description: 'Choose what you want to do'
options:
- deploy
- destroy
env:
ssh_public_key: ${{ vars.SSH_PUB_KEY }}
ANSIBLE_HOST_KEY_CHECKING: False
jobs:
provision-and-configure:
runs-on: ubuntu-22.04
env:
TF_VAR_subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.SUBSCRIPTION_ID }}
TF_VAR_client_id: ${{ secrets.CLIENT_ID }}
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
TF_VAR_client_secret: ${{ secrets.CLIENT_SECRET }}
ARM_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
TF_VAR_tenant_id: ${{ secrets.TENANT_ID }}
ARM_TENANT_ID: ${{ secrets.TENANT_ID }}
TF_VAR_ssh_public_key: ${{ github.workspace }}/id_rsa.pub
steps:
- uses: actions/checkout@v4
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.PRIVATE_SSH_KEY }}
- name: Create ssh pub/priv key from variable
run: echo "$ssh_public_key" > ${{ github.workspace }}/id_rsa.pub
- name: Run terraform init
run: terraform -chdir=terraform init
- if: github.event.inputs.action == 'deploy'
name: Run terraform apply
run: terraform -chdir=terraform apply --auto-approve
- if: github.event.inputs.action == 'deploy'
name: Run ansible configuration
run: |
VM_IP=$(terraform -chdir=terraform output -raw hylastix_vm_public_ip)
cat > ansible/inventory.yml << EOF
consul_server:
hosts:
hylvm:
ansible_host: $VM_IP
ansible_user: adminuser
consul_server: true
duck_dns_token: ${{ secrets.DUCK_DNS_TOKEN }}
letsencrypt_email: ${{ secrets.LETSENCRYPT_EMAIL }}
kc_client_secret: ${{ secrets.KC_CLIENT_SECRET }}
EOF
cat > ansible/playbook.yml << EOF
- name: Install Consul and Nomad
hosts:
- all
roles:
- consul
- nomad
EOF
ansible-playbook -i ansible/inventory.yml ansible/playbook.yml
- if: github.event.inputs.action == 'destroy'
name: Run terraform destroy
run: terraform -chdir=terraform destroy --auto-approve