-
Notifications
You must be signed in to change notification settings - Fork 35
121 lines (118 loc) · 4.06 KB
/
terraform-ci-cd.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
110
111
112
113
114
115
116
117
118
119
120
121
name: Terraform CI/CD
on:
push:
branches:
- "**"
paths-ignore:
- docs/**.md
- "*.md"
jobs:
terraform_linter:
runs-on: ubuntu-latest
steps:
- name: Clone git repo
uses: actions/checkout@v1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.14.2
- name: Terraform Linter Check (Formatting)
run: |
terraform fmt -recursive -check
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: "1.15" # The Go version to download (if necessary) and use.
- name: "Terraform Code Standards Check"
run: |
GO111MODULE="on" go get github.com/terraform-docs/[email protected]
export PATH=$HOME/go/bin:$PATH
pip3 install --pre slalom.dataops
s-infra check_tf_metadata ./catalog/aws \
--check_module_headers \
--required_input_vars=[name_prefix,resource_tags,environment] \
--required_output_vars=[summary] \
--check_input_descriptions \
--check_output_descriptions \
--raise_error
s-infra check_tf_metadata ./components/aws \
--check_module_headers \
--required_input_vars=[name_prefix,resource_tags,environment] \
--required_output_vars=[] \
--check_input_descriptions \
--check_output_descriptions \
--raise_error
tf_test:
runs-on: ubuntu-latest
strategy:
max-parallel: 8
fail-fast: false
matrix:
# python-version: [3.7]
sample-id:
- airflow-on-aws
- dbt-and-singer-on-aws
- kitchen-sink-on-aws
- ml-ops-on-aws
- ml-ops-on-aws-img-recognition
- mysql-on-aws
- postgres-on-aws
- redshift-on-aws
- s3-lambda-trigger
- secrets-manager-on-aws
- sftp-on-aws
- tableau-on-aws
steps:
- name: Clone git repo
uses: actions/checkout@v1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.14.2
terraform_wrapper: false
- name: "Terraform Init (${{ matrix.sample-id }})"
run: |
cd ./samples/${{ matrix.sample-id }}
terraform init
- name: "Terraform Validate (${{ matrix.sample-id }})"
run: |
cd ./samples/${{ matrix.sample-id }}
terraform validate
- name: "Rename all secrets file templates"
run: |
sudo apt-get install rename
find . -name "*.template" | xargs rename -v "s/\.template//g"
- name: "Terraform Plan (${{ matrix.sample-id }})"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
cd ./samples/${{ matrix.sample-id }}
terraform plan -out plan.out | tee plan.out.txt
terraform show -json plan.out > plan.out.json
md5sum plan.out | head -c 32 > plan.out.md5
- name: Upload Plan File Artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.sample-id }}-plans
path: samples/${{ matrix.sample-id }}/plan.out*
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: "Install Terraform-Compliance"
run: |
pip install terraform-compliance
- name: "Terraform Compliance Checks (${{ matrix.sample-id }})"
run: |
cd ./samples/${{ matrix.sample-id }}
terraform-compliance -p plan.out.json -f ../../tests/rules | tee compliance.out.txt
- name: Upload Compliance File Artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.sample-id }}-compliance
path: samples/${{ matrix.sample-id }}/compliance.out.txt