-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (93 loc) · 3.13 KB
/
terraform.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Apply terraform
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'terraform/**'
- '!**/*.md'
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
prepare:
concurrency:
group: storage
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure Azure credentials
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
- name: Setup Ansible
run: >
pipx uninstall ansible-core &&
pip3 install ansible &&
ansible-galaxy collection install azure.azcollection --force
- name: Install dependecies
run:
pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements.txt
- name: Setup Azure Storage for Terraform Backend
run:
ansible-playbook -v storage-playbook.yml
env:
RESOURCE_GROUP: ${{ secrets.AZ_RESOURCE_GROUP }}
STORAGE_ACCOUNT_NAME: ${{ secrets.AZ_STORAGE_ACCOUNT_NAME }}
CONTAINER_NAME: ${{ secrets.AZ_CONTAINER_NAME }}
deploy:
needs:
- prepare
env:
tf_actions_working_dir: terraform
ARM_CLIENT_ID: ${{ secrets.AZ_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZ_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZ_TENANT_ID }}
defaults:
run:
working-directory: ./terraform
concurrency:
group: terraform
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure Azure credentials
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
- name: Configure Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.5
- name: Generate backend configuration
run: |
echo "resource_group_name = \"$RESOURCE_GROUP\"" >> backend.hcl
echo "storage_account_name = \"$STORAGE_ACCOUNT_NAME\"" >> backend.hcl
echo "container_name = \"$CONTAINER_NAME\"" >> backend.hcl
env:
RESOURCE_GROUP: ${{ secrets.AZ_RESOURCE_GROUP }}
STORAGE_ACCOUNT_NAME: ${{ secrets.AZ_STORAGE_ACCOUNT_NAME }}
CONTAINER_NAME: ${{ secrets.AZ_CONTAINER_NAME }}
- name: Terraform Init
id: init
run: |
terraform init -backend-config=backend.hcl -lock-timeout=120s
- name: Terraform Validate
id: validate
run: |
terraform validate -no-color
- name: Terraform Plan
id: plan
run: |
terraform plan -no-color -lock-timeout=120s
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
run: terraform apply -auto-approve -input=false -lock-timeout=120s