https://pulumi.com logo
#general
Title
# general
g

gorgeous-salesmen-27957

12/21/2023, 7:26 PM
I have another question. I'm not sure if I'm just "doing it wrong" but I would expect this to output "my host is: <hostname>" but the value for the hostname is empty:
Copy code
pulumi env run myorg/databricks-foo -- echo "my host is: $DATABRICKS_HOST"
considering my environment looks like this:
Copy code
values:
      databricks:
        host: https://<hostname here>
      environmentVariables:
        DATABRICKS_HOST: ${databricks.host}
      pulumiConfig:
        databricks:host: ${databricks.host}
when I run:
Copy code
eval `pulumi env get myorg/databricks-foo --value shell`
and then
Copy code
echo "my host is: $DATABRICKS_HOST"
I get the expected output. I would expect
pulumi env run
to make the env vars available to the command its running, but that's not the behavior I'm seeing.
even when I run
Copy code
pulumi env run myorg/databricks-foo -- env
I see the expected values there, but when I try to use them, they are empty, happens regardless which command I'm running
l

little-cartoon-10569

12/21/2023, 7:28 PM
Are you running this from the shell?
The problem is most likely that your shell is resolving the env vars before you want them resolved.
You need to prevent your shell from parsing the env vars, and ensure that the pulumi-spawned shell does it.
g

gorgeous-salesmen-27957

12/21/2023, 7:30 PM
yeah, I'm using zsh
l

little-cartoon-10569

12/21/2023, 7:30 PM
So you'll need to quote things appropriately so that zsh doesn't do that work.
g

gorgeous-salesmen-27957

12/21/2023, 7:33 PM
hmm, even when do
Copy code
pulumi env run myorg/env -- echo "host: ${DATABRICKS_HOST}"
?
how else would the quoting need to be done?
l

little-cartoon-10569

12/21/2023, 7:34 PM
Yes, that won't work, because double-quoted strings are parsed by the current shell. The value has already been substituted before the shell invokes pulumi.
I don't know the correct solution, other than to not use a shell to invoke this. You could set the env var to be a function that just gets the real value, but I don't think that's what you want.
You could use an alias. That might do things in the right order
g

gorgeous-salesmen-27957

12/21/2023, 7:35 PM
for now, I'm just doing
Copy code
eval `pulumi env run ... --value shell`
which works
running that before the other bits that require the values
l

little-cartoon-10569

12/21/2023, 7:36 PM
Yes, because the env var isn't being substituted by your interactive shell
d

dry-keyboard-94795

12/21/2023, 7:38 PM
Can you try escaping the dollar,
$$DATABRICKS_HOST
g

gorgeous-salesmen-27957

12/21/2023, 7:38 PM
it's weird because I can do the same thing with tools like chamber and don't have the same issue. Like this.
l

little-cartoon-10569

12/21/2023, 7:38 PM
Which example on that page?
g

gorgeous-salesmen-27957

12/21/2023, 7:39 PM
sorry, I was trying to link to the section on
Exec
l

little-cartoon-10569

12/21/2023, 7:39 PM
In zsh isn't the escape
\$
? Or you could turn your double-quotes into single-quotes. I'm not optimistic though, since prevent the outer shell parsing the var would presumably also prevent the pulumi-spawned shell from doing it.
g

gorgeous-salesmen-27957

12/21/2023, 7:39 PM
when I do the double-dollar it looks like the first
$
is being sub'd w/ the proc:
Copy code
my host is 38389{DATABRICKS_HOST}
l

little-cartoon-10569

12/21/2023, 7:39 PM
Yes,
$$
is wrong.
pulumi env
works exactly the same was as the page you linked. chamber will have exacty the same problem if you use env vars on the command line. This isn't a problem with pulumi or chamber, it's a problem with the order of evaluation of env vars.
Which is a shell thing.
d

dry-keyboard-94795

12/21/2023, 7:41 PM
It depends how pulumi is running the command. If they're wrapping in a shell, single quotes will work (or escaping). Otherwise, you'll need to wrap the command with
sh -c 'your command here'
g

gorgeous-salesmen-27957

12/21/2023, 7:42 PM
what I'm saying is that when I run
Copy code
chamber exec <ns> -- echo "my host is $DATABRICKS_HOST"
I get the expected output
l

little-cartoon-10569

12/21/2023, 7:42 PM
Yes, if evaluating the escaped values "unescapes" them for the next shell, that would be good.
That must be because DATABRICKS_HOST has the correct value in your current shell.
g

gorgeous-salesmen-27957

12/21/2023, 7:44 PM
I've made sure to
unset DATABRICKS_HOST
l

little-cartoon-10569

12/21/2023, 7:45 PM
Then I don't know how that works. It defies my knowledge of shells and parsing. I know it would work if it was being run from something other than an interactive shell (I do that sort of thing in my package.json files all the time), but once the interactive shell gets involved, the rules change.
But Anthony's solution should work?
g

gorgeous-salesmen-27957

12/21/2023, 7:47 PM
yep, that works
d

dry-keyboard-94795

12/21/2023, 7:54 PM
Which, wrapping in
sh -c
?
g

gorgeous-salesmen-27957

12/21/2023, 7:56 PM
yeah, wrapping in
sh -c
-- this:
Copy code
pulumi env run myorg/myenv -- sh -c 'echo my host is: $DATABRICKS_HOST'
thanks for your help friends 🙂