Update Terraform Deploy to GCP.yaml
Fixed errors
This commit is contained in:
41
.github/workflows/Terraform Deploy to GCP.yaml
vendored
41
.github/workflows/Terraform Deploy to GCP.yaml
vendored
@@ -1,41 +1,54 @@
|
|||||||
name: Terraform Deploy to GCP
|
name: Terraform Deploy to GCP
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_dispatch: # Manual trigger
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
terraform:
|
terraform:
|
||||||
name: Deploy with Terraform on GCP
|
name: Deploy GCP Infrastructure
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json
|
GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout this repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Clone Terraform repo from Gerrit
|
||||||
|
run: |
|
||||||
|
git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo
|
||||||
|
|
||||||
|
|
||||||
- name: Set up Terraform
|
- name: Set up Terraform
|
||||||
uses: hashicorp/setup-terraform@v3
|
uses: hashicorp/setup-terraform@v3
|
||||||
with:
|
with:
|
||||||
terraform_version: 1.5.0
|
terraform_version: 1.5.0
|
||||||
|
|
||||||
- name: Authenticate to Google Cloud
|
- name: Authenticate to Google Cloud
|
||||||
run: echo "${{ secrets.GCP_CREDENTIALS }}" > gcp-key.json
|
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcp-key.json
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: Terraform Init
|
- name: Terraform Init with backend
|
||||||
run: terraform init -var="credentials_file=gcp-key.json"
|
working-directory: ./onix-dev/Terraform
|
||||||
|
run: |
|
||||||
|
terraform init \
|
||||||
|
-backend-config="bucket=your-backend-bucket-name" \
|
||||||
|
-backend-config="prefix=terraform/state" \
|
||||||
|
-backend-config="credentials=${{ github.workspace }}/gcp-key.json"
|
||||||
|
|
||||||
- name: Terraform Validate
|
|
||||||
run: terraform validate
|
|
||||||
|
|
||||||
- name: Terraform Plan
|
- name: Terraform Plan
|
||||||
run: terraform plan -var="credentials_file=gcp-key.json" -out=tfplan
|
working-directory: ./onix-dev/Terraform
|
||||||
|
run: terraform plan -out=tfplan -var="credentials_file=${{ github.workspace }}/gcp-key.json"
|
||||||
|
|
||||||
|
- name: Wait for Manual Approval
|
||||||
|
uses: hmarr/auto-approve-action@v2
|
||||||
|
if: false # prevents automatic approval
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.PAT_GITHUB }}
|
||||||
|
|
||||||
- name: Terraform Apply
|
- name: Terraform Apply
|
||||||
run: terraform apply -auto-approve tfplan
|
working-directory: ./onix-dev/Terraform
|
||||||
|
run: terraform apply tfplan
|
||||||
|
|
||||||
- name: Clean up credentials file
|
- name: Clean up credentials
|
||||||
run: rm -f gcp-key.json
|
run: rm -f gcp-key.json
|
||||||
|
|||||||
Reference in New Issue
Block a user