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

Add terraform pre-commit hook #100

Merged
merged 11 commits into from
Jun 27, 2023
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
83 changes: 83 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Pre-Commit

on:
pull_request:
branches:
- main
- master

env:
TERRAFORM_DOCS_VERSION: v0.16.0
TFLINT_VERSION: v0.44.1

jobs:
collectInputs:
name: Collect workflow inputs
runs-on: ubuntu-latest
outputs:
directories: ${{ steps.dirs.outputs.directories }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get root directories
id: dirs
uses: clowdhaus/terraform-composite-actions/[email protected]

preCommitMinVersions:
name: Min TF pre-commit
needs: collectInputs
runs-on: ubuntu-latest
strategy:
matrix:
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Terraform min/max versions
id: minMax
uses: clowdhaus/[email protected]
with:
directory: ${{ matrix.directory }}

- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory != '.' }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'

- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory == '.' }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'

preCommitMaxVersion:
name: Max TF pre-commit
runs-on: ubuntu-latest
needs: collectInputs
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Terraform min/max versions
id: minMax
uses: clowdhaus/[email protected]

- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
uses: clowdhaus/terraform-composite-actions/[email protected]
with:
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
tflint-version: ${{ env.TFLINT_VERSION }}
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
install-hcledit: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ tmp
examples/*/plan
*.auto.tfvars

.envrc
.envrc
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.79.1
hooks:
- id: terraform_fmt
- id: terraform_validate
- id: terraform_docs
args:
- '--args=--lockfile=false'
- id: terraform_tflint
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ By participating in this project, you agree to abide by our [Code of Conduct](ht
- If you have any questions or need assistance, feel free to open an issue or reach out to the maintainers on GitHub.
- We welcome any suggestions for improvements or new features.

We look forward to working with you and improving Data-Quality-Gate together!
We look forward to working with you and improving Data-Quality-Gate together!
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
2 changes: 1 addition & 1 deletion configs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"globalUploadSettings":{
"format":"JSON"
}
}
}
2 changes: 1 addition & 1 deletion configs/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"CALL ID": "call id",
"new_col_added0": "year_month"
}
}
}
2 changes: 1 addition & 1 deletion configs/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"only_failed": true
}

}
}
2 changes: 1 addition & 1 deletion configs/pks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"RECORD_NUMBER"
]
}
}
}
2 changes: 1 addition & 1 deletion configs/sort_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"update_dt"
]
}
}
}
2 changes: 1 addition & 1 deletion configs/test_coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"sample": {
"complexSuite": true
}
}
}
File renamed without changes.
43 changes: 43 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
provider "aws" {
region = "eu-west-2"

default_tags {
tags = {
Terraform = true
}
}
}

module "data_qa" {
source = "../../terraform"

data_test_storage_bucket_name = "dqg-settings-dev"
s3_source_data_bucket = "data-bucket-name"
environment = "demo"
project = "provectus"

allure_report_image_uri = "..."
data_test_image_uri = "..."
push_report_image_uri = "..."

data_reports_notification_settings = {
channel = "DataReportSlackChannelName"
webhook_url = "https://hooks.slack.com/services/........"
}

lambda_private_subnet_ids = ["private_subnet_id"]
lambda_security_group_ids = ["security_group_id"]

reports_vpc_id = "some_vpc_id"
reports_subnet_id = "subnet_id"
reports_whitelist_ips = ["0.0.0.0/0"]

test_coverage_path = "../../configs/test_coverage.json"
pipeline_config_path = "../../configs/pipeline.json"
pks_path = "../../configs/pks.json"
sort_keys_path = "../../configs/sort_keys.json"
mapping_path = "../../configs/mapping.json"
manifest_path = "../../configs/manifest.json"
great_expectation_path = "../../templates/great_expectations.yml"
expectations_store = "../../expectations_store"
}
Empty file added examples/basic/outputs.tf
Empty file.
Empty file added examples/basic/variables.tf
Empty file.
10 changes: 10 additions & 0 deletions examples/basic/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.1.7"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.64.0"
}
}
}
60 changes: 0 additions & 60 deletions examples/docker_basic/docker.tf

This file was deleted.

69 changes: 0 additions & 69 deletions examples/docker_basic/main.tf

This file was deleted.

Loading