Merge pull request #5 from cristian-rincon/support/documentation #10
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: CD | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
GCP_REGION: ${{ secrets.GCP_REGION }} | |
GCP_ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | |
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }} | |
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/credentials.json | |
jobs: | |
apply: | |
name: Apply Terraform | |
runs-on: ubuntu-latest | |
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
terraform_version: 1.8.1 | |
- name: Set up gcloud Cloud SDK environment | |
uses: google-github-actions/setup-gcloud@v2.1.1 | |
- name: Authenticate to GCP | |
run: | | |
echo "${GCP_CREDENTIALS_JSON}" > ${{ github.workspace }}/credentials.json | |
gcloud auth activate-service-account --key-file=${{ github.workspace }}/credentials.json | |
gcloud config set project ${{ env.GCP_PROJECT_ID }} | |
- name: Terraform Init | |
run: terraform init | |
working-directory: ./infra | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -out=tfplan | |
working-directory: ./infra | |
env: | |
TF_VAR_environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | |
TF_VAR_project_id: ${{ env.GCP_PROJECT_ID }} | |
TF_VAR_region: ${{ env.GCP_REGION }} | |
- name: Terraform Apply | |
run: terraform apply -auto-approve tfplan | |
working-directory: ./infra | |
env: | |
TF_VAR_environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'development' }} | |
TF_VAR_project_id: ${{ env.GCP_PROJECT_ID }} | |
TF_VAR_region: ${{ env.GCP_REGION }} | |
- name: Terraform Output | |
run: terraform output |