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

salmon-beard-79336

07/30/2019, 4:53 PM
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

white-balloon-205

07/30/2019, 4:55 PM
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

salmon-beard-79336

07/30/2019, 4:55 PM
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

high-translator-22614

07/30/2019, 4:57 PM
there's also
pulumi.interpolate
but yeah, in general you should assume that resource properties are asyncronous `Output`s and not actual values
s

salmon-beard-79336

07/30/2019, 4:58 PM
got a link or some demo on how to use that neat
interpolate
function?
w

white-balloon-205

07/30/2019, 4:58 PM
Yes - in the case above -
pulumi.interpolate
should do what you want. https://www.pulumi.com/docs/reference/programming-model/#outputs-and-strings
s

salmon-beard-79336

07/30/2019, 5:01 PM
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

white-balloon-205

07/30/2019, 5:02 PM
The interpolate should go on:
Copy code
xmlContent: pulumi.interpolate`...`
s

salmon-beard-79336

07/30/2019, 5:02 PM
aaahhh
wow… much neat! many thanks
w

white-balloon-205

07/30/2019, 5:04 PM
Definitely encourage reading the rest of https://www.pulumi.com/docs/reference/programming-model/#outputs for details on
Output
more generally.
s

salmon-beard-79336

07/30/2019, 5:04 PM
thank you, will go through it