How can I use the ouput of a custom resource, as a...
# general
s
How can I use the ouput of a custom resource, as a string in a policy? - CustomResource outputs endpoint - Need to use that output as such:
url="${customResource.endpoint}"
w
In general - the answer is "use `apply`". For example:
Copy code
policy: cutomResource.endpoint.apply(endpoint => JSON.stringify({ ... endpoint ... })
Depending on exactly what you are doing - there may be easier options.
s
I just want the output (which is a url), so I can pass it on to another policy
Context:
Copy code
const exampleApiOperationPolicy = new azure.apimanagement.ApiOperationPolicy("test-policy", {
    apiManagementName: homePageOperation.apiManagementName,
    apiName: homePageOperation.apiName,
    operationId: homePageOperation.operationId,
    resourceGroupName: homePageOperation.resourceGroupName,
    xmlContent: `<policies>
  <inbound>
    <set-backend-service base-url="${staticWebsiteUrl}" />
  </inbound>
  <backend>
    <forward-request timeout="30" follow-redirects="true" />
  </backend>
</policies>
`,
});
h
there's also
pulumi.interpolate
but yeah, in general you should assume that resource properties are asyncronous `Output`s and not actual values
s
got a link or some demo on how to use that neat
interpolate
function?
w
Yes - in the case above -
pulumi.interpolate
should do what you want. https://www.pulumi.com/docs/reference/programming-model/#outputs-and-strings
s
Same error
Copy code
const staticWebsiteUrl = pulumi.interpolate `${staticWebsite.endpoint}`;

....

   xmlContent: `<policies>
  <inbound>
    <set-backend-service base-url="${staticWebsiteUrl}" />

....
Copy code
Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => `pref..
have tried apply too
w
The interpolate should go on:
Copy code
xmlContent: pulumi.interpolate`...`
s
aaahhh
wow… much neat! many thanks
w
Definitely encourage reading the rest of https://www.pulumi.com/docs/reference/programming-model/#outputs for details on
Output
more generally.
s
thank you, will go through it