https://pulumi.com logo
#typescript
Title
# typescript
f

famous-bear-66383

06/18/2020, 2:41 PM
Quick question: How to convert
pulumi.Output<string>
to a
string
? given
Copy code
const pass = new random.RandomPassword("password", { length: 20, special: true },{additionalSecretOutputs: ["password"]}).result;
I want to use
pass
as a string to set other resources.
Copy code
const dbuser = new gcp.sql.User(`${user}-database-user`, {
    instance: instanceName,
    name: user,
    password: pass.apply(p => p.toString()),
    host: "cloudsqlproxy~%"
});
using
apply
like the following throughs errors
Copy code
pass.apply(p => p.toString()
r

rich-napkin-40911

06/18/2020, 2:44 PM
The only way I found is to use `pulumi.interpolate`; I also couldn't make
apply
work; something like
Copy code
const dbuser = new gcp.sqlUser('...', {
  // ...,
  name: pulumi.interpolate`${name}`,
});
f

famous-bear-66383

06/18/2020, 3:03 PM
When I use what u suggest I got
Argument of type 'Output<string>' is not assignable to parameter of type 'string
interpolate
returns
Output<string>
so it doesn’t really solve my issue
r

rich-napkin-40911

06/18/2020, 3:08 PM
But usually, you should be able to use
Output<string>
as input... 🤔
f

faint-table-42725

06/18/2020, 3:47 PM
You should be able to pass this directly in like
password: pass
— did you get an error doing that?
f

famous-bear-66383

06/18/2020, 7:40 PM
I had a wrapper function on top of it. like this
Copy code
export function AddDBUser(user: string, pass: string, instanceName: string){ 
    return new gcp.sql.User(`${user}-database-user`, {
    instance: instanceName,
    name: user,
    password: pass,
});
}
The error was coming from that function. once I changed the arguments to
pulumi.Input<string>
it worked.
f

faint-table-42725

06/18/2020, 10:03 PM
ah, okay — makes sense
3 Views