Hi guys! I have a question regarding outputs. Let'...
# general
d
Hi guys! I have a question regarding outputs. Let's say I need to create a resource B (step function), which takes a stringified json configuration. This config is stored inside a file. However, this configuration is templated, and relies on an arn of a previously created resource (resource A)
{
"Comment": "Save Restriction - Trigger Deletion - Restore on Fail",
"StartAt": "ExportRestrictionData",
"States": {
"ExportRestrictionData": {
"Type": "Task",
"Resource": "${resource_A_ARN}"
}
}
}
The problem is, that reading this file and replacing this variable won't work using language native functions, as it's an Output type at the time. I know you can circumvent the issue by creating resource B inside the
.apply()
block, but is there a better way without a potential callback hell? I was thinking about
pulumi.interpolate
s
I have basically the same challenge and I've tried so many different ways to get around it and I haven't had any luck yet
The next thing I was going to try was to create resource A and get the resulting Output<> object. Then pass that Output<> into a function (as an Input<>. No conversion needed) where I create the next resource.
The problem I'm having is that I need a property of that Output, ( the Id )
so I'm forced into wrapping everything into an apply()
so all I will really be doing it making the code a bit easier to read but it's the same problem at the end of the day
d
I sorta figured out the way. I just extended
String
type with the required function (
replacePulumi
accepting Output as a replacement value) The issue with this approach is that it only works once, as the return type is Output, so you can't chain
.repalcePulumi()
And you can't extend Output, as it doesn't have a prototype (I'm using type script) Unless there's a way?
s
@limited-rainbow-51650 any ideas?
l
In your language host, you will never be able to fetch the value from an
Output
directly. You will have to pass a callback function to
apply
. This is the inherent to the asynchronous nature of Pulumi where the program in your language host, and the provisioning by Pulumi run in different processes, communicating with each other via a local gRPC connection.
d
I understand that, that's why the
.replace.Pulumi
extension is nothing more than a wrap around .
replace
inside
.apply()
callback returning output. Would it be possible to extend the Output class to add additional functions? With casting later on. From what I see, .d.ts defines it as an interface rather than a class. Is there a reason for this?
pulumi.interpolate
and
pulumi.concat
are not enough for more complex string manipulations. For example, chained
.replace()