1

I have a terraform file:

terraform {
  required_version = "1.3.5"
}


locals {
  a = "foo"
  b = "bar"
}

in a bash terminal, I can do:

$ echo "local.a" | terraform console
"foo"
$ echo "local.b" | terraform console
"bar"

Now what I'm trying to do is start a process running terraform console in the background and feed it commands.

This is what I've tried (following this answer https://serverfault.com/a/815253):

$ mkfifo /tmp/srv-input
$ tail -f /tmp/srv-input | terraform console >>output.txt 2>&1 &

this starts the background process correctly:

$ ps -ax | grep terraform
6030 pts/0    Sl     0:01 terraform console

if I then run:

$ echo "local.a" > /tmp/srv-input

the output file, output.txt is empty.

$ cat output.txt
$ 

If I run:

$ echo "local.c" > /tmp/srv-input # invalid input

the output file, output.txt contains the (expected) error:

$ cat output.txt
╷
│ Error: Reference to undeclared local value
│
│   on <console-input> line 1:
│   (source code not available)
│
│ A local value with the name "c" has not been declared. Did you mean "a"?
╵

[1]+  Exit 1                  tail -f /tmp/srv-input | terraform console >> output.txt 2>&1

Why is only the stderr being redirected to the log file, but not stdout?

3
  • Perhaps the two streams are being buffered differently (stderr line-buffered but stdout block-buffered)? Commented Dec 15, 2022 at 15:40
  • @steeldriver if that was the case, how can I achieve what I'm after? Commented Dec 16, 2022 at 11:25
  • Potentially relevant answer. Commented Dec 20, 2022 at 9:23

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.