Skip to content

CD Pipeline

CD Pipeline #1

Workflow file for this run

name: CD Pipeline
on:
workflow_dispatch:
jobs:
plan-infrastructure:
name: Terraform Plan AWS Infrastructure
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
- name: Initialize Terraform
run: terraform init -upgrade
- name: Terraform Plan
run: terraform plan -lock-timeout=600s -compact-warnings -out=plan.tfplan
- name: Save Terraform Plan as an artifact
uses: actions/upload-artifact@v2
with:
name: plan
path: plan.tfplan
apply-infrastructure:
name: Terraform Apply AWS Infrastructure (Manual)
runs-on: ubuntu-latest
needs: plan-infrastructure
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Download Terraform Plan
uses: actions/download-artifact@v2
with:
name: plan
- name: Set up Terraform
uses: hashicorp/setup-terraform@v1
- name: Wait for Manual Approval
uses: peter-evans/wait-for-approval@v2
with:
custom-message: "Please approve to apply the Terraform changes."
- name: Terraform Apply
id: terraform_apply
run: terraform apply "plan.tfplan"
- name: Get EC2 instance public IP
id: get_ip
run: echo "::set-output name=ec2_public_ip::$(terraform output -raw ec2_public_ip)"
deploy-stack:
name: Deploy Monitoring Stack with Ansible
runs-on: ubuntu-latest
needs: apply-infrastructure
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install Ansible
run: sudo apt-get install -y ansible
- name: Create Ansible inventory
run: |
echo "[gbfs]" > inventory.ini
echo "gbfs-instance ansible_host=${{ steps.get_ip.outputs.ec2_public_ip }} ansible_user=ec2-user ansible_ssh_private_key_file=${{ secrets.SSH_PRIVATE_KEY }} ansible_ssh_common_args='-o StrictHostKeyChecking=no'" >> inventory.ini
- name: Deploy GBFS Monitoring Stack
run: ansible-playbook infra/deployment/playbooks/gbfs.yaml -i inventory.ini
env:
ANSIBLE_HOST_KEY_CHECKING: false