From 1a393756b526c3fc0e15aef3db15ea8f13798602 Mon Sep 17 00:00:00 2001 From: Abhilash <32317996+iabhee@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:27:01 -0600 Subject: [PATCH] add tf apply actions (#6) --- .github/workflows/terraform-apply.yml | 47 +++++++++++++++++++++++++++ .github/workflows/terraform-plan.yml | 5 +++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/terraform-apply.yml diff --git a/.github/workflows/terraform-apply.yml b/.github/workflows/terraform-apply.yml new file mode 100644 index 0000000..fb1d13f --- /dev/null +++ b/.github/workflows/terraform-apply.yml @@ -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 }} + diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 7e3c0f0..b2d027a 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -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