hello. how can i convert an Ouput<String> to...
# general
p
hello. how can i convert an Ouput<String> to a simple string? I need it in th following example. The "members" array is a []string but the interpolate function always returns an Output<String>.
Copy code
const member = pulumi.interpolate`serviceAccount:${serviceAccount.email}`;
const policyData = gcp.organizations.getIAMPolicy({
  bindings: [
    {
      role: "roles/storage.admin",
      members: [member]
    }
  ]
});
f
You should be able to wrap the
get
itself within an apply, e.g.
Copy code
policyData = serviceAccount.email.apply(email =>
    gcp.organizations.getIAMPolicy(...))
(policyData will now be an
Output<GetIAMPolicyResult>
which you can use elsewhere
p
cool. it works 👍
well, I need to add another service account from another property. How can I do it with this solution?
Copy code
const policyData = serviceAccount.email.apply(email =>
  gcp.organizations.getIAMPolicy({
    bindings: [
      {
        role: "roles/storage.admin",
        members: [
          "serviceAccount:" + email,
          "serviceAccount:" + gcpServiceAccount
        ]
      }
    ]
  })
);

const bucketPolicy = new gcp.storage.BucketIAMPolicy("velero", {
  bucket: bucket.id,
  policyData: policyData.policyData
});
f
You can use
pulumi.all
— you might want to take a look at https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs if you haven’t already
p
I stumbled upon
pulumi.all
in the unit tests documentation today Will try
Not sure if I am using correctly:
Copy code
const policyData = pulumi
  .all([serviceAccount.email, gcpServiceAccount])
  .apply(([veleroServiceAccount, gcpServiceAccount]) => {
    gcp.organizations.getIAMPolicy({
      bindings: [
        {
          role: "roles/storage.admin",
          members: [
            "serviceAccount:" + veleroServiceAccount,
            "serviceAccount:" + gcpServiceAccount
          ]
        }
      ]
    });
  });
But now policyData is an instance of
pulumi.OutputInstance<void>
and not
Output<GetIAMPolicyResult>
f
The compiler sees
=> { … }
as a void function. You should remove that extra set of braces and it should give you back what you want.
p
Thanks. it works now