https://pulumi.com logo
#yaml
Title
# yaml
r

rich-motorcycle-71684

03/16/2023, 7:41 AM
Hi Everyone, I'm trying to use the result of a string function in a resource, but it won't let me. Is there a way to do this without creating a variable for each function result then using that in the resource?
Copy code
ses_DomainIdentityVerification:
    type: aws:ses:DomainIdentityVerification
    properties:
      domain:
        fn::invoke:
          function: str:trimPrefix
          arguments:
            # arguments dictionary
            prefix: "production." # the prefix to trim
            string: "${ses_DomainIdentity.id}" # the string from which to trim it
...
Error: aws:ses/domainIdentityVerification:DomainIdentityVerification is not assignable from {domain: str:index:trimPrefixResult}
e

echoing-dinner-19531

03/25/2023, 9:47 PM
I think the following will work:
Copy code
ses_DomainIdentityVerification:
    type: aws:ses:DomainIdentityVerification
    properties:
      domain:
        fn::invoke:
          function: str:trimPrefix
          arguments:
            # arguments dictionary
            prefix: "production." # the prefix to trim
            string: "${ses_DomainIdentity.id}" # the string from which to trim it
          result: result
result
in an fn block lets you set which field of the result to return rather than the overall result object.
r

rich-motorcycle-71684

03/27/2023, 12:32 AM
@echoing-dinner-19531 wow! Thank you. Was this somewhere in the documentation? Because I sure didn't see it when I was looking
e

echoing-dinner-19531

03/27/2023, 7:47 AM
Yup, at https://www.pulumi.com/docs/reference/yaml/#fninvoke Hopefully some other useful bits on that page as well
I note this is specific to
fn::invoke
which might have made it a bit less obvious to find
r

rich-motorcycle-71684

03/28/2023, 4:13 AM
@echoing-dinner-19531 Thanks again. It's obvious now that you pointed it out. I think my brain passed over that bit because it didn't have 'result' anywhere in it.