-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Precommit to check for hardcoded aws partition (#108)
- Loading branch information
Showing
3 changed files
with
77 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
name: Lint-Format-Scan | ||
on: [push] | ||
jobs: | ||
|
@@ -97,6 +96,15 @@ jobs: | |
uses: pre-commit/[email protected] | ||
with: | ||
extra_args: terraform_checkov --all-files | ||
check_aws_partition: | ||
name: Check for hardcoded aws partition | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Check for hardcoded aws partition | ||
uses: pre-commit/[email protected] | ||
with: | ||
extra_args: check_aws_partition --all-files | ||
test-examples: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#! /usr/bin/env bash | ||
|
||
exec 1>&2 | ||
|
||
check_aws_partition() { | ||
declare -A failed_files | ||
|
||
for file in $(git ls-files | grep -v "check-aws-partition.sh"); do | ||
if grep -q "arn:aws" "${file}"; then | ||
failed_files["${file}"]=1 | ||
fi | ||
done | ||
|
||
if [ ${#failed_files[@]} -ne 0 ]; then | ||
for file in "${!failed_files[@]}"; do | ||
echo "${file} contains a hardcoded AWS partition. Use arn:\${data.aws_partition.current.partition} instead of arn:aws." | ||
done | ||
return 1 | ||
fi | ||
|
||
return 0 | ||
|
||
} | ||
|
||
check_aws_partition | ||
exit_code=$? | ||
exit $exit_code |