Last active
August 9, 2019 15:51
-
-
Save carbonrobot/7b20c45ee57b8e72627817a5f334efa7 to your computer and use it in GitHub Desktop.
Exports Terraform outputs into an environment file that can be sourced into shell
This file contains hidden or 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
# Exports Terraform outputs into an environment file that can be sourced into shell | |
# Supports Terraform 0.12+ (also works with Terragrunt 19+) | |
# | |
# It can be useful to export tf outputs into a .env file for use with serverless, jenkins, and node | |
# to use with tools that directly support dotenv, remove the "export " from the prefix | |
# | |
# Steps | |
# 1. Gets the terraform output | |
# 2. Add quotes to the right hand side of equals | |
# 3. Remove spaces around equal signs | |
# 4. Add a prefix for the env variables | |
# 5. Output to a dotenv file that can be loaded with source command or dotenv tools | |
terraform output | sed 's/\(=[[:blank:]]*\)\(.*\)/\1"\2"/' | sed -r 's/\s+//g' | sed 's/^/export TF_OUTPUT_/' >> .env |
This file contains hidden or 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
./export.sh | |
source .env | |
# All TF_OUTPUTS are now available |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uppercase version