Merge pull request #5 from Resourcely-Inc/update/provider #13
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: Plan and Apply Terraform | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
terraform: | |
name: 'Terraform' | |
runs-on: ubuntu-latest | |
environment: production | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
- name: Terraform Init | |
run: terraform init | |
- name: Terraform Plan | |
run: terraform plan -out=plan.raw | |
- name: Convert the plan to JSON | |
id: planToJson | |
run: terraform show -json plan.raw | |
- name: Save JSON to a file | |
uses: fishcharlie/[email protected] | |
with: | |
data: ${{ steps.planToJson.outputs.stdout }} | |
output: plan.json | |
- name: Upload Terraform Plan Output | |
uses: actions/upload-artifact@v2 | |
with: | |
name: plan-file | |
path: plan.json | |
- name: Terraform Apply | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
run: terraform apply -auto-approve -input=false | |
resourcely-ci: | |
needs: terraform | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download Terraform Plan Output | |
uses: actions/download-artifact@v2 | |
with: | |
name: plan-file | |
path: tf-plan-files/ | |
- name: Resourcely CI | |
uses: Resourcely-Inc/resourcely-action@v1 | |
with: | |
resourcely_api_token: ${{ secrets.RESOURCELY_API_TOKEN }} | |
resourcely_api_host: "https://api.resourcely.io" | |
tf_plan_directory: "tf-plan-files" |