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

silly-apple-46154

12/18/2023, 10:00 PM
Is it possible to use the javascript spread operator on an input? well, i guess, more so a workaround?
Copy code
async create({
    addtOrigins = []
  }: {
    addtOrigins?: aws.cloudfront.DistributionArgs['origins'];
  }): Promise<aws.cloudfront.Distribution> {
    const apiDistribution = new aws.cloudfront.Distribution(
      `distribution`,
      {
        origins: [
          {
            // removed, but assume one exists here.
          },
          ...addtOrigins
        ],
there is a lot more to that but essentially i am looking to add anything additional that i passed to this helper function and spread them into some existing default configuration... however, it appears that when i utilize the pulumi aws.cloudfront.DistributionArgs i am dealing with an input which will not allow me to spread this in.
g

gifted-balloon-26385

12/18/2023, 10:07 PM
hm i dont think there’s a problem with this approach. possible issue is that addtOrigins is optional which you cant spread if it’s undefined, you can use a default like `addtOrigins: <type> = []`so its an array even if nothing is passed in
oh jk you have the default there. what’s the TS error you’re getting
s

silly-apple-46154

12/18/2023, 10:09 PM
Type 'Input<Input<DistributionOrigin>[]>' must have a '[Symbol.iterator]()' method that returns an iterator.
g

gifted-balloon-26385

12/18/2023, 10:13 PM
hmm tricky
try this
Copy code
origins: pulumi
      .output(addtOrigins)
      .apply((addtOrigins) => [...addtOrigins, {...}]),
actually this is the right way: replace the type of
addtOrigins
with the real object type (not wrapped in pulumi.Input):
aws.types.input.cloudfront.DistributionOrigin[];
s

silly-apple-46154

12/18/2023, 10:20 PM
aha! thanks 🙂
i've done that before i just could not quite remember how i had done it 🙂
5 Views