Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to have spaces in directories #11

Merged
merged 1 commit into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v1.2.0
rev: v1.2.3
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-case-conflict
- id: check-merge-conflict
- id: check-executables-have-shebangs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ An example `.pre-commit-config.yaml`:

```yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
sha: v1.5.0
sha: v1.6.0
hooks:
- id: terraform_fmt
```
Expand Down
6 changes: 6 additions & 0 deletions terraform_fmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare -a tfvars_files
index=0

for file_with_path in "$@"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"

paths[index]=$(dirname "$file_with_path")

if [[ "$file_with_path" == *".tfvars" ]]; then
Expand All @@ -17,12 +19,16 @@ for file_with_path in "$@"; do
done

for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
terraform fmt
popd > /dev/null
done

# terraform.tfvars are excluded by `terraform fmt`
for tfvars_file in "${tfvars_files[@]}"; do
tfvars_file="${tfvars_file//__REPLACED__SPACE__/ }"

terraform fmt "$tfvars_file"
done
4 changes: 4 additions & 0 deletions terraform_validate_no_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ declare -a paths
index=0

for file_with_path in "$@"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"

paths[index]=$(dirname "$file_with_path")
let "index+=1"
done

for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
terraform validate -check-variables=false

Expand Down
4 changes: 4 additions & 0 deletions terraform_validate_with_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ declare -a paths
index=0

for file_with_path in "$@"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"

paths[index]=$(dirname "$file_with_path")
let "index+=1"
done

for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
terraform validate -check-variables=true

Expand Down