Sign inSign up

pagarme/docker-iac-toolkit

By pagarme

•Updated over 5 years ago

Image
0

4.1K

pagarme/docker-iac-toolkit repository overview

⁠docker-iac-toolkit

A swiss army knife to use in a CI tool in order to ensure quality of your terraform code and so on.

⁠Documentation

⁠Tools

This tool contains (latest version):

⁠Using

⁠Creating an alias
⁠Configuration

Add line below to .bash_aliases or .bashrc

alias toolkit='docker run -v $(pwd):/data -it pagarme/docker-iac-toolkit:latest'
⁠Show versions
toolkit -v
⁠Help
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
⁠Using
toolkit verify -d . --tflint-config .tflint.hcl
⁠Selecting terraform version
⁠Using environment variable
TF_VERSION=0.14.0
TOOLKIT_DATA_DIR=/root/project
⁠Using tfswitch
tfswitch 0.14.0
⁠Go inside the container

Inside the container you are free to use all commands as you prefer

toolkit
⁠Verify folder
# single folder
toolkit verify -d <sigle folder>

# application folders
toolkit verify -r <applications folder>
⁠Terraform
toolkit terraform <command>(init, plan, apply, destroy)
⁠TFLint
toolkit tflint
⁠Overriding configuration

Mount file overriding /opt/toolkit/.tflint/config.hcl

Template⁠

⁠Checkov
toolkit checkov
⁠CircleCI

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

⁠Credentials

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⁠.

⁠Contributing

Feel free to fork and send us a pull request with other good features

⁠Build
# 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> .

Tag summary

Content type

Image

Digest

Size

481.7 MB

Last updated

over 5 years ago

docker pull pagarme/docker-iac-toolkit