Skip to content

RossyWhite/tfsubst

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

tfsubst

tfstate substitution tool like envsubst.

Usage

tfsubst substitutes all variables in the file with the values from the tfstate.

$ tfsubst -s <tfstate-file> -i <input-file>

Example

If you have a template file below

# input.yaml
value: {{ tfstate "aws_ssm_parameter.your_parameter.value" }}

and your tfstate is in s3://yourbucket/terraform.tfstate

then the output file will be

$ tfsubst -s s3://yourbucket/terraform.tfstate -i input.yaml -o output.yaml
# output.yaml
value: your_parameter_value

Installation

From binary

Download the binary from GitHub Releases and drop it in your $PATH.
Or one-liner installation command is below.(jq is required)

$ curl -sfL https://raw.githubusercontent.com/RossyWhite/tfsubst/main/install.sh | sh

With Go

$ go install github.com/rossywhite/tfsubst@latest

Docker

$ docker pull ghcr.io/rossywhite/tfsubst:latest

Use in GitHub Actions

- name: run tfsubst
  uses: RossyWhite/tfsubst@v0.0.4
  with:
    input: <your input file path>
    output: <your output file path>
    tfstate: <your tfstate file path>