https://pulumi.com logo
#general
Title
# general
p

polite-motherboard-78438

03/14/2020, 6:15 PM
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

faint-table-42725

03/14/2020, 8:09 PM
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

polite-motherboard-78438

03/15/2020, 10:20 AM
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

faint-table-42725

03/15/2020, 4:53 PM
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

polite-motherboard-78438

03/21/2020, 3:54 PM
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

faint-table-42725

03/23/2020, 3:12 AM
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

polite-motherboard-78438

04/18/2020, 10:23 AM
Thanks. it works now