https://pulumi.com logo
Title
e

enough-caravan-98871

03/21/2023, 1:06 AM
I am having trouble escaping a single backslash for a UNC path.
export const var = pulumi.concat("\\", storageAccount.name, ".<http://file.core.windows.net|file.core.windows.net>\", fileShare.name);
The backslash after .net is what I am wanting to keep and having trouble with. Anyone know how to accomplish this?
l

little-cartoon-10569

03/21/2023, 1:56 AM
Does \\ not work?
e

enough-caravan-98871

03/21/2023, 1:57 AM
No, it produces \\. That is what I have in the beginning and desire it there. After the .net, I desire a single \ but cannot get it to go.
l

little-cartoon-10569

03/21/2023, 1:58 AM
What language is it? Is there a different quote character?
e

enough-caravan-98871

03/21/2023, 1:59 AM
typescript
i want an output of a UNC path, like \\<storageAccountName.file.core.windows.net\<shareName>.
l

little-cartoon-10569

03/21/2023, 2:00 AM
When I run
console.log("\\");
I see
\
e

enough-caravan-98871

03/21/2023, 2:01 AM
When I use a single backslash like what I have in the original example after .net, it makes what comes after it (fileShare.name) raw text. I am unable to escape it.
That may be true with console.log. Not how it is working in Pulumi and typescript.
My first part of "\\" shows \\ and I desire it there. I have tried three \\\, four \\\\, etc. No dice.
l

little-cartoon-10569

03/21/2023, 2:04 AM
Are you using typescript? That behaviour differs from what I'm seeing.
e

enough-caravan-98871

03/21/2023, 2:06 AM
yes, I am using typescript in Pulumi.
Her is a line with no issues.
export const fslProfilesUnc = pulumi.concat("\\", storageAccount.name, ".<http://file.core.windows.net|file.core.windows.net>", fileShareProfiles.name);
Need to get a '\' after the '.net'.
l

little-cartoon-10569

03/21/2023, 2:08 AM
Try another "\\", instead of "x.y.net\\".
Honestly, this is too weird to explain 🙂
e

enough-caravan-98871

03/21/2023, 2:11 AM
No go. It produces two \\ in output just like it does in the beginning.
+ fslProfilesUnc: "\\saf0de4e4c\\profiles"
Goofy for sure! 😀
l

little-cartoon-10569

03/21/2023, 2:15 AM
Could it be something to do with your editor? Is the file being transformed in some way? "\\" is definitely the correct way to produce a single backslash in JS/TS; could there be something odd in your environment?
You could try using '\\'?
There may be a file separator constant that you could use?
e

enough-caravan-98871

03/21/2023, 2:16 AM
The way I see it, if I want a \\, it should be \\\\ and if I want a single \, it should be \\.
l

little-cartoon-10569

03/21/2023, 2:17 AM
How about importing path and using
path.sep
?
e

enough-caravan-98871

03/21/2023, 2:18 AM
I am not that fluent. lol
l

little-cartoon-10569

03/21/2023, 2:18 AM
import * as path from "path";
console.log(path.sep);
On Windows, path.sep will be
\
It removes portability unfortunately; you won't be able to build UNC paths on non-Windows machines.
Have you checked that
storageAccount.name
doesn't start with
\
?
If it does, then "\\" is correctly generating
\
e

enough-caravan-98871

03/21/2023, 2:21 AM
no it does not start with \
I am already successfully generating \\ with "\\", no issue. I am just unable to generate a single \. Windows should not matter. I am not trying to use a UNC path yet, in which case it would only work on a Windows OS; understood. I am simply trying to out a text string that represents a UNC path here.
l

little-cartoon-10569

03/21/2023, 2:24 AM
Yes. We have a weird issue, which is that "\\" is generating
\\
, which it doesn't do for anyone else. I can't help with that, you'll have to figure that one out yourself. My current suggestion is to get
path.sep
and use it when building your string. On Windows machines,
path.sep
is
\
, so it should do the job.
BTW, what is
pulumi.concat()
? I haven't seen that before.
Ah, I looked it up. It's like interpolate. You could try switching to interpolate, maybe there's a bug in pulumi.concat?
export const var = pulumi.interpolate`\\\\${storageAccount.name}.<http://file.core.windows.net|file.core.windows.net>\\${fileShare.name}`
e

enough-caravan-98871

03/21/2023, 2:30 AM
Going to sleep on it. Thanks!
l

little-cartoon-10569

03/21/2023, 2:30 AM
I'm a Puluminary. Quite familiar with Pulumi 🙂
No worries, I'm here to help.
e

enough-caravan-98871

03/21/2023, 2:32 AM
Screenshot 2023-03-20 at 10.31.57 PM.png
l

little-cartoon-10569

03/21/2023, 2:33 AM
You'll need to put in a valid variable name. I used the same example as you provided at the top of the thread.
e

enough-caravan-98871

03/21/2023, 2:36 AM
Those are valid variable names. It is the position of your \\\\ that is throwing it off.
l

little-cartoon-10569

03/21/2023, 2:37 AM
var
is an identifier in typescript, not a valid variable name.
Try "x"
e

enough-caravan-98871

03/21/2023, 2:40 AM
You are correct.
I am familiar with pulumi.interpolate and use it often. I thought you nailed it for a minute. I have tried several different combinations with it. Same issue with the single \ whether using pulumi.interpolate or pulumi.concat.
export const x = pulumi.interpolate`\\\\${storageAccount.name}.<http://file.core.windows.net|file.core.windows.net>\\${fileShareProfiles.name}`
is valid code and produces the following output: '\\\\fqdn\\share'.
l

little-cartoon-10569

03/21/2023, 3:30 AM
Ah yes, sorry, my bad. In backticks, you don't need to quote backslashes.
e

enough-caravan-98871

03/21/2023, 3:32 AM
What do you mean?
export const x = pulumi.interpolate`\\${storageAccount.name}.<http://file.core.windows.net|file.core.windows.net>\${fileShareProfiles.name}`
turns
$fileShareShareProfiles.name
to a string and produces the following output: '\\fqdn${fileShareProfiles.name}'.
It is the same issue with the not being able to escape the single \ as when we were using
pulumi.concat
.
l

little-cartoon-10569

03/21/2023, 4:19 AM
"\$" quotes the $, which breaks the interpolation. "\\" is supposed to escape the "\" but it's not, for you. Can you confirm that this sort of this is happening for you with strings that are not Outputs? What does this output?
const simpleString = "foo";
const slashyString = "x\\y";
console.log(`\\ ${simpleString} Continue ${slashyString} \\`);
That issue you posted seems to be exactly what you're encountering.
So it looks like you're foiled for now, unless you find a clever workaround, maybe regex-replacing or something.
e

enough-caravan-98871

03/21/2023, 6:21 AM
The console log works just fine, but need a Pulumi output. /smh
str = '\\'
console.log(str);
output = '\'
Pulumi does not like a single '\' in a string. I tried atChar(index) to try to extract a single character of '\' and then use that as a variable in my complete string. It inserts it as a double '\\'. I tried putting a var of '\' in my stack config and then using that as a variable in my complete string. It still inserts the double '\\'.
l

little-cartoon-10569

03/21/2023, 8:08 AM
You will have to upvote that GitHub issue, and work around the problem some other way. Maybe create the resource inside an apply in order to bypass Pulumi's intervention?
e

enough-caravan-98871

03/21/2023, 5:17 PM
@little-cartoon-10569 I am happy to report that with more testing, what you gave me last does essentially work. It is deceiving as when you
pulumi up
to create the output, the output value on the screen is not what is expected. However, if I then run a
pulumi stack output
or observe the output from the web app, it is exactly what I need it to be with the extra backslashes removed.
export const fslShare = pulumi.interpolate`\\\\${storageAccount.name}.<http://file.core.windows.net|file.core.windows.net>$\\${fileShareProfiles.name}`;
That produces
+ fslShare: "\\<http://name.core.windows.net|name.core.windows.net>\\profiles"
on screen after
pulumi up
. However, the stack output is
fslShare  \\<http://name.file.core.windows.net|name.file.core.windows.net>$\profiles
. A misread that had me chasing something for nothing.
l

little-cartoon-10569

03/21/2023, 7:03 PM
Good stuff! 🎉 Would you like to add a comment to that GitHub issue with your findings? It may help them resolve the issue faster.