forked from AdminTurnedDevOps/DevOps-The-Hard-Way-AWS
-
Notifications
You must be signed in to change notification settings - Fork 217
64 lines (54 loc) · 1.71 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Terrform-Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
terraform:
name: Terrform-Deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: "./2-Terraform-AZURE-Services-Creation/4-aks"
permissions:
contents: write
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
tf_resource_group_name: "thomasthorntoncloud"
tf_storage_account_name: "thomasthorntontfstate"
tf_state_container: "devopsthehardwaygithub"
tf_state_key: "terraform.tfstate"
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.6
terraform_wrapper: true
- name: Terraform Init
run: terraform init
- name: Terraform Format
if: github.event_name == 'pull_request'
run: terraform fmt
- name: Auto Commit Changes
uses: stefanzweifel/git-auto-commit-action@v5
if: github.event_name == 'pull_request'
with:
commit_message: "Terraform fmt"
file_pattern: "*.tf *.tfvars"
commit_user_name: "github-actions[bot]"
- name: Terraform Plan
run: terraform plan -no-color -input=false
env:
DEPLOYMENT_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: terraform apply -auto-approve -input=false