GithubHelp home page GithubHelp logo

excoriate / handy-terraform-bash-scripts Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 22 KB

πŸš€ Set of bash scripts ready to be used to automate common terraform tasks within your project ;)

Shell 100.00%

handy-terraform-bash-scripts's Introduction

Terraform automations scripts

All these scripts were made to be used either in an automated environment β€”Β let's say, a CICD job that runs in a given pipeline, a terminal alias, npm script, etc.

Even though, these scripts can be easily integrated on some git hook such as husky or pre-commit framework. They're agnostic to any specific tool β€”Β they're just bash scripts :)

Scripts

Hook Description
terraform_validate.sh Validates all Terraform configuration files.
terraform_fmt Format (check and fix) Terraform configuration following the canonical format.
terraform_docs Generate and keep up to date the documentation of terraform components. Re-write the readme.md file dynamically
terraform_lint Use TFLint to prevent bugs!
terraform_clean Get rid of the .terraform folder on local executions, after you've done all your local terraform commands.
terraform_sec Validates all Terraform configuration from the security point of view. It uses TFSec
terraform_plan Execute terraform plan command onto specific terraform modules
terraform_init Execute terraform init command onto specific terraform modules
terraform_lifecycle Script that wraps the terraform licecycle: init, plan, apply and destroy
terraform_modules_auth_gitlab Whether you're using Gitlab and you're using private terraform modules within Gitlab, this script allows you authenticate your child modules and download (terraform get) other called modules from within Gitlab

Example of use

Add this scripts in npm scripts

    "tf:init": "export ENVIRONMENT=test && ./scripts/automation/terraform_lifecycle.sh --command=init --dir=example --config=config/remote.config",
    "tf:plan": "export ENVIRONMENT=test && ./scripts/automation/terraform_lifecycle.sh --command=plan --dir=example --vars=config/terraform.tfvars --config=config/remote.config",
    "tf:apply": "export ENVIRONMENT=test && ./scripts/automation/terraform_lifecycle.sh --command=apply --dir=example --vars=config/terraform.tfvars --config=config/remote.config",
    "tf:destroy": "export ENVIRONMENT=test && ./scripts/automation/terraform_lifecycle.sh --command=destroy --dir=example --vars=config/terraform.tfvars --config=config/remote.config",
    "tf:clean": "export ENVIRONMENT=test && ./scripts/automation/terraform_lifecycle.sh --command=clean --dir=example && ./scripts/automation/terraform_lifecycle.sh --command=clean --dir=module",
    "tf:docs": "./scripts/hooks/terraform_docs.sh --dir=module",
    "tf:format": "./scripts/hooks/terraform_fmt.sh --dir=module",

Use them standalone

    ./scripts/automation/terraform_lifecycle.sh --command=init --dir=example --config=config/remote.config

Use in CICD (Example> Gitlab)

    plan_infra:
    stage: plan
    variables:
      TF_VAR_environment: test
      AWS_DEFAULT_REGION: ${AWS_REG_TEST}
    script:
      - ./scripts/automation/terraform_lifecycle.sh --command=plan --dir=example --vars=config/terraform.tfvars --config=config/remote.config
    dependencies:
      - init_infra

handy-terraform-bash-scripts's People

Contributors

excoriate avatar

Stargazers

Luis Gaete avatar v1k1n60 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.