forked from solutions-plug/predictIQ
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (85 loc) · 2.85 KB
/
Copy pathdeploy.yml
File metadata and controls
101 lines (85 loc) · 2.85 KB
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
name: Infrastructure Deployment
on:
push:
branches: [main]
paths:
- 'infrastructure/terraform/**'
- '.github/workflows/deploy.yml'
pull_request:
branches: [main]
paths:
- 'infrastructure/terraform/**'
env:
AWS_REGION: us-east-1
TERRAFORM_VERSION: 1.5.0
jobs:
plan:
name: Terraform Plan
runs-on: ubuntu-latest
strategy:
matrix:
environment: [dev, staging, prod]
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets[format('AWS_ROLE_{0}', matrix.environment)] }}
aws-region: ${{ env.AWS_REGION }}
- name: Terraform Init
working-directory: infrastructure/terraform
run: terraform init
- name: Terraform Plan
working-directory: infrastructure/terraform
run: |
terraform plan \
-var-file="environments/${{ matrix.environment }}.tfvars" \
-out=tfplan-${{ matrix.environment }}
- name: Upload plan
uses: actions/upload-artifact@v3
with:
name: tfplan-${{ matrix.environment }}
path: infrastructure/terraform/tfplan-${{ matrix.environment }}
apply:
name: Terraform Apply
runs-on: ubuntu-latest
needs: plan
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
strategy:
matrix:
environment: [dev, staging, prod]
max-parallel: 1
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets[format('AWS_ROLE_{0}', matrix.environment)] }}
aws-region: ${{ env.AWS_REGION }}
- name: Download plan
uses: actions/download-artifact@v3
with:
name: tfplan-${{ matrix.environment }}
path: infrastructure/terraform
- name: Terraform Init
working-directory: infrastructure/terraform
run: terraform init
- name: Terraform Apply
working-directory: infrastructure/terraform
run: terraform apply -auto-approve tfplan-${{ matrix.environment }}
- name: Output infrastructure details
working-directory: infrastructure/terraform
run: terraform output -json > /tmp/outputs-${{ matrix.environment }}.json
- name: Upload outputs
uses: actions/upload-artifact@v3
with:
name: outputs-${{ matrix.environment }}
path: /tmp/outputs-${{ matrix.environment }}.json