-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
terraform console
can't be scripted as outputing some messages on stdout
#35817
Comments
Thanks for this report! |
Will be a suitable solution to output warnings to the stderr or just add |
I'm also looking for a way to get around this. To give my use case, I've been using things like FOO=$(terraform console <<< var.foo) to grab the value of |
So I think a potential workaround is by always using jsonencode (to force the output to be exactly one line) and piping through # returns something appropriate for passing to jq
function tf_query_json () {
terraform console <<< "jsonencode($1)" | tail -n 1 | jq -r .
}
# returns "raw" output (no quotes or escaping)
function tf_query_raw () {
tf_query_json "$1" | jq -r .
} Because terraform is double escaping string output, the extra tf_query_raw '"hello world"'
tf_query_raw '0.5'
tf_query_raw '1'
tf_query_raw '["a", "b", "c", "d"]'
tf_query_json '["a", "b", "c", "d"]' | jq -r '.[2]'
tf_query_json '{foo="bar"}'
I wish this is how |
Terraform Version
Terraform Configuration Files
N/A
Debug Output
N/A
Expected Behavior
Only output console result on stdout in order to be able to parse output.
Actual Behavior
When warning (or may be other cases) are emitted, they are also printed on stdout:
Command:
Stdout:
Also tried with
TF_IN_AUTOMATION=true TF_LOG=off
same result.Steps to Reproduce
terraform init
terraform console <<<'jsonencode(local.test)'
Additional Context
N/A
References
N/A
The text was updated successfully, but these errors were encountered: