diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..96ff8c6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: check-added-large-files + - id: check-byte-order-marker + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: detect-private-key + - id: end-of-file-fixer + - id: mixed-line-ending + args: [--fix=no] + - id: trailing-whitespace + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.0.8 + hooks: + - id: shellcheck diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..9bef39b --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,11 @@ +# This configuration file allows our pre-commit hooks to be used with pre-commit: http://pre-commit.com/ + +- id: terraform-validate + name: Terraform validate + description: Validates all Terraform configuration files + entry: hooks/terraform-validate.sh + language: script + files: \.tf$ + exclude: \.+.terraform\/.*$ + require_serial: true + args: [--azurerm-provider-version=2.25.0] diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..3764018 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,3 @@ +{ + "extends": "@quantum-sec/semantic-release-config/base" +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b28ed81 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +© 2020 Quantum Security Pte. Ltd. All Rights Reserved. diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..56152a4 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,16 @@ +trigger: + branches: + include: + - master + - feature/* + - fix/* + +resources: + repositories: + - repository: pipeline-library + type: github + endpoint: quantum-sec-github + name: quantum-sec/pipeline-library + +jobs: + - template: templates/jobs/default.yml@pipeline-library diff --git a/hooks/terraform-validate.sh b/hooks/terraform-validate.sh new file mode 100755 index 0000000..cb50827 --- /dev/null +++ b/hooks/terraform-validate.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -e + +# This is a clone of https://github.com/gruntwork-io/pre-commit/blob/master/hooks/terraform-validate.sh +# It adds support for modules that use the Azure Resource Manager provider 2.0+. +# This provider requires an explicit `features` block which in most cases is supplied by a super module. +# See: https://github.com/hashicorp/terraform/pull/24896 + +function main() { + local azurerm_provider_version="2.25.0" + + if [[ "$1" = "--azurerm-provider-version"* ]]; then + azurerm_provider_version="${1//--azurerm-provider-version=/}" + fi + + for dir in $(echo "$@" | xargs -n1 dirname | sort -u | uniq); do + pushd "$dir" >/dev/null + if [ -n "$azurerm_provider_version" ]; then + cat << EOF > provider.tf +provider "azurerm" { + version = "$azurerm_provider_version" + features {} +} +EOF + fi + terraform init -backend=false + terraform validate + rm provider.tf + popd >/dev/null + done +} + +main "$@" diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9df8351 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "@quantum-sec/pre-commit", + "version": "0.0.0-development", + "lockfileVersion": 1 +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c6685d5 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "@quantum-sec/pre-commit", + "version": "0.0.0-development", + "repository": { + "type": "git", + "url": "git@github.com:quantum-sec/pre-commit.git" + }, + "author": "Quantum Security Pte. Ltd.", + "license": "SEE LICENSE IN LICENSE" +}