diff --git a/.automation/test/terraform_fmt/README.md b/.automation/test/terraform_fmt/README.md new file mode 100644 index 00000000..1ce0310f --- /dev/null +++ b/.automation/test/terraform_fmt/README.md @@ -0,0 +1,19 @@ +# AWS States language Test Cases + +This folder holds the test cases for **Terraform Formatting**. + +## Additional Docs + +No Additional information is needed for this test case. + +## Good Test Cases + +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. + +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases + +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. + +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/terraform_fmt/bad/terraform_fmt_bad_1.tf b/.automation/test/terraform_fmt/bad/terraform_fmt_bad_1.tf new file mode 100644 index 00000000..0ed57992 --- /dev/null +++ b/.automation/test/terraform_fmt/bad/terraform_fmt_bad_1.tf @@ -0,0 +1,18 @@ +resource "aws_instance" "instanceWithVpc" { + ami = "some-id" + instance_type = "t2.micro" + + monitoring = true + ebs_optimized = true + + vpc_security_group_ids = ["sg-12345678901234567"] + subnet_id = "subnet-12345678901234567" + + metadata_options { + http_endpoint = "disabled" + } + + tags = { + Name = "HelloWorld" + } +} diff --git a/.automation/test/terraform_fmt/good/terraform_fmt_good_1.tf b/.automation/test/terraform_fmt/good/terraform_fmt_good_1.tf new file mode 100644 index 00000000..d30b5f82 --- /dev/null +++ b/.automation/test/terraform_fmt/good/terraform_fmt_good_1.tf @@ -0,0 +1,18 @@ +resource "aws_instance" "instanceWithVpc" { + ami = "some-id" + instance_type = "t2.micro" + + monitoring = true + ebs_optimized = true + + vpc_security_group_ids = ["sg-12345678901234567"] + subnet_id = "subnet-12345678901234567" + + metadata_options { + http_endpoint = "disabled" + } + + tags = { + Name = "HelloWorld" + } +} diff --git a/README.md b/README.md index 0c2f4a9d..ebc0f5a4 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their codebase w | **Snakemake** | [snakefmt](https://github.com/snakemake/snakefmt/) / [snakemake --lint](https://snakemake.readthedocs.io/en/stable/snakefiles/writing_snakefiles.html#best-practices) | | **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) / [sqlfluff](https://github.com/sqlfluff/sqlfluff) | | **Tekton** | [tekton-lint](https://github.com/IBM/tekton-lint) | -| **Terraform** | [tflint](https://github.com/terraform-linters/tflint) / [terrascan](https://github.com/accurics/terrascan) | +| **Terraform** | [fmt](https://github.com/hashicorp/terraform) / [tflint](https://github.com/terraform-linters/tflint) / [terrascan](https://github.com/accurics/terrascan) | | **Terragrunt** | [terragrunt](https://github.com/gruntwork-io/terragrunt) | | **TypeScript** | [ESLint](https://eslint.org/) / [standard js](https://standardjs.com/) | | **XML** | [LibXML](http://xmlsoft.org/) | diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index a7dff909..8eba8855 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -723,6 +723,7 @@ function BuildFileList() { ################################ FILE_ARRAY_TERRAFORM_TFLINT+=("${FILE}") FILE_ARRAY_TERRAFORM_TERRASCAN+=("${FILE}") + FILE_ARRAY_TERRAFORM_FMT+=("${FILE}") ############################ # Get the Terragrunt files # diff --git a/lib/linter.sh b/lib/linter.sh index 3b466a7f..d65a462d 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -259,8 +259,8 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLANG_FORMAT' 'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'R' 'RAKU' 'RUBY' 'RUST_2015' 'RUST_2018' 'RUST_2021' 'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT' 'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'SQLFLUFF' 'TEKTON' - 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' 'TYPESCRIPT_ES' - "${TYPESCRIPT_STYLE_NAME}" 'XML' 'YAML') + 'TERRAFORM_FMT' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX' + 'TYPESCRIPT_ES' "${TYPESCRIPT_STYLE_NAME}" 'XML' 'YAML') ############################## # Linter command names array # @@ -330,6 +330,7 @@ LINTER_NAMES_ARRAY['STATES']="asl-validator" LINTER_NAMES_ARRAY['SQL']="sql-lint" LINTER_NAMES_ARRAY['SQLFLUFF']="sqlfluff" LINTER_NAMES_ARRAY['TEKTON']="tekton-lint" +LINTER_NAMES_ARRAY['TERRAFORM_FMT']="terraform" LINTER_NAMES_ARRAY['TERRAFORM_TFLINT']="tflint" LINTER_NAMES_ARRAY['TERRAFORM_TERRASCAN']="terrascan" LINTER_NAMES_ARRAY['TERRAGRUNT']="terragrunt" @@ -966,6 +967,7 @@ LINTER_COMMANDS_ARRAY['STATES']="asl-validator --json-path" LINTER_COMMANDS_ARRAY['SQL']="sql-lint --config ${SQL_LINTER_RULES}" LINTER_COMMANDS_ARRAY['SQLFLUFF']="sqlfluff lint --config ${SQLFLUFF_LINTER_RULES}" LINTER_COMMANDS_ARRAY['TEKTON']="tekton-lint" +LINTER_COMMANDS_ARRAY['TERRAFORM_FMT']="terraform fmt -check" LINTER_COMMANDS_ARRAY['TERRAFORM_TFLINT']="tflint -c ${TERRAFORM_TFLINT_LINTER_RULES}" LINTER_COMMANDS_ARRAY['TERRAFORM_TERRASCAN']="terrascan scan -i terraform -t all -c ${TERRAFORM_TERRASCAN_LINTER_RULES} -f" LINTER_COMMANDS_ARRAY['TERRAGRUNT']="terragrunt hclfmt --terragrunt-check --terragrunt-log-level error --terragrunt-hclfmt-file"