Skip to content

chore: Added terraform cd pipeline #2

chore: Added terraform cd pipeline

chore: Added terraform cd pipeline #2

name: 'Terraform Apply'
on:
push:
branches:
- main
env:
TF_CLOUD_ORGANIZATION: "${{ secrets.TERRAFORM_ORGANISATION }}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "${{ secrets.TF_WORKSPACE }}"
CONFIG_DIRECTORY: "./infrastructure"
jobs:
docker-build:
uses: ./.github/workflows/docker.yml
secrets:
DOCKERHUB_USERNAME: "${{ secrets.DOCKERHUB_USERNAME }}"
DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}"
terraform:
name: "Terraform Apply"
needs: [ docker-build ]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply-upload
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.CONFIG_DIRECTORY }}
- name: Create Apply Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply-run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }}
- name: Wait for Manual Approval
run: |
echo "Terraform apply requires manual approval in Terraform Cloud."
echo "Go to Terraform Cloud UI to approve the apply: ${{ steps.apply-run.outputs.run_link }}"