diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..7cf5f6d
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,161 @@
+version: 2.1
+
+jobs:
+ #
+ # Test 1 & Test 2
+ #
+ test-static-code-and-linting:
+ machine:
+ image: ubuntu-1604:201903-01
+ # This job has been blocked because Docker Layer Caching is not available on your plan.
+ # Please upgrade to continue building.
+ # Note: you will need to push a new commit or call the API to rerun the pipeline.
+ docker_layer_caching: false
+
+ steps:
+ - checkout
+
+ - run: pwd
+ - run: ls -ltra
+ - run: git branch
+
+ - run:
+ name: test1-terraform-format
+ command: |
+ if [[ $(make format| tail -n +2) ]]; then
+ echo "==================================================================================================="
+ echo " NOT PASSED - There are Terraform conf files that needs a canonical format and styleto be formated "
+ echo "==================================================================================================="
+ exit 1
+ else
+ echo "==================================================================================================="
+ echo " PASSED - All Terraform conf files already have canonical format and are correcyly styled "
+ echo "==================================================================================================="
+ fi
+
+ - run:
+ name: test2-terraform-linting
+ command: |
+ if make lint | grep 'Awesome! Your code is following the best practices'; then
+ echo "==============================================================================================="
+ echo " PASSED - Awesome! Your code is following the best practices "
+ echo "==============================================================================================="
+ else
+ echo "==============================================================================================="
+ echo " NOT PASSED - Terraform lint needed "
+ echo "==============================================================================================="
+ fi
+ #
+ # Test 3
+ #
+ test-e2e-terratests:
+ machine:
+ image: ubuntu-1604:201903-01
+ docker_layer_caching: false
+
+ steps:
+ - checkout
+
+ - run: pwd
+ - run: ls -ltra
+ - run: git branch
+
+ - run:
+ name: Install awscli
+ command: sudo pip install awscli
+
+ - run:
+ name: Configure awscli
+ command: |
+ echo "AWS_ACCESS_KEY_ID - $AWS_ACCESS_KEY_ID"
+ echo "AWS_PROFILE_NAME - $AWS_PROFILE_NAME"
+
+ # AWS defautl awscli profile
+ aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
+ aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
+ aws configure set region us-east-1
+ aws configure set output json
+
+ # AWS dev awscli profile
+ aws configure set role_arn arn:aws:iam::$AWS_ACCOUNT_ID_DEV:role/DeployMaster --profile $AWS_PROFILE_NAME
+ aws configure set source_profile default --profile $AWS_PROFILE_NAME
+
+# - run: cat ~/.aws/credentials
+# - run: cat ~/.aws/config
+
+ - run:
+ name: Test AWS permissions
+ command: aws budgets describe-budgets --account-id $AWS_ACCOUNT_ID_DEV --profile $AWS_PROFILE_NAME
+
+ - run:
+ name: test3-terratests-dep-init
+ command: cd modules/waf-global && make terratest-dep-init
+
+ - run:
+ name: test3-terratests-go-test
+ command: cd modules/waf-global && make terratest-go-test
+
+ - run:
+ name: test4-terratests-dep-init
+ command: cd modules/waf-regional && make terratest-dep-init
+
+ - run:
+ name: test4-terratests-go-test
+ command: cd modules/waf-regional && make terratest-go-test
+ #
+ # Release
+ #
+ release-patch-with-changelog:
+ machine:
+ image: ubuntu-1604:201903-01
+ docker_layer_caching: false
+
+ steps:
+ - checkout
+
+ - run: pwd
+ - run: ls -ltra
+ - run: git branch
+
+ - run:
+ name: release-patch-with-changelog-circleci
+ command: |
+ if git status | grep 'nothing to commit, working tree clean'; then
+ echo "==============================================================================================="
+ echo "release-patch-with-changelog-circleci"
+ echo "==============================================================================================="
+ git config --global user.email "$GIT_USER_EMAIL"
+ git config --global user.name "$GIT_USER_NAME"
+ make release-patch-with-changelog-circleci
+ else
+ echo "==============================================================================================="
+ echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below "
+ echo "==============================================================================================="
+ echo "$(git status)"
+ echo "==============================================================================================="
+ fi
+#
+# Jobs workflow
+#
+workflows:
+ version: 2
+ changelog_and_release:
+ jobs:
+ - test-static-code-and-linting:
+ context: binbashar-org-global-context
+ filters:
+ branches:
+ ignore: # only branches matching the below regex filters will run
+ - master
+ - test-e2e-terratests:
+ context: binbashar-org-global-context
+ filters:
+ branches:
+ ignore: # only branches matching the below regex filters will run
+ - master
+ - release-patch-with-changelog:
+ context: binbashar-org-global-context
+ filters:
+ branches:
+ only: # only branches matching the below regex filters will run
+ - master
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index bf3bf91..7f58769 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
# Except
#
!*.env.example
+!*.circleci
!*.dockeringnore
!*.hosts
!/.gitignore
@@ -65,6 +66,8 @@ Thumbs.db
*.iml
*.ipr
.vscode
+/src
+/venv
# Custom Project tools files #
########################
@@ -88,4 +91,5 @@ Thumbs.db
#
# Terratest
#
-tests/vendor/
\ No newline at end of file
+modules/waf-global/tests/vendor/
+modules/waf-regional/tests/vendor/
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 1e4c551..9014eda 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ LOCAL_OS_GIT_CONF_DIR := ~/.gitconfig
LOCAL_OS_AWS_CONF_DIR := ~/.aws
TF_PWD_DIR := $(shell pwd)
-TF_VER := 0.11.14
+TF_VER := 0.12.12
TF_PWD_CONT_DIR := "/go/src/project/"
TF_DOCKER_ENTRYPOINT := /usr/local/go/bin/terraform
TF_DOCKER_IMAGE := binbash/terraform-resources
@@ -36,7 +36,7 @@ endef
GIT_SEMTAG_VER_PATCH := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s patch -o)
GIT_SEMTAG_VER_MINOR := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s minor -o)
-GIT_SEMTAG_VER_MINOR := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s major -o)
+GIT_SEMTAG_VER_MAJOR := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s major -o)
help:
@echo 'Available Commands:'
@@ -54,8 +54,20 @@ version: ## Show terraform version
format: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt ${TF_PWD_CONT_DIR}
-lint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan.
- docker run --rm -v ${TF_PWD_DIR}:/data -t wata727/tflint --deep
+doc-tf-eleven: ## A utility to generate documentation from Terraform 0.11 modules in various output formats.
+ docker run --rm -v ${TF_PWD_DIR}:/data -t binbash/terraform-docs markdown table /data
+
+doc-tf-twelve: ## A utility to generate documentation from Terraform 0.12 modules in various output formats.
+ bash terraform-docs.sh markdown ${TF_PWD_DIR}
+
+lint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.11 --> < 0.9.2.
+ docker run --rm -v ${TF_PWD_DIR}:/data -t wata727/tflint:0.9.2 --deep
+
+#==============================================================#
+# CIRCLECI #
+#==============================================================#
+circleci-validate-config: ## Validate A CircleCI Config (https://circleci.com/docs/2.0/local-cli/)
+ circleci config validate .circleci/config.yml
#==============================================================#
# GIT RELEASE #
@@ -66,24 +78,80 @@ release-patch: ## releasing patch (eg: 0.0.1 -> 0.0.2) based on semantic tagging
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
${GIT_SEMTAG_CMD_PREFIX} final -s patch
+release-patch-with-changelog: ## make changelog-patch && git add && git commit && make release-patch
+ @if git status | grep 'nothing to commit, working directory clean'; then\
+ make changelog-patch;\
+ git status;\
+ git add CHANGELOG.md;\
+ git commit -m "Updating CHANGELOG.md via make changelog-patch for ${GIT_SEMTAG_VER_PATCH} [ci skip]";\
+ git push origin master;\
+ make release-patch;\
+ else\
+ echo "===============================================================================================";\
+ echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below ";\
+ echo "===============================================================================================";\
+ echo "$$(git status)";\
+ echo "===============================================================================================";\
+ fi
+
+release-patch-with-changelog-circleci: ## make changelog-patch && git add && git commit && make release-patch
+ make changelog-patch
+ git status
+ git add CHANGELOG.md
+ git commit -m "Updating CHANGELOG.md via make changelog-patch for ${GIT_SEMTAG_VER_PATCH} [ci skip]"
+ git push origin master
+ make release-patch
+
release-minor: ## releasing minor (eg: 0.0.2 -> 0.1.0) based on semantic tagging script for Git
# pre-req -> https://github.com/pnikosis/semtag
${GIT_SEMTAG_CMD_PREFIX} get
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
${GIT_SEMTAG_CMD_PREFIX} final -s minor
+release-minor-with-changelog: ## make changelog-minor && git add && git commit && make release-minor
+ @if git status |grep 'nothing to commit, working directory clean'; then\
+ make changelog-minor;\
+ git status;\
+ git add CHANGELOG.md;\
+ git commit -m "Updating CHANGELOG.md via make changelog-minorfor ${GIT_SEMTAG_VER_PATCH} [ci skip]";\
+ git push origin master;\
+ make release-minor;\
+ else\
+ echo "===============================================================================================";\
+ echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below ";\
+ echo "===============================================================================================";\
+ echo "$$(git status)";\
+ echo "===============================================================================================";\
+ fi
+
release-major: ## releasing major (eg: 0.1.0 -> 1.0.0) based on semantic tagging script for Git
# pre-req -> https://github.com/pnikosis/semtag
${GIT_SEMTAG_CMD_PREFIX} get
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
${GIT_SEMTAG_CMD_PREFIX} final -s major
+release-major-with-changelog: ## make changelog-major && git add && git commit && make release-major
+ @if git status |grep 'nothing to commit, working directory clean'; then\
+ make changelog-major;\
+ git status;\
+ git add CHANGELOG.md;\
+ git commit -m "Updating CHANGELOG.md via make changelog-major for ${GIT_SEMTAG_VER_PATCH} [ci skip]";\
+ git push origin master;\
+ make release-major;\
+ else\
+ echo "===============================================================================================";\
+ echo "Changes in working directory pending to be pushed - please check 'git status' cmd output below ";\
+ echo "===============================================================================================";\
+ echo "$$(git status)";\
+ echo "===============================================================================================";\
+ fi
+
changelog-init: ## git-chglog (https://github.com/git-chglog/git-chglog) config initialization -> ./.chglog
@if [ ! -d ./.chglog ]; then\
docker run --rm -v ${TF_PWD_DIR}:/data -it binbash/git-release --init;\
sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.chglog;\
else\
- echo "==============================";\
+ echo "==============================";\
echo "git-chglog already initialized";\
echo "==============================";\
echo "$$(ls ./.chglog)";\
diff --git a/README.md b/README.md
index edbd8f5..993d78d 100644
--- a/README.md
+++ b/README.md
@@ -154,4 +154,29 @@ module "waf_regional_test" {
rule_csrf_action_type = "COUNT"
rule_blacklisted_ips_action_type = "COUNT"
}
-```
\ No newline at end of file
+```
+
+# Release Management
+
+## Docker based makefile commands
+- https://cloud.docker.com/u/binbash/repository/docker/binbash/git-release
+- https://github.com/binbashar/terraform-aws-waf-owasp/blob/master/Makefile
+
+Root directory `Makefile` has the automated steps (to be integrated with **CircleCI jobs** []() )
+
+### CircleCi PR auto-release job
+
+
+
+
+- https://circleci.com/gh/binbashar/terraform-aws-waf-owasp
+- **NOTE:** Will only run after merged PR.
+
+### Manual execution from workstation
+```
+$ make
+Available Commands:
+ - release-major-with-changelog make changelog-major && git add && git commit && make release-major
+ - release-minor-with-changelog make changelog-minor && git add && git commit && make release-minor
+ - release-patch-with-changelog make changelog-patch && git add && git commit && make release-patch
+ ```
\ No newline at end of file
diff --git a/figures/circleci.png b/figures/circleci.png
new file mode 100644
index 0000000..6e3a37b
Binary files /dev/null and b/figures/circleci.png differ
diff --git a/modules/waf-global/Makefile b/modules/waf-global/Makefile
index b5adbe8..f0f57a4 100644
--- a/modules/waf-global/Makefile
+++ b/modules/waf-global/Makefile
@@ -6,7 +6,7 @@ LOCAL_OS_GIT_CONF_DIR := ~/.gitconfig
LOCAL_OS_AWS_CONF_DIR := ~/.aws
TF_PWD_DIR := $(shell pwd)
-TF_VER := 0.11.14
+TF_VER := 0.12.12
TF_PWD_CONT_DIR := "/go/src/project/"
TF_DOCKER_ENTRYPOINT := /usr/local/go/bin/terraform
TF_DOCKER_IMAGE := binbash/terraform-resources
@@ -46,22 +46,6 @@ docker run --rm \
-it ${TF_DOCKER_IMAGE}:${TF_VER}
endef
-#
-# GIT-RELEASE
-#
-# pre-req -> https://github.com/pnikosis/semtag
-define GIT_SEMTAG_CMD_PREFIX
-docker run --rm \
--v ${TF_PWD_DIR}:/data:rw \
--v ${LOCAL_OS_SSH_DIR}:/root/.ssh \
--v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \
---entrypoint=/opt/semtag/semtag/semtag \
--it binbash/git-release
-endef
-
-GIT_SEMTAG_VER_PATCH := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s patch -o)
-GIT_SEMTAG_VER_MINOR := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s minor -o)
-GIT_SEMTAG_VER_MINOR := $(shell ${GIT_SEMTAG_CMD_PREFIX} final -s major -o)
help:
@echo 'Available Commands:'
@@ -79,12 +63,14 @@ version: ## Show terraform version
format: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style.
${TF_CMD_PREFIX} fmt ${TF_PWD_CONT_DIR}
-doc: ## A utility to generate documentation from Terraform modules in various output formats.
+doc-tf-eleven: ## A utility to generate documentation from Terraform 0.11 modules in various output formats.
docker run --rm -v ${TF_PWD_DIR}:/data -t binbash/terraform-docs markdown table /data
-lint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan.
- docker run --rm -v ${TF_PWD_DIR}:/data -t wata727/tflint --deep
+doc-tf-twelve: ## A utility to generate documentation from Terraform 0.12 modules in various output formats.
+ bash terraform-docs.sh markdown ${TF_PWD_DIR}
+lint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan (tf0.11 --> < 0.9.2.
+ docker run --rm -v ${TF_PWD_DIR}:/data -t wata727/tflint:0.9.2 --deep
#==============================================================#
# TERRATEST #
@@ -98,55 +84,4 @@ terratest-dep-init: ## dep is a dependency management tool for Go. (https://gith
terratest-go-test: ## lint: TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan.
${TERRATEST_GO_CMD_PREFIX} test
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} .
-
-#==============================================================#
-# GIT RELEASE #
-#==============================================================#
-release-patch: ## releasing patch (eg: 0.0.1 -> 0.0.2) based on semantic tagging script for Git
- # pre-req -> https://github.com/pnikosis/semtag
- ${GIT_SEMTAG_CMD_PREFIX} get
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- ${GIT_SEMTAG_CMD_PREFIX} final -s patch
-
-release-minor: ## releasing minor (eg: 0.0.2 -> 0.1.0) based on semantic tagging script for Git
- # pre-req -> https://github.com/pnikosis/semtag
- ${GIT_SEMTAG_CMD_PREFIX} get
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- ${GIT_SEMTAG_CMD_PREFIX} final -s minor
-
-release-major: ## releasing major (eg: 0.1.0 -> 1.0.0) based on semantic tagging script for Git
- # pre-req -> https://github.com/pnikosis/semtag
- ${GIT_SEMTAG_CMD_PREFIX} get
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- ${GIT_SEMTAG_CMD_PREFIX} final -s major
-
-changelog-init: ## git-chglog (https://github.com/git-chglog/git-chglog) config initialization -> ./.chglog
- @if [ ! -d ./.chglog ]; then\
- docker run --rm -v ${TF_PWD_DIR}:/data -it binbash/git-release --init;\
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.chglog;\
- else\
- echo "==============================";\
- echo "git-chglog already initialized";\
- echo "==============================";\
- echo "$$(ls ./.chglog)";\
- echo "==============================";\
- fi
-
-changelog-patch: ## git-chglog generation for path release
- docker run --rm -v ${TF_PWD_DIR}:/data -it binbash/git-release -o CHANGELOG.md --next-tag ${GIT_SEMTAG_VER_PATCH}
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.chglog
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./CHANGELOG.md
-
-changelog-minor: ## git-chglog generation for minor release
- docker run --rm -v ${TF_PWD_DIR}:/data -it binbash/git-release -o CHANGELOG.md --next-tag ${GIT_SEMTAG_VER_MINOR}
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.chglog
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./CHANGELOG.md
-
-changelog-major: ## git-chglog generation for major release
- docker run --rm -v ${TF_PWD_DIR}:/data -it binbash/git-release -o CHANGELOG.md --next-tag ${GIT_SEMTAG_VER_MAJOR}
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.chglog
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git
- sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./CHANGELOG.md
\ No newline at end of file
+ sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} .
\ No newline at end of file
diff --git a/modules/waf-global/README.md b/modules/waf-global/README.md
index 0e72b70..7ee21d0 100644
--- a/modules/waf-global/README.md
+++ b/modules/waf-global/README.md
@@ -43,26 +43,29 @@ References
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
-| admin\_remote\_ipset | List of IPs allowed to access admin pages | list | n/a | yes |
-| blacklisted\_ips | List of IPs to blacklist | list | n/a | yes |
-| cloudfront\_arn | List of CloudFront Distributions ARNs | list | n/a | yes |
-| rule\_admin\_access\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_auth\_tokens\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_blacklisted\_ips\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_csrf\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_lfi\_rfi\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_php\_insecurities\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_size\_restriction\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_sqli\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_ssi\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
-| rule\_xss\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"BLOCK"` | no |
+| admin\_remote\_ipset | List of IPs allowed to access admin pages, ['1.1.1.1/32', '2.2.2.2/32', '3.3.3.3/32'] | list(string) | `` | no |
+| blacklisted\_ips | List of IPs to blacklist, eg ['1.1.1.1/32', '2.2.2.2/32', '3.3.3.3/32'] | list(string) | `` | no |
+| cloudfront\_arn | List of CloudFront Distributions ARNs | list(string) | `` | no |
+| rule\_admin\_access\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_auth\_tokens\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_blacklisted\_ips\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_csrf\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_lfi\_rfi\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_php\_insecurities\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_size\_restriction\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_sqli\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_ssi\_action\_type | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| rule\_xss\_action | Rule action type. Either BLOCK, ALLOW, or COUNT (useful for testing) | string | `"COUNT"` | no |
+| tags | A mapping of tags to assign to all resources | map | `