Skip to content

Commit

Permalink
add tf apply actions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
iabhee authored Dec 17, 2024
1 parent 1cb8609 commit 1a39375
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Terraform Apply"

on:
push:
branches:
- main

env:
TF_CLOUD_ORGANIZATION: "${{ secrets.TF_CLOUD_ORGANIZATION }}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "learn-terraform"
CONFIG_DIRECTORY: "./learn-terraform-vnet"

jobs:
terraform:
if: github.repository != 'hashicorp-education/learn-terraform-github-actions'
name: "Terraform Apply"
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

- name: Terraform init
id: init
run: terraform init
working-directory: ${{ env.CONFIG_DIRECTORY }}

- name: Terraform Plan
id: plan
run: terraform plan
working-directory: ${{ env.CONFIG_DIRECTORY }}

- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
working-directory: ${{ env.CONFIG_DIRECTORY }}

- name: Terraform Apply
run: terraform apply -auto-approve
working-directory: ${{ env.CONFIG_DIRECTORY }}

5 changes: 5 additions & 0 deletions .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
run: terraform plan
working-directory: ${{ env.CONFIG_DIRECTORY }}

- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
working-directory: ${{ env.CONFIG_DIRECTORY }}

- name: Update PR
uses: actions/github-script@v6
id: plan-comment
Expand Down

0 comments on commit 1a39375

Please sign in to comment.