CREATE_ENV #39
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |