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

orange-tailor-85423

02/11/2019, 8:02 PM
g

gorgeous-egg-16927

02/11/2019, 8:05 PM
Do you have a link to this example? It looks like that may have been auto-generated from a TF example
o

orange-tailor-85423

02/11/2019, 8:06 PM
sure
hold please….
w

white-balloon-205

02/11/2019, 8:07 PM
o

orange-tailor-85423

02/11/2019, 8:08 PM
oh interesting
w

white-balloon-205

02/11/2019, 8:08 PM
The variable being the same name will be fixed once https://github.com/pulumi/tf2pulumi/pull/60 is rolled out to all the providers (next day or two).
w

white-balloon-205

02/11/2019, 8:09 PM
You should be able to just rename one of them for now.
o

orange-tailor-85423

02/11/2019, 8:09 PM
yeah ok - makes sense
just so I understand, this call isn’t using the node sdk?
just the native Pulumi stuff which brought it in from TF?
w

white-balloon-205

02/11/2019, 8:10 PM
Yes - this is just a native Pulumi SDK thing - documented at the link above.
o

orange-tailor-85423

02/11/2019, 8:11 PM
roger
will that regenerate the docs?
example still doesn’t work
type mismatch
g

gorgeous-egg-16927

02/11/2019, 8:28 PM
@white-balloon-205 It looks like the
getAccountKeyArgs
are expecting a
string
rather than an
Input<string>
for the name. Seems like that example wouldn't work without updating that type as well
o

orange-tailor-85423

02/11/2019, 8:31 PM
I think this will work?
const sysdigAccountDef = iam.createServiceAccount( config.project, config.containerSecurityScanner ); const sysdigAccountKey = new gcp.serviceAccount.Key(“sysdigkey”, { serviceAccountId: sysdigAccountDef.name }); const sysdigGetAccountKey = pulumi.output( gcp.serviceAccount.getAccountKey({ name:
Copy code
projects/${projectNumber}/serviceAccounts/${
        sysdigAccountDef.accountId
      }/keys/${sysdigAccountKey.id}
, publicKeyType: “TYPE_X509_PEM_FILE” }) );
not sure about that last attribute of the key name/path
example says it wants the id of the key but the id I show above is a Pulumi ID
w

white-balloon-205

02/11/2019, 8:38 PM
This works for me:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const myaccount = new gcp.serviceAccount.Account("myaccount", {
    accountId: "dev-foo-account",
});
const mykeyKey = new gcp.serviceAccount.Key("mykey", {
    serviceAccountId: myaccount.name,
});
const mykeyAccountKey = mykeyKey.name.apply(keyname => gcp.serviceAccount.getAccountKey({
    name: keyname,
    publicKeyType: "TYPE_X509_PEM_FILE",
}));

export const publicKey = mykeyAccountKey.apply(hmm => hmm.publicKey);
👍 1
o

orange-tailor-85423

02/11/2019, 8:41 PM
You do it that way so you aren’t dealing with output strings?
the apply is taking the object and “converts” to string?
ok interesting
what’s the accepted programming model for doing an export like the above inside a conditional
i.e. if (some criteria) do the above
sorry this is Typescripty stuff, not Pulumi
w

white-balloon-205

02/11/2019, 8:45 PM
Copy code
export let foo;
if (something) {
  foo = mykeyAccountKey.apply(hmm => hmm.publicKey);
}
Or set another default value in the initializer if that makes sense.
o

orange-tailor-85423

02/11/2019, 8:45 PM
ah ok
sure I’ll give it a go
basically trying to figure out a way to export the JSON creds file for service accounts