npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tf-output

v1.8.3

Published

Fetch terraform output

Downloads

5,147

Readme

Coverage Status

tf-output

Fetches terraform outputs and lets you:

  • print them to stdout in different formats
  • call another command with them exposed in the environment
  • export them to your current shell

Getting Started

You need to install this module and then run it's command from somewhere that has a property initialized terraform environment.

Install

npm install -g tf-output

Usage

Assuming you have a module called database.tf with an output called DATABASE_URL in a folder called terraform/database and you have already set up terraform...

Examples

tf-output database

Would print out something like:

DATABASE_URL="http://database.totallysecure.com"

And:

tf-output database -- node src/app.js

Would call node src/app.js with the DATABASE_URL available in the process environment.

You can also

export $(tf-output database)

Which will populate outputs in to your current shell.

Configuration

Module

-m or --module specifies which module to obtain output from. -m alone uses the dir name as the value. So

tf-output api -m

calls terraform output -m api in terraform/api

Output Format

-f or --format allows you to specify an alternate output format, currently json is supported. This flag is ignored if a command is specified.

Backend Initialization

-a or --auto-init allows you to auto-initialize terraform (terraform init) prior to copying outputs.

-g or --auto-init-get will pull down modules mentioned in the root module during auto-initialization.

-i or --init-opts allows you to pass additional options to terraform init (e.g. -backend-config).

Output Flattening

-fl or --flatten will flatten output values that are objects by concatenating key names.

-fd or --flatten-delimiter allows you to specify the delimiter to use while concatenating key names (_ by default).

Advanced Configuration

Plan Check

-c or --check-plan checks if terraform plan has any unapplied changes (and aborts if it does).

-o or --plan-opts allows you to pass additional options to terraform plan (e.g. -var-file).

Path Template

-p or -path specifies a path template. tf-output looks for modules according to a path template, which by default is terraform/{dir} - so tf-output api database would look for a module in two directories:

  • terraform/database
  • terraform/api

You can use more complex path templates. Imagine you deploy your app using the following command:

deploy --stage=dev --region=us-east-1

You might organize your terraform definitions in a number of ways and you can customize where tf-output looks to suit your needs.

tf-output database -p {stage}/{region}/terraform/{dir}

This command would fail, because while it knows the module you are trying to load, it doesn't know what stage and region should be.

You can specify them:

tf-output database api -p {stage}/{region}/terraform/{dir} --stage=dev --region=us-east-1

This would cause tf-output to load modules from:

  • dev/us-east-1/terraform/api
  • dev/us-east-1/terraform/database

If you run a command through tf-output, it will look ahead for substitution values. This works the same:

tf-output database api -p {stage}/{region}/terraform/{dir} -- deploy --stage=dev --region=us-east-1

Except instead of printing the outputs out to stdout, it would exec deploy --stage=dev --region=us-east-1 with environment variables set, and the path template would still be substituted with the right stage and region. This saves you havin to repeat region, stage, etc.

.tfoutput

In many cases the arguments you will specify to tf-output are always going to be the same, for example the -p path template argument. You can put these in a .tfoutput file which will be read on every execution.

Example .tfoutput file:

{
	"path": "terraform/{dir}/{stage}/{region}",
	"module": true,
	"auto-init": true,
	"auto-init-get": true
}