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

brave-angle-33257

10/12/2018, 6:49 PM
missing something here.. I'm creating a resource in Azure, and I want the principal ID of that item, it's an output.. but it's giving me back a function. I realize that's because its' from a promise of some type, but how do i get the value as an output? it says I can't use
.get()
during an update.. is this where I'd use
apply()
instead?
so it's only available as an output, and not say for console log?
im creating a bunch of Identities, but I need the output of the identity.principalId, I was trying to create an object of all the identities to export out
w

white-balloon-205

10/12/2018, 7:00 PM
Yes - this is where you use
.apply
. To log it out, you can do
.apply(console.log)
. To transform the value to use in some other way, do
.apply(id => “hello: “ + id)
b

brave-angle-33257

10/12/2018, 7:00 PM
this is the base idea im going for:
Copy code
for role in roles:
  for region in regions:
     let uai = new azure.msi.UserAssignedIdentity()
     output[`${role}:${region}`] = uai.principalId

export let output_mapping = output;
w

white-balloon-205

10/12/2018, 7:02 PM
That should work fine as is. What do you see when you do
Pulumi stack output
?
b

brave-angle-33257

10/12/2018, 7:02 PM
Copy code
- uai:[object Object]:resources   : [
                  -     [0]: "st:inf3bootstrapwus:bootstrap"
                  -     [1]: "kv:inf3bootstrapwus"
                    ]
thats the preview output, let me try
pulumi stack output
Copy code
"weu":{"uai:[object Object]:resources":["st
w

white-balloon-205

10/12/2018, 7:05 PM
Not sure I quite follow how that’s related to the code snippet above - do you have the complete (or a small repro) code that is hitting this?
b

brave-angle-33257

10/12/2018, 7:06 PM
sure, running couple tests now that i know it should work
i was trying to use the principal id as an interpolated string template var
that seems to be the issue
this worked, where uai.principal gets assigned as the value pushed to an array
Copy code
Utils._add_to_output(output_list, role, env_id, region, `kv:${vault_name_parsed}`, uai.principalId)
but this didnt
Copy code
Utils._add_to_output(output_list, role, env_id, region, `uai:${String(uai.principalId)}:resources`, `st:${storage_account_name_parsed}:${container.name}`)
where I was trying to use the output in a string interpolation
here's the diff on the output after running it both ways
Copy code
- st:inf3bootstrapwus:bootstrap: [
-     [0]: "81f5de7e-9f4a-404b-bfd4-c4e478e975c8"
]
+ uai:[object Object]:resources: [
+     [0]: "st:inf3bootstrapwus:bootstrap"
]
it's a 1-1 relationship though, so i think i'm OK either way
i realize this is probably an odd situation, but this UAI + Azure thing has been a nightmare lol
thank you @white-balloon-205
👍 1