-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update makefile * Export mode * Update README.yaml Co-Authored-By: osterman <[email protected]>
- Loading branch information
Showing
4 changed files
with
225 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ | |
# tfenv [![Build Status](https://travis-ci.org/cloudposse/tfenv.svg?branch=master)](https://travis-ci.org/cloudposse/tfenv) [![Latest Release](https://img.shields.io/github/release/cloudposse/tfenv.svg)](https://github.com/cloudposse/tfenv/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) | ||
|
||
|
||
Command line utility to transform environment variables for use with Terraform (e.g. `HOSTNAME` → `TF_VAR_hostname`) | ||
Command line utility to transform environment variables for use with Terraform. | ||
(e.g. `HOSTNAME` → `TF_VAR_hostname`) | ||
|
||
__NOTE__: `tfenv` is **not** a [terraform version manager](https://github.com/tfutils/tfenv). | ||
It can also intelligently map environment variables to terraform command line arguments (e.g. `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=example` → `TF_CLI_ARGS_init=-backend-config=bucket=example`). | ||
|
||
__NOTE__: `tfenv` is **not** a [terraform version manager](https://github.com/tfutils/tfenv). It strictly manages environment variables. | ||
|
||
|
||
--- | ||
|
@@ -45,6 +48,7 @@ If you answer "yes" to any of these questions, then look no further! | |
* Have you ever wished you could easily pass environment variables to terraform *without* adding the `TF_VAR_` prefix? | ||
* Do you use [`chamber`](https://github.com/segmentio/chamber) and get annoyed when it transforms environment variables to uppercase? | ||
* Would you like to use common environment variables names with terraform? (e.g. `USER` or `AWS_REGION`) | ||
* Is there some argument to `terraform init` you want to specify with an environment variable? (e.g. a `-backend-config` property) | ||
|
||
**Yes?** Great! Then this utility is for you. | ||
|
||
|
@@ -57,6 +61,11 @@ The `tfenv` utility will perform the following transformations: | |
|
||
__NOTE__: `tfenv` will preserve the existing environment and add the new environment variables with `TF_VAR_`. This is because some terraform providers expect non-`TF_VAR_*` prefixed environment variables. Additionally, when using the `local-exec` provisioner, it's convenient to use regular environment variables. See our [`terraform-null-smtp-mail`](https://github.com/cloudposse/terraform-null-smtp-mail) module for an example of using this pattern. | ||
|
||
|
||
**But wait, there's more!** | ||
|
||
With `tfenv` we can surgically assign a value to any terraform argument using per-argument environment variables. | ||
|
||
## Usage | ||
|
||
|
||
|
@@ -75,9 +84,58 @@ The basic usage looks like this. We're going to run some `command` and pass it ` | |
So for example, we can pass our current environment to terraform by simply running: | ||
|
||
```sh | ||
tfenv terraform plan | ||
tfenv terraform plan | ||
``` | ||
|
||
### Direnv | ||
|
||
You can use `tfenv` with direnv very easily. Running `tfenv` without any arguments will emit `export` statements. | ||
|
||
Example `.envrc`: | ||
|
||
```sh | ||
# Export terraform environment | ||
tfenv | ||
``` | ||
|
||
### Bash | ||
|
||
Load the terraform environment into your shell. | ||
|
||
Just add the following into your shell script: | ||
|
||
```sh | ||
source <(tfenv) | ||
``` | ||
|
||
### Terraform Args | ||
|
||
With `tfenv` we can populate the [`TF_CLI_ARGS` and `TF_CLI_ARGS_*` environment variables](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name) automatically. This makes it easy to toggle settings. | ||
|
||
For example, if you want to pass `-backend-config=bucket=terraform-state-bucket` to `terraform init`, then you would do the following: | ||
|
||
```sh | ||
export TF_CLI_INIT_BACKEND_CONFIG_BUCKET=terraform-state-bucket | ||
``` | ||
|
||
Running `tfenv` will populate the `TF_CLI_ARGS_init=-backend-config=bucket=terraform-state-bucket` | ||
|
||
Multiple arguments can be specified and they will be properly concatenated. | ||
|
||
### Initializing Modules | ||
|
||
Terraform as the built-in capability to initialize "root modules" from a remote sources by passing the `-from-module` argument to `terraform init`. | ||
|
||
We can turn this into a 12-factor style invocation using `tfenv`. | ||
|
||
```sh | ||
export TF_CLI_INIT_FROM_MODULE=git::[email protected]:ImpactHealthio/terraform-root-modules.git//aws/$(SERVICE)?ref=tags/0.5.7 | ||
source <(tfenv) | ||
terraform init | ||
``` | ||
|
||
Learn more about `TF_CLI_ARGS` and `TF_CLI_ARGS_*` in the [official documentation](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name). | ||
|
||
|
||
|
||
|
||
|
@@ -207,7 +265,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. | |
|
||
## Copyright | ||
|
||
Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright) | ||
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,12 @@ badges: | |
|
||
# Short description of this project | ||
description: |- | ||
Command line utility to transform environment variables for use with Terraform (e.g. `HOSTNAME` → `TF_VAR_hostname`) | ||
Command line utility to transform environment variables for use with Terraform. | ||
(e.g. `HOSTNAME` → `TF_VAR_hostname`) | ||
It can also intelligently map environment variables to terraform command line arguments (e.g. `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=example` → `TF_CLI_ARGS_init=-backend-config=bucket=example`). | ||
__NOTE__: `tfenv` is **not** a [terraform version manager](https://github.com/tfutils/tfenv). | ||
__NOTE__: `tfenv` is **not** a [terraform version manager](https://github.com/tfutils/tfenv). It strictly manages environment variables. | ||
introduction: |- | ||
|
@@ -41,6 +44,7 @@ introduction: |- | |
* Have you ever wished you could easily pass environment variables to terraform *without* adding the `TF_VAR_` prefix? | ||
* Do you use [`chamber`](https://github.com/segmentio/chamber) and get annoyed when it transforms environment variables to uppercase? | ||
* Would you like to use common environment variables names with terraform? (e.g. `USER` or `AWS_REGION`) | ||
* Is there some argument to `terraform init` you want to specify with an environment variable? (e.g. a `-backend-config` property) | ||
**Yes?** Great! Then this utility is for you. | ||
|
@@ -54,6 +58,11 @@ introduction: |- | |
__NOTE__: `tfenv` will preserve the existing environment and add the new environment variables with `TF_VAR_`. This is because some terraform providers expect non-`TF_VAR_*` prefixed environment variables. Additionally, when using the `local-exec` provisioner, it's convenient to use regular environment variables. See our [`terraform-null-smtp-mail`](https://github.com/cloudposse/terraform-null-smtp-mail) module for an example of using this pattern. | ||
**But wait, there's more!** | ||
With `tfenv` we can surgically assign a value to any terraform argument using per-argument environment variables. | ||
# How to use this project | ||
usage: |- | ||
|
@@ -72,9 +81,59 @@ usage: |- | |
So for example, we can pass our current environment to terraform by simply running: | ||
```sh | ||
tfenv terraform plan | ||
tfenv terraform plan | ||
``` | ||
### Direnv | ||
You can use `tfenv` with direnv very easily. Running `tfenv` without any arguments will emit `export` statements. | ||
Example `.envrc`: | ||
```sh | ||
# Export terraform environment | ||
tfenv | ||
``` | ||
### Bash | ||
Load the terraform environment into your shell. | ||
Just add the following into your shell script: | ||
```sh | ||
source <(tfenv) | ||
``` | ||
### Terraform Args | ||
With `tfenv` we can populate the [`TF_CLI_ARGS` and `TF_CLI_ARGS_*` environment variables](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name) automatically. This makes it easy to toggle settings. | ||
For example, if you want to pass `-backend-config=bucket=terraform-state-bucket` to `terraform init`, then you would do the following: | ||
```sh | ||
export TF_CLI_INIT_BACKEND_CONFIG_BUCKET=terraform-state-bucket | ||
``` | ||
Running `tfenv` will populate the `TF_CLI_ARGS_init=-backend-config=bucket=terraform-state-bucket` | ||
Multiple arguments can be specified and they will be properly concatenated. | ||
### Initializing Modules | ||
Terraform has the built-in capability to initialize "root modules" from a remote sources by passing the `-from-module` argument to `terraform init`. | ||
We can turn this into a 12-factor style invocation using `tfenv`. | ||
```sh | ||
export TF_CLI_INIT_FROM_MODULE=git::[email protected]:ImpactHealthio/terraform-root-modules.git//aws/$(SERVICE)?ref=tags/0.5.7 | ||
source <(tfenv) | ||
terraform init | ||
``` | ||
Learn more about `TF_CLI_ARGS` and `TF_CLI_ARGS_*` in the [official documentation](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name). | ||
related: | ||
- name: "Packages" | ||
description: "Cloud Posse installer and distribution of native apps" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters