few-carpenter-12885
10/12/2022, 5:19 PMOutput<string>
types. I'm dealing with a MongoDB URI, db name, and an associated username/password. I have all 4 of these as outputs, and i am trying to form them into a proper MongoDB connection string. This involves taking the URI in the format <mongodb+srv://mycluster.randomchars.mongodb.net>
and inserting the username/password to form this format: mongodb+srv://<username>:<password>@mycluster.randomchars.mongodb.net/<dbName>
.
The problem I have is that I need to do some sort of replace in order to retain the mycluster.randomchars
section of the URI - this means that pulumi.interpolate
is not sufficient for my use-case. Any suggestions where I can go from here? Just keep them separate and form them properly in the application?billowy-army-68599
10/12/2022, 5:20 PMapply
- once you’re inside the apply
you can manipulate the string as you would any other stringuri
have the random string in there?few-carpenter-12885
10/12/2022, 5:22 PMusername:password@
section after the mongodb+srv://
section.replace
function within an apply. Let me see if I can get back to that point.little-library-54601
10/12/2022, 5:29 PMsqlServerOutput
which is of type:
Output.Tuple<string, string, string> // aka
Output<(string, string, string)>
Using .Apply
looks like:
// Server=tcp:{server-name}.<http://database.windows.net|database.windows.net>,1433;Initial Catalog={db-name};Persist Security Info=False;User ID={login-name};Password={login-password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
return sqlServerOutput.Apply(t =>
{
(string server, string loginId, string loginPassword) = t;
return sqlDatabase.Name.Apply(finalDbName =>
$"Server=tcp:{server}.<http://database.windows.net|database.windows.net>,1433;Initial Catalog={finalDbName};Persist Security Info=False;User ID={loginId};Password={loginPassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
);
});
sqlDatabase.Name
is another Output<string>
few-carpenter-12885
10/12/2022, 5:30 PMconst mongoDbUri = pulumi
.all([db.uri, db.user, db.password, db.name])
.apply(([uri, user, password, name]) => {
const [prefix, suffix] = uri.split('//')
return `${prefix}//${user}:${password}@${suffix}/${name}`
})
billowy-army-68599
10/12/2022, 5:31 PM