Currently, I am trying to export out an object of ...
# typescript
m
Currently, I am trying to export out an object of key,values in a pulumi stack. This is mostly setup to automate our pipeline deployment with resources generated by pulumi. Problem I am having is getting this to populate correctly.
Copy code
export const resources = pulumiResources.reduce(
  (result, res) => ({
    ...result,
    [res.location]: {
      // This variable is Output<string>
      resourceGroup: res.resourceGroup,
      otherProperty: res.foo,
    },
  }),
  {}
);
Problem I am running into is when I try to run pulumi.apply in order to set the key as a string. When I run this, I will either only get the first item in the list applied to the object or I will get the last object of list applied.
Copy code
export const resources = pulumiResources.reduce((result, res) =>
  res.location.apply(
    (location) => ({
      ...result,
      [location]: {
        // This variable is Output<string>
        resourceGroup: res.resourceGroup,
        otherProperty: res.foo,
      },
    }),
    {}
  )
);
I tried doing a pulumi.all on the resources and this didn’t work either.
s
res.location.apply()
returns an
Output<T>
which becomes the type for
result
. Given that, I'm not sure what
...result
ends up being but it's definitely not the structure you intend. I am not sure if it's possible to be honest 🤔 You'd need to find a way to convert an
Array<Output<string>>
into
Output<Array<string>>