-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (123 loc) · 4.74 KB
/
deploy.yaml
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Terraform Deployment
on:
workflow_dispatch:
inputs:
environment:
description: "Environment name"
required: true
type: choice
options:
- dev
pull_request: null
defaults:
run:
working-directory: ./terraform
jobs:
tflint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout source code
- uses: actions/cache@v4
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: ${{ runner.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- uses: terraform-linters/[email protected]
name: Setup TFLint
with:
tflint_version: v0.52.0
- name: Show version
run: tflint --version
- name: Init TFLint
run: tflint --init
env:
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
GITHUB_TOKEN: ${{ github.token }}
- name: Run TFLint
run: tflint -f compact
tfsec:
name: tfsec
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Cache tfsec binary
uses: actions/cache@v4
with:
path: ~/.tfsec
key: tfsec-${{ runner.os }}-${{ hashFiles('**/*.tf') }}
restore-keys: |
tfsec-${{ runner.os }}-
- name: Install tfsec (if not cached)
run: |
if [ ! -f ~/.tfsec/tfsec ]; then
mkdir -p ~/.tfsec
curl -L "https://github.com/aquasecurity/tfsec/releases/download/v1.28.0/tfsec-linux-amd64" -o ~/.tfsec/tfsec
chmod +x ~/.tfsec/tfsec
fi
shell: bash
- name: Run tfsec
run: ~/.tfsec/tfsec . || true
deploy:
needs: [tflint, tfsec]
runs-on: ubuntu-latest
name: Deploy to ${{ matrix.name }} Environment
environment:
name: ${{ matrix.name }}
url: https://${{ vars.DOMAIN_NAME }}
strategy:
matrix:
name:
- dev
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check if deployment should proceed
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.environment }}" != "${{ matrix.name }}" ]]; then
echo "Skipping deployment for ${{ matrix.name }}"
exit 0
fi
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.8
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- name: Set DB Password and Username as Environment Variables
run: |
echo "TF_VAR_name=${{ matrix.name }}-env" >> $GITHUB_ENV
echo "TF_VAR_db_username=${{ vars.DB_USERNAME }}" >> $GITHUB_ENV
echo "TF_VAR_db_password=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV
echo "TF_VAR_oidc_kc_client_id=${{ vars.OIDC_KC_CLIENT_ID }}" >> $GITHUB_ENV
echo "TF_VAR_oidc_kc_client_secret=${{ secrets.OIDC_KC_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "TF_VAR_oidc_kc_issuer_url=${{ vars.OIDC_KC_ISSUER_URL }}" >> $GITHUB_ENV
echo "TF_VAR_cert_arn=${{ vars.CERT_ARN }}" >> $GITHUB_ENV
echo "TF_VAR_region=${{ vars.AWS_REGION }}" >> $GITHUB_ENV
echo "TF_VAR_zone_name=${{ vars.DOMAIN_NAME }}" >> $GITHUB_ENV
echo "TF_VAR_prs_private_key=${{ secrets.SERVER_PRIVATE_KEY_JSON }}" >> $GITHUB_ENV
echo "TF_VAR_prs_public_key=${{ secrets.SERVER_PUBLIC_KEY_JSON }}" >> $GITHUB_ENV
echo "TF_VAR_jwt_issuer=${{ vars.JWT_ISSUER }}" >> $GITHUB_ENV
echo "TF_VAR_jwt_expiration=${{ vars.JWT_EXPIRATION_TIME_MS }}" >> $GITHUB_ENV
echo "TF_VAR_twilio_account_sid=${{ vars.TWILIO_ACCOUNT_SID }}" >> $GITHUB_ENV
echo "TF_VAR_twilio_auth_token=${{ vars.TWILIO_AUTH_TOKEN }}" >> $GITHUB_ENV
echo "TF_VAR_twilio_phone_number=${{ vars.TWILIO_PHONE_NUMBER }}" >> $GITHUB_ENV
echo "TF_VAR_otp_salt=${{ secrets.OTP_SALT }}" >> $GITHUB_ENV
- name: Terraform Init
run: |
terraform init -var-file=${{ matrix.name }}.tfvars \
-backend-config="region=${{ vars.AWS_REGION }}" \
-backend-config="bucket=webank-dev-terraform-state" \
-backend-config="dynamodb_table=webank-dev-terraform-state-lock"
- name: Terraform Plan
run: |
terraform plan -var-file=${{ matrix.name }}.tfvars -out=plan.tfplan
- name: Terraform Apply
if: github.event_name == 'workflow_dispatch'
run: |
terraform apply -auto-approve plan.tfplan