Skip to content

Instantly share code, notes, and snippets.

@osterman
Last active January 14, 2019 19:56
Show Gist options
  • Select an option

  • Save osterman/1541fd6b60626cef4a3b322baf8d7e3d to your computer and use it in GitHub Desktop.

Select an option

Save osterman/1541fd6b60626cef4a3b322baf8d7e3d to your computer and use it in GitHub Desktop.

Revisions

  1. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant ([**III. Config**](https://12factor.net/config)). That is, terraform doesn't consume environment variables for all settings & parameters.
    One of the biggest pains with terraform is that it's not totally 12-factor compliant ([**III. Config**](https://12factor.net/config)). That is, terraform doesn't consume environment variables for all settings & parameters. As a result, many of us use wrappers like `terragrunt` to invoke `terraform`.

    **Have you ever wanted to set the backend config using strictly environment variables?**

  2. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket`

    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv) (#golang), which will then map them to the `TF_CLI_ARGS_*`.

    Download the precompiled binary [here](https://github.com/cloudposse/tfenv/releases) for your OS.
    *[Download the precompiled binary here](https://github.com/cloudposse/tfenv/releases) for your OS.*

    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
  3. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket`

    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv) (#golang), which will then map them to the `TF_CLI_ARGS_*`.

    **DOWNLOAD BINARY** [here](https://github.com/cloudposse/tfenv/releases).
    Download the precompiled binary [here](https://github.com/cloudposse/tfenv/releases) for your OS.

    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
  4. osterman revised this gist Jan 14, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,9 @@ Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket`

    **The Solution**

    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv) (#golang; [binary releases](https://github.com/cloudposse/tfenv/releases)), which will then map them to the `TF_CLI_ARGS_*`.
    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv) (#golang), which will then map them to the `TF_CLI_ARGS_*`.

    **DOWNLOAD BINARY** [here](https://github.com/cloudposse/tfenv/releases).

    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
  5. osterman revised this gist Jan 14, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,8 @@ Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket`

    **The Solution**

    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv), which will then map them to the `TF_CLI_ARGS_*`.
    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv) (#golang; [binary releases](https://github.com/cloudposse/tfenv/releases)), which will then map them to the `TF_CLI_ARGS_*`.


    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
  6. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -53,4 +53,4 @@ source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')

    3. **...and we can use vanilla terraform without wrappers.**

    Curious? We do this and *WAAAAAAY MORE* in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
    Curious? We do this and *WAAAAAAY* more in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
  7. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -53,4 +53,4 @@ source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')

    3. **...and we can use vanilla terraform without wrappers.**

    Curious? We do this and *WAY MORE* in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
    Curious? We do this and *WAAAAAAY MORE* in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
  8. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -53,4 +53,4 @@ source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')

    3. **...and we can use vanilla terraform without wrappers.**

    Curious? We do this and **WAY MORE** in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
    Curious? We do this and *WAY MORE* in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
  9. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -53,4 +53,4 @@ source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')

    3. **...and we can use vanilla terraform without wrappers.**

    Curious? We do this and more in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
    Curious? We do this and **WAY MORE** in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
  10. osterman revised this gist Jan 14, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -51,4 +51,6 @@ source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')

    2. **We can use the task runner of our choice** (e.g. `make`, [`robo`](https://github.com/tj/robo), [`variant`](https://github.com/mumoshu/variant)).

    3. **...and we can use vanilla terraform without wrappers.**
    3. **...and we can use vanilla terraform without wrappers.**

    Curious? We do this and more in [`cloudposse/geodesic`](https://github.com/cloudposse/geodesic)
  11. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,6 @@ What I like about this is we can now manage our environment how we want to.
    source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')
    ```

    2. **We can use the task runner of our choice** (e.g. `make`, `robo`, [`variant`](https://github.com/mumoshu/variant)).
    2. **We can use the task runner of our choice** (e.g. `make`, [`robo`](https://github.com/tj/robo), [`variant`](https://github.com/mumoshu/variant)).

    3. **...and we can use vanilla terraform without wrappers.**
  12. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ Now, when I run `terraform init`, it will download the remote module and initial
    What I like about this is we can now manage our environment how we want to.


    1. **Manage the enviroment the way we want to.** e.g. using `chamber` or some other tool like `direnv`, or both!
    1. **Manage the enviroment the way we want to.** e.g. using [`chamber`](https://github.com/segmentio/chamber) or some other tool like `direnv`, or both!
    ```
    source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')
    ```
  13. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ Now, when I run `terraform init`, it will download the remote module and initial
    What I like about this is we can now manage our environment how we want to.


    1. **Manage the enviroment the way we want to.** e.g. using `chamber` or some other tool like `direnv`.
    1. **Manage the enviroment the way we want to.** e.g. using `chamber` or some other tool like `direnv`, or both!
    ```
    source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')
    ```
  14. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ We can automatically initialize any [terraform-root-module](https://github.com/c

    For example, if I add this to my `.envrc`:
    ```
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules.git//aws/vpc-peering.git?ref=tags/0.29.0"
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules.git//aws/vpc-peering?ref=tags/0.29.0"
    source <(tfenv)
    ```

  15. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ We can automatically initialize any [terraform-root-module](https://github.com/c

    For example, if I add this to my `.envrc`:
    ```
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.0"
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules.git//aws/vpc-peering.git?ref=tags/0.29.0"
    source <(tfenv)
    ```

  16. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ We can automatically initialize any [terraform-root-module](https://github.com/c

    For example, if I add this to my `.envrc`:
    ```
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.9"
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.0"
    source <(tfenv)
    ```

  17. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ We can automatically initialize any [terraform-root-module](https://github.com/c

    For example, if I add this to my `.envrc`:
    ```
    TF_CLI_INIT_FROM_MODULE=git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.9
    export TF_CLI_INIT_FROM_MODULE="git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.9"
    source <(tfenv)
    ```

  18. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ One of the biggest pains with terraform is that it's not totally 12-factor compl

    **Have you ever wanted to set the backend config using strictly environment variables?**

    Well, as it turns out _this is possible_ - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    Well, as it turns out _this **is** possible_ - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init="-backend-config=bucket=my-bucket"
  19. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ One of the biggest pains with terraform is that it's not totally 12-factor compl

    **Have you ever wanted to set the backend config using strictly environment variables?**

    Well, as it turns out __this is possible__ - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    Well, as it turns out _this is possible_ - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init="-backend-config=bucket=my-bucket"
  20. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ One of the biggest pains with terraform is that it's not totally 12-factor compl

    **Have you ever wanted to set the backend config using strictly environment variables?**

    Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    Well, as it turns out __this is possible__ - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init="-backend-config=bucket=my-bucket"
  21. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (**III. Config**). That is, terraform doesn't consume environment variables for all settings & parameters.
    One of the biggest pains with terraform is that it's not totally 12-factor compliant ([**III. Config**](https://12factor.net/config)). That is, terraform doesn't consume environment variables for all settings & parameters.

    **Have you ever wanted to set the backend config using strictly environment variables?**

  22. osterman revised this gist Jan 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ One of the biggest pains with terraform is that it's not totally 12-factor compl
    Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init=-backend-config=bucket=my-bucket
    export TF_CLI_ARGS_init="-backend-config=bucket=my-bucket"
    ```

    (Read more [here](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name))
  23. osterman revised this gist Jan 14, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions tfenv.md
    Original file line number Diff line number Diff line change
    @@ -42,11 +42,13 @@ source <(tfenv)
    Now, when I run `terraform init`, it will download the remote module and initialize it all in one fell swoop.

    What I like about this is we can now manage our environment how we want to.
    e.g. using `chamber` or some other tool like `direnv`.


    1. **Manage the enviroment the way we want to.** e.g. using `chamber` or some other tool like `direnv`.
    ```
    source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')
    ```

    We can use the task runner of our choice (e.g. `make`).
    2. **We can use the task runner of our choice** (e.g. `make`, `robo`, [`variant`](https://github.com/mumoshu/variant)).

    ...and we can use vanilla terraform.
    3. **...and we can use vanilla terraform without wrappers.**
  24. osterman revised this gist Jan 14, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,9 @@ Then I can use vanilla `terraform` without any wrappers and just run `terraform

    **But wait, there's more!!!**

    We can do this in our `.envrc`:
    We can automatically initialize any [terraform-root-module](https://github.com/cloudposse/terraform-root-modules).

    For example, if I add this to my `.envrc`:
    ```
    TF_CLI_INIT_FROM_MODULE=git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.9
    source <(tfenv)
  25. osterman revised this gist Jan 14, 2019. No changes.
  26. osterman revised this gist Jan 14, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion tfenv.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,9 @@ Then anytime I call `terraform init`, it will automatically pass the backend set

    **The Problem**

    What I don't like about this is it's difficult to toggle individual parameters without reconstructing the entire env. Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly, then I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`
    The problem with `TF_CLI_ARGS_*` is that it is difficult to toggle individual parameters without reconstructing the entire env.

    Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly, then I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`

    **The Solution**

  27. osterman revised this gist Jan 14, 2019. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions tfenv.md
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,31 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (**III. Config**). That is, terraform doesn't consume environment variables for all settings & parameters.

    Have you ever wanted to set the backend config using strictly environment variables? Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    **Have you ever wanted to set the backend config using strictly environment variables?**

    Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init=-backend-config=bucket=my-bucket
    ```

    (Read more [here](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name))

    Then anytime I call `terraform init`, it will automatically pass the backend setting as a parameter.
    Then anytime I call `terraform init`, it will automatically pass the backend setting as a parameter. This works for all other settings as well.

    **The Problem**

    What I don't like about this is it's difficult to toggle individual parameters without reconstructing the entire env. Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly, then I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`

    It's for this reason, we've added support for this to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv).
    **The Solution**

    It's for this reason, we've added support for setting `TF_CLI_*` environment settings to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv), which will then map them to the `TF_CLI_ARGS_*`.

    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
    source <(tfenv)
    ```

    Then I can use vanilla `terraform` without any wrappers and just run `terraform init`, `terraform plan`, terraform apply`, etc... and they "just work". No wrappers needed (e.g. `terragrunt`).
    Then I can use vanilla `terraform` without any wrappers and just run `terraform init`, `terraform plan`, `terraform apply`, etc... and they "just work". **No wrappers needed (e.g. `terragrunt`).**

    **But wait, there's more!!!**

  28. osterman revised this gist Jan 14, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tfenv.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (**III. Config**). That is, terraform doesn't consume environment variables for all settings & parameters. Have you ever wanted to set the backend config using strictly environment variables?
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (**III. Config**). That is, terraform doesn't consume environment variables for all settings & parameters.

    Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    Have you ever wanted to set the backend config using strictly environment variables? Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```sh
    export TF_CLI_ARGS_init=-backend-config=bucket=my-bucket
  29. osterman revised this gist Jan 14, 2019. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions tfenv.md
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,25 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (III. Config). That is, terraform doesn't consume environment variables for all settings & parameters. Have you ever wanted to set the backend config using strictly environment variables?
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (**III. Config**). That is, terraform doesn't consume environment variables for all settings & parameters. Have you ever wanted to set the backend config using strictly environment variables?

    Well, it turns out this is possible, just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:
    Well, as it turns out this is possible - just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```
    ```sh
    export TF_CLI_ARGS_init=-backend-config=bucket=my-bucket
    ```

    (Read more [here](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name))

    Then anytime I call `terraform init`, it will automatically pass the backend setting.
    Then anytime I call `terraform init`, it will automatically pass the backend setting as a parameter.

    What I don't like about this is it's difficult to toggle individual parameters. What I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`
    What I don't like about this is it's difficult to toggle individual parameters without reconstructing the entire env. Instead, what I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly, then I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`

    It's for this reason, we've added support for this to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv).

    Now, we can do the following (e.g. by adding it to our `.envrc` and using `direnv`):
    Now, we can do the following (e.g. by adding it to our `.envrc` and using [`direnv`](http://direnv.net)):
    ```
    source <(tfenv)
    ```

    Now, I can use vanilla `terraform` without any wrappers and just run `terraform init`, `terraform plan`, terraform apply`, etc... and they "just work". No wrappers (e.g. `terragrunt`).
    Then I can use vanilla `terraform` without any wrappers and just run `terraform init`, `terraform plan`, terraform apply`, etc... and they "just work". No wrappers needed (e.g. `terragrunt`).

    **But wait, there's more!!!**

  30. osterman created this gist Jan 14, 2019.
    41 changes: 41 additions & 0 deletions tfenv.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    One of the biggest pains with terraform is that it's not totally 12-factor compliant (III. Config). That is, terraform doesn't consume environment variables for all settings & parameters. Have you ever wanted to set the backend config using strictly environment variables?

    Well, it turns out this is possible, just in an extremely roundabout way. For example, if we want to set the backend-config bucket using an environment variable, we can do the following:

    ```
    export TF_CLI_ARGS_init=-backend-config=bucket=my-bucket
    ```
    (Read more [here](https://www.terraform.io/docs/configuration/environment-variables.html#tf_cli_args-and-tf_cli_args_name))

    Then anytime I call `terraform init`, it will automatically pass the backend setting.

    What I don't like about this is it's difficult to toggle individual parameters. What I want to do is set `TF_CLI_INIT_BACKEND_CONFIG_BUCKET=my-bucket` and not mess with constructing terraform parameters. Similarly I can set `TF_CLI_PLAN_REFRESH=true` to automatically add `-refresh=true` when calling `terraform plan`

    It's for this reason, we've added support for this to [`cloudposse/tfenv`](https://github.com/cloudposse/tfenv).

    Now, we can do the following (e.g. by adding it to our `.envrc` and using `direnv`):
    ```
    source <(tfenv)
    ```

    Now, I can use vanilla `terraform` without any wrappers and just run `terraform init`, `terraform plan`, terraform apply`, etc... and they "just work". No wrappers (e.g. `terragrunt`).

    **But wait, there's more!!!**

    We can do this in our `.envrc`:
    ```
    TF_CLI_INIT_FROM_MODULE=git::https://github.com/cloudposse/terraform-root-modules/tree/master/aws/vpc-peering.git?ref=tags/0.29.9
    source <(tfenv)
    ```

    Now, when I run `terraform init`, it will download the remote module and initialize it all in one fell swoop.

    What I like about this is we can now manage our environment how we want to.
    e.g. using `chamber` or some other tool like `direnv`.
    ```
    source <(chamber exec $(basename `pwd`) -- bash -c 'export -p')
    ```

    We can use the task runner of our choice (e.g. `make`).

    ...and we can use vanilla terraform.