An open API service indexing awesome lists of open source software.

https://github.com/wobondar/tfconfig

Terraform configuration manager
https://github.com/wobondar/tfconfig

aws-sdk-go aws-ssm dotenv terraform terraform-aws terraform-configuration terraform-dotenv terraform-scripts terraform-ssm

Last synced: 2 months ago
JSON representation

Terraform configuration manager

Awesome Lists containing this project

README

        

# tfconfig

## Terraform configuration manager

Environment variables:

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

```
usage: tfconfig [] [ ...]

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 [...]
Show help.

env
Switch Terraform project environment

dotenv [] []
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.`

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

Inspiring by [ssm-env](https://github.com/remind101/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
```