A swiss army knife to use in a CI tool in order to ensure quality of your terraform code and so on.
This tool contains (latest version):
Add line below to .bash_aliases or .bashrc
alias toolkit='docker run -v $(pwd):/data -it pagarme/docker-iac-toolkit:latest'
toolkit -v
toolkit -h
usage: toolkit.py cli [-h] [-v] [-d DIRECTORY] [-r RECURSIVE] [-w WORKSPACE] [--tf-version TF_VERSION] [--disable-checkov] [--checkov-args CHECKOV_ARGS] [--disable-tflint]
[--tflint-args TFLINT_ARGS] [--disable-validate] [--validate-args VALIDATE_ARGS] [--disable-format] [--format-args FORMAT_ARGS] [--init-args INIT_ARGS]
optional arguments:
-h, --help show this help message and exit
-v, --version show program version
-d DIRECTORY, --directory DIRECTORY
verify a directory
-r RECURSIVE, --recursive RECURSIVE
verify a applications directory recursively
-w WORKSPACE, --workspace WORKSPACE
configure terraform workspace
--tf-version TF_VERSION
configure terraform version
--disable-checkov disable checkov
--checkov-args CHECKOV_ARGS
extra args to checkov
--disable-tflint disable tflint
--tflint-args TFLINT_ARGS
extra args to tflint
--disable-validate disable terraform validate
--validate-args VALIDATE_ARGS
extra args to terraform validate
--disable-format disable terraform format
--format-args FORMAT_ARGS
extra args terraform format
--init-args INIT_ARGS
extra args to terraform init
toolkit verify -d . --tflint-config .tflint.hcl
TF_VERSION=0.14.0
TOOLKIT_DATA_DIR=/root/project
tfswitch 0.14.0
Inside the container you are free to use all commands as you prefer
toolkit
# single folder
toolkit verify -d <sigle folder>
# application folders
toolkit verify -r <applications folder>
toolkit terraform <command>(init, plan, apply, destroy)
toolkit tflint
Mount file overriding /opt/toolkit/.tflint/config.hcl
toolkit checkov
Example using CircleCI
version: 2.1
jobs:
build:
docker:
- image: $DOCKER_IMAGE
environment:
# select terraform version
TF_VERSION: "<version>"
TOOLKIT_DATA_DIR: "/root/project"
steps:
- checkout
- run:
name: Verify single folder
command: verify -d my-single-folder
- run:
name: Verify all projects in applications
command: verify -r applications
To use with credentials use need configure AWS Cli environment variables.
docker run \
-e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \
-e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \
-e AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN} \ #required if use aws-vault session
-e AWS_SECURITY_TOKEN=${AWS_SECURITY_TOKEN} \ #required if use aws-vault session
-v $(pwd):/data -it pagarme/docker-iac-toolkit:latest
Another option is to use aws-vault cli in server mode (--server). The docker container will get credentials via instance metadata.
Feel free to fork and send us a pull request with other good features
# Build args are optional, you might change tag latest for you preferred version
# Change <semantic_version> according to desired version
docker build -t pagarme/docker-iac-toolkit:<semantic_version> .
Content type
Image
Digest
Size
481.7 MB
Last updated
over 5 years ago
docker pull pagarme/docker-iac-toolkit