-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (71 loc) · 2.1 KB
/
ci.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
name: CI
on:
pull_request:
branches: [main]
types: [opened, reopened, synchronize, edited]
jobs:
env:
name: Set Env Vars
runs-on: ubuntu-latest
steps:
- name: Set up DEV Environment Variables
if: github.base_ref == 'main'
run: |
matrix='{
"env":[
{
"tf_version":"1.8.0",
"tf_working_dir":"./examples/ci-1_0",
"aws_account":"977306314792",
"aws_gha_role":"terraform-bastion-dev-gha"
}
]
}'
echo matrix=`echo $matrix | jq -c .` >> $GITHUB_ENV
outputs:
matrix: ${{ env.matrix }}
format:
name: Terraform Format
runs-on: ubuntu-latest
needs: env
strategy:
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Terraform Setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.env.tf_version }}
- name: Terraform Format
working-directory: "./"
run: terraform fmt -check -recursive
plan:
name: Terraform Plan
runs-on: ubuntu-latest
needs: env
strategy:
matrix: ${{ fromJson(needs.env.outputs.matrix) }}
permissions:
contents: read
actions: read
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::${{ matrix.env.aws_account }}:role/${{ matrix.env.aws_gha_role }}"
role-session-name: ${{ github.sha }}
aws-region: us-west-2
- name: Terraform Setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.env.tf_version }}
- name: Terraform Init
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform init
- name: Terraform Plan
working-directory: ${{ matrix.env.tf_working_dir }}
run: terraform plan -input=false
# TODO: Post plan back to PR