This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (83 loc) · 3.02 KB
/
examples.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
name: Examples Checks
on:
push:
branches:
- main
pull_request:
paths:
- .github/workflows/examples.yml
- .go-version
- .tflint.hcl
- examples/**
- tools/go.mod
env:
AWS_DEFAULT_REGION: us-west-2
jobs:
validate-terraform:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
terraform_version: ["0.12.31", "1.0.6"]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
# See also: https://github.com/actions/setup-go/pull/62
- run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: go build
run: go build -o terraform-plugin-dir/terraform-provider-aws_v99.99.99_x5 .
- name: override plugin
run: |
# For Terraform v0.12
mkdir -p ~/.terraform.d/plugins
cp terraform-plugin-dir/terraform-provider-aws_v99.99.99_x5 ~/.terraform.d/plugins
# For newer versions
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/99.99.99/$(go env GOOS)_$(go env GOARCH)/
cp terraform-plugin-dir/terraform-provider-aws_v99.99.99_x5 ~/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/99.99.99/$(go env GOOS)_$(go env GOARCH)/
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: ${{ matrix.terraform_version }}
# Needed to use the output of `terraform validate -json`
terraform_wrapper: false
- name: install tflint
run: cd tools && go install github.com/terraform-linters/tflint
- uses: actions/cache@v2
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- name: terraform
run: |
TFLINT_CONFIG="$(pwd -P)/.tflint.hcl"
for DIR in $(find ./examples -type f -name '*.tf' -exec dirname {} \; | sort -u); do
pushd "$DIR"
if [ -f terraform.template.tfvars ]; then
cp terraform.template.tfvars terraform.tfvars
fi
echo; echo -e "\e[1;35m===> Initializing Example: $DIR <===\e[0m"; echo
terraform init
echo; echo -e "\e[1;35m===> Format Checking Example: $DIR <===\e[0m"; echo
terraform fmt -check
echo; echo -e "\e[1;35m===> Validating Example: $DIR <===\e[0m"; echo
# Catch errors
terraform validate
# Terraform syntax checks
# We don't want to exit on the first tflint error
set +e
tflint --config=$TFLINT_CONFIG \
--enable-rule=terraform_deprecated_interpolation \
--enable-rule=terraform_deprecated_index \
--enable-rule=terraform_unused_declarations \
--enable-rule=terraform_comment_syntax \
--enable-rule=terraform_required_version
set -e
popd
done