Is there a hook that I can get the outputs of a re...
# general
b
Is there a hook that I can get the outputs of a resource creation that can be used to write to a database / file?
l
Is exporting outputs from your Pulumi program not doing everything you need? Can you describe your intended flow?
b
I want to take the output of creating some resources and create a dynamodb TableItem with the contents
l
You want to use outputs in the JSON going into the TableItem? You need to either 1) create the TableItem inside an
apply()
, or 2) create the TableItem outside your Pulumi program, possibly in another program, in another inline automation-api program, or outside Pulumi altogether, using the normal DynamoDB SDK or API.
If the TableItem's Item property was a pulumi.Input<string>, you could do it the normal way....
Oh cool, it is! The docs don't say that it is. You don't need to create the resource inside
apply
, you can use
pulumi.interpolate
.
Someday, someone will make a
pulumi.interpolateJson
function to make it even easier...
r
The docs omit
pulumi.Input
from all input types just because of redundancy but they're always `Input`s. It would probably make sense to have some sort of one-liner to that effect in the docs though.
l
They're not always Inputs though. They should be, but there are some places where it's been missed.
I come across them quite frequently. More than once a week.
r
Like what? I know the resource_name is a
str
but other than that I didn't know that that was a thing.
(No need to find one now but lemme know next time you come across one)
👍 1
b
I thought I saw somewhere in the docs that you shouldn't create resources within apply() ?
l
You shouldn't, if you can avoid it. And you can avoid it this time. You need to build your JSON string inside an apply, but you can pass the result to TableItem's args.item.
1
You can use pulumi.interpolate in lieu of apply(), it's the same thing.
b
gotcha!
l
Something a bit like this (where foobar is an output on a resource you've created):
Copy code
const item = resource.foobar.apply(foo => JSON.stringify({ "key": `${foo}bar`})); // item is a pulumi.Output<string>
const ti = new aws.dynamodb.TableItem("ti", {
  tableName: table.name,
  hashKey: table.hashKey,
  item: item
}, opts);
b
oh! that makes sense. Thanks for the example.
👍 1
@little-cartoon-10569, if I had an object =>
Copy code
{ 
   foo: Output<string>
   bar: Output<string>
}
would Pulumi.output() evaluate each property?
l
Your options there are to chain your calls to
apply()
, or use
pulumi.all()
.
❤️ 1
I sometimes use chained calls to
apply()
, it it's more readable. Though since this is a TableItem and you're building JSON, I think you're probably better off with
pulumi.all()
.