Merge pull request #32716 from taktakpeops/fix/opensearchdomain-offpe… #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Examples Checks | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
paths: | |
- .github/workflows/examples.yml | |
- .ci/.tflint.hcl | |
- .ci/tools/go.mod | |
- examples/** | |
- go.mod | |
env: | |
AWS_DEFAULT_REGION: us-west-2 | |
jobs: | |
tflint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 | |
with: | |
fetch-depth: 0 | |
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }} | |
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 | |
with: | |
go-version-file: go.mod | |
- name: install tflint | |
run: cd .ci/tools && go install github.com/terraform-linters/tflint | |
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
name: Cache plugin dir | |
with: | |
path: ~/.tflint.d/plugins | |
key: ${{ runner.os }}-tflint-${{ hashFiles('.ci/.tflint.hcl') }} | |
- run: tflint --config .ci/.tflint.hcl --init | |
- name: tflint | |
run: | | |
exit_code=0 | |
TFLINT_CONFIG="$(pwd -P)/.ci/.tflint.hcl" | |
for DIR in $(find ./examples -type f -name '*.tf' -exec dirname {} \; | sort -u); do | |
pushd "$DIR" | |
tflint --config="$TFLINT_CONFIG" \ | |
--enable-rule=terraform_comment_syntax \ | |
--enable-rule=terraform_deprecated_index \ | |
--enable-rule=terraform_deprecated_interpolation \ | |
--enable-rule=terraform_required_version \ | |
--disable-rule=terraform_required_providers \ | |
--disable-rule=terraform_typed_variables \ | |
|| exit_code=1 | |
popd | |
done | |
exit $exit_code | |
validate-terraform: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
terraform_version: ["0.12.31", "1.0.6"] | |
env: | |
TF_IN_AUTOMATION: "1" | |
steps: | |
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 | |
with: | |
fetch-depth: 0 | |
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 | |
with: | |
path: ~/go/pkg/mod | |
key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }} | |
- uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 | |
with: | |
go-version-file: go.mod | |
- 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@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 | |
with: | |
terraform_version: ${{ matrix.terraform_version }} | |
# Needed to use the output of `terraform validate -json` | |
terraform_wrapper: false | |
- name: terraform | |
run: | | |
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 | |
popd | |
done |