https://pulumi.com logo
#aws
Title
# aws
a

astonishing-dentist-11149

03/08/2023, 7:19 PM
Hey all, this seems like really bad code here, and it makes me believe I am doing something really wrong. I am coming to typescript from python so there are some serious gaps in understanding. I assume that I need to do something with apply. Right now this is the only way I have figured out how to get my code to work, but I hate the idea of using an as, because you are never guaranteed to get that structure from the other end. It feels generally like a bad practice. The point here is to feed in secrets that are created from my infra stack, as we follow the microstack model.
Sorry if this was supposed to be in the typescript channel.
l

little-cartoon-10569

03/08/2023, 8:28 PM
You won't need to use apply unless you're trying to get at those values immediately. Most of the time, values from other stacks are used in constructors of Pulumi resources, which handle Outputs correctly.
You don't need to cast on these lines, unless there's something about the way you're using the values that requires this. Can you post (as text please, not a picture) how you're using these stack references?
a

astonishing-dentist-11149

03/08/2023, 8:41 PM
I needed to concat the two Secret arays together, after reading the docs, I figured out, I think the proper way to do it. If I do not cast them, TS errors saying type mismatch.
Copy code
const secrets: pulumi.Output<aws.ecs.Secret[]> = await pulumi
    .all([baseSecretArns, envSecretArns])
    .apply(async ([base, env]) => {
      return base.concat(env);
    });
Thank you for replying @little-cartoon-10569
l

little-cartoon-10569

03/08/2023, 9:08 PM
You don't need the async in the formal definition of the anonymous function. And you shouldn't await this.
This should do the same thing:
Copy code
const secrets = pulumi
    .all([baseSecretArns, envSecretArns])
    .apply(([base, env]) => [...base, ...env]);
If you need to do this often, it would be more efficient to do it in the exporting stack.
a

astonishing-dentist-11149

03/08/2023, 9:15 PM
That is not valid syntax, base and env do not have iterators on them (Type 'Output<Secret[]>' must have a '[Symbol.iterator]()' method that returns an iterator.), but I have removed the await and async, but even with that, because I have .all returns, I would still need the as on the const variables. This just seems really bad. Let me rethink this to see if there is a way I can do both, I think there may be a way to combine them on this side so I don't have to do all the crazy stuff. That might fix my as concern as well.
I really appreciate you reaching out though.
l

little-cartoon-10569

03/08/2023, 9:16 PM
Why are base and env still outputs? They're inside the apply...
a

astonishing-dentist-11149

03/08/2023, 9:16 PM
THis is good stuff!
They end up being this type: pulumi.UnwrappedArray<aws.ecs.Secret>
l

little-cartoon-10569

03/08/2023, 9:17 PM
That should have an iterator? If not, then the .concat() optoion is fine too.
a

astonishing-dentist-11149

03/08/2023, 9:18 PM
I don't think I am going to need it, I don't think base and env need to be seperate, ❤️ thank you! Good idea putting it on the export side.
l

little-cartoon-10569

03/08/2023, 9:19 PM
You can export all 3 sets of secrets for convenience.