I have another question. I'm not sure if I'm just ...
# general
g
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
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
yeah, I'm using zsh
l
So you'll need to quote things appropriately so that zsh doesn't do that work.
g
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
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
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
Yes, because the env var isn't being substituted by your interactive shell
d
Can you try escaping the dollar,
$$DATABRICKS_HOST
g
it's weird because I can do the same thing with tools like chamber and don't have the same issue. Like this.
l
Which example on that page?
g
sorry, I was trying to link to the section on
Exec
l
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
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
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
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
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
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
I've made sure to
unset DATABRICKS_HOST
l
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
yep, that works
d
Which, wrapping in
sh -c
?
g
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 🙂