Awesome
tfrstate (Terraform Remote State)
CLI to find directories where changed terraform_remote_state data source is used.
You can warn changes of Terraform Output Values in CI:
You can also create pull requests via CI to reflect changes of Output Values to Terraform Root Modules:
Overview
When Terraform Output Values are updated, you would want to reflect the update to Terraform Root Modules where referring those values via terrform_remote_state
data sources.
Or when you remove Terraform Output Values, you would want to know which Terraform Root Modules are depending on those values.
tfrstate is a CLI to find Terraform Root Modules depending on a given Terraform State via terraform_remote_state
.
Using this tool, you can look into the dependency, notifying to people when changing output values in CI, and creating pull requests to reflect changes of output values after applying changes.
Supported Backends
How To Use
- Check directories where a specific output is used.
tfrstate find -s3-bucket mybucket -s3-key path/to/my/key -output foo
- Post a comment when outputs are changed in CI
terraform plan -out plan.out
terraform show -json plan.out > plan.json
tfrstate find -plan-json plan.json -base-dir "$(git rev-parse --show-toplevel)" > result.json
length=$(jq length result.json)
if [ "$length" -eq 0 ]; then
exit 0
fi
# Post a comment
To post comments, github-comment is useful.
- Create pull requests after running
terraform apply
terraform apply -auto-approve plan.out
while read -r dir; do
echo "[INFO] Creating a pull request: $dir" >&2
# Create a pull request
done < <(jq -r ".[].dir" result.json)
Output Format
[
{
"dir": "A directory where depending on changed outputs. A relative path from the base directory",
"files": [
{
"path": "A file depending on changed outputs. A relative path from dir",
"outputs": [
"changed output name"
]
}
]
}
]