Add tf_vars input to supply Terraform variable values in CI#22
Merged
Conversation
A Terraform variable declared in variables.tf without a default and without a .tfvars entry makes Terraform prompt for its value on STDIN. That works in an interactive terminal but hangs in CI. The immediate need is to feed an image tag built by a docker-build-and-push-to-ECR job into the apply, which is a per-build value that cannot be committed. Add a tf_vars reusable-workflow input (one KEY=VALUE per line) to plan.yml, apply.yml, base.yml, and detect-drift.yml. base.yml exports the lines to GITHUB_ENV before plan/apply; the tf wrapper inherits the environment, so a TF_VAR_<name> entry reaches Terraform as the value for variable <name>. This mirrors the tf_additional_env_vars input from the FiveXL tf.sh this replaces. The input is passed via env: rather than interpolated into the run script to avoid shell injection. detect-drift.yml accepts the input for consistency, with docs noting that per-build values there cause false drift and should instead be given a default in variables.tf. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
JonJagger
approved these changes
Jun 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A Terraform variable declared in
variables.tfwith no default and no.tfvarsentry makesTerraform prompt for its value on STDIN. That's fine in an interactive terminal but hangs in CI.
The immediate need is to feed an image tag built by a docker-build-and-push-to-ECR job into the
apply — a per-build value that cannot be committed to tfvars or
tf.env.The old FiveXL
tf.shsolved this with atf_additional_env_varsinput that setTF_VAR_*envvars. This PR builds the equivalent.
Approach
The
tfwrapper needs no change — it already forwards the whole environment to Terraform viaos.execvp, so anyTF_VAR_*env var in the job reaches Terraform. This PR only adds a way to getvalues into that environment from the calling workflow.
base.yml— newtf_varsinput plus anExport Terraform variablesstep that appends thelines to
$GITHUB_ENVbefore Plan (visible to both Plan and Apply). Passed viaenv:rather thaninterpolated into the run script, to avoid shell injection.
plan.yml/apply.yml— add the input and thread it intobase.yml.detect-drift.yml— accepts the input for consistency.README.md— new "Supplying Terraform variables" section with the docker-build → apply ECRexample, the non-secret caveat, pointers to the static-value alternatives, and the drift caveat.
Usage
Caveats
tf_varsis for non-sensitive values — inputs are not masked. Secrets should not go through it.detect-drift.yml's planfail, and a fixed tag there produces false drift. The fix lives in the caller's Terraform (a
default in
variables.tfand/orlifecycle { ignore_changes = [...] }). Documented, notauto-solved, since it's outside this repo.
Verification
actionlint .github/workflows/*.yml— clean.🤖 Generated with Claude Code