tfstate substitution tool like envsubst
.
tfsubst
substitutes all variables in the file with the values from the tfstate.
$ tfsubst -s <tfstate-file> -i <input-file>
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
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
$ go install github.com/rossywhite/tfsubst@latest
$ docker pull ghcr.io/rossywhite/tfsubst:latest
- 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>