GithubHelp home page GithubHelp logo

wobondar / tfconfig Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 43 KB

Terraform configuration manager

Shell 5.19% Go 94.81%
terraform terraform-scripts terraform-configuration dotenv terraform-dotenv terraform-aws aws-sdk-go aws-ssm terraform-ssm

tfconfig's Introduction

tfconfig

Terraform configuration manager

Environment variables:

CI - if true or 1, confirmation before any changes will be skipped

usage: tfconfig [<flags>] <command> [<args> ...]

Terraform configuration manager

Flags:
  -h, --help       Show context-sensitive help (also try --help-long and --help-man).
  -v, --version    Show application version.
  -c, --ci         CI flag, default 'false', if 'true' that you will not be asked before changes
  -p, --path=PATH  Terraform project path
  -V, --verbose    Verbose mode, default 'false'

Commands:
  help [<command>...]
    Show help.


  env <environment>
    Switch Terraform project environment


  dotenv [<flags>] <environment> [<dotEnvFile>]
    Generate .env file or expose configuration into env vars from Parameter Store

    -d, --decrypt  Will attempt to decrypt the parameter, default: true. use --no-decrypt to disable it
    -e, --export   Prints vars prepared for export to env via eval like 'export VAR_NAME=var_value\n'

Commands

env

Switches Terraform environment for you project by generating environment.tf

config.tf must be exists inside your project folder

aws-terraform-modules the folder should be somewhere near the project and have the structure, see example above

env example

$ tfconfig env dev
[INFO]  Path:   /Volumes/Secured/user/git/your-cool-application/terraform
[INFO]  Config: /Volumes/Secured/user/git/your-cool-application/terraform/config.tf
[INFO]  Environment:    /Volumes/Secured/user/git/your-cool-application/terraform/environment.tf
[WARNING]  Environment file 'environment.tf' exists and will be overridden
[INFO]  Looking in '/Volumes/Secured/user/git/your-cool-application/terraform/./'
[INFO]  Looking in '/Volumes/Secured/user/git/your-cool-application/terraform/../'
[INFO]  Looking in '/Volumes/Secured/user/git/your-cool-application/terraform/../../'
[INFO]  Found 'aws-terraform-modules' in '/Volumes/Secured/user/git/your-cool-application/terraform/../../'
[INFO]  Module source will be: '../../aws-terraform-modules/environment/dev/config'

After this operation configuration will be changed
Do you want to continue? [Y/n] y
[INFO]  Environment successfully switched: dev

$ cat environment.tf
######################################
##   DO NOT EDIT THIS FILE          ##
##   Generated by tfconfig          ##
######################################

module "config" {
  source = "../../aws-terraform-modules/environment/dev/config"
}

dotenv

Generate .env file or expose configuration into env vars from AWS Parameter Store via your provided .env.<environment>

Before start to working with dotenv command you should have AWS_REGION environment variable!

Inspiring by ssm-env I've got part of @remind101 code that communicates with AWS.

dotenv examples

$ export AWS_REGION=us-west-1
$ tfconfig dotenv example
DOTENV_SECURE_DB_HOST=db1.example.com DOTENV_PLAIN_DB_NAME=db_name DOTENV_SECURE_DB_PASSWORD=PaSsW0rd
$ tfconfig dotenv example -e
export DOTENV_PLAIN_DB_NAME=db_name
export DOTENV_SECURE_DB_PASSWORD=PaSsW0rd
export DOTENV_SECURE_DB_HOST=db1.example.com
$ tfconfig dotenv example .env
[INFO]  Path:   /Volumes/Secured/user/git/tfconfig/src
[INFO]  Environment:    example
[INFO]  Source dotEnv file:     .env.example
[INFO]  Destination dotEnv file:        .env
[WARNING]  dotEnv file '.env' exists and will be overridden

After this operation configuration will be changed
Do you want to continue? [Y/n] y
[INFO]  Successful.
$ env $(tfconfig dotenv example) node -e "console.log(process.env)" | grep "DOTENV_"
  DOTENV_SECURE_DB_PASSWORD: 'PaSsW0rd',
  DOTENV_SECURE_DB_HOST: 'db1.example.com',
  DOTENV_PLAIN_DB_NAME: 'db_name' }
$ eval "$(tfconfig dotenv example -e)"
$ env | grep "DOTENV_"
DOTENV_SECURE_DB_HOST=db1.example.com
DOTENV_SECURE_DB_PASSWORD=PaSsW0rd
DOTENV_PLAIN_DB_NAME=db_name

Some different use case, might be useful:

  1. Reading .env.example, getting values from AWS SSM and writes into .env.dev
  2. Reading .env.dev and then exposing vars without requesting those from AWS SSM, because a new .env.dev doesnt have values that should be requested
$ tfconfig dotenv example .env.dev -c
[INFO]  Path:   /Volumes/Secured/user/git/tfconfig/src
[INFO]  Environment:    example
[INFO]  Source dotEnv file:     .env.example
[INFO]  Destination dotEnv file:        .env.dev
[WARNING]  Confirmation has been skipped via running environment configuration
[INFO]  Successful.
$ cat .env.dev
DOTENV_PLAIN_DB_NAME="db_name"
DOTENV_SECURE_DB_HOST="db1.example.com"
DOTENV_SECURE_DB_PASSWORD="PaSsW0rd"
$ tfconfig dotenv dev -e
export DOTENV_PLAIN_DB_NAME=db_name
export DOTENV_SECURE_DB_HOST=db1.example.com
export DOTENV_SECURE_DB_PASSWORD=PaSsW0rd

tfconfig's People

Contributors

abaucorp avatar wobondar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rajasekhar92127

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.