orange-arm-29738
07/03/2024, 5:07 AMurls.public
whereas I would expect 6.
const records: pulumi.Output<cloudflare.Record>[] = [];
for (const service of ["ga", "hr", "wp", "api"]) {
records.push(
pulumi.output(
new cloudflare.Record(
`${service}-dns-record`,
{
zoneId: process.env.CLOUDFLARE_ZONE_ID!,
type: "CNAME",
name: pulumi.interpolate`${service}-${suffix}`,
value: traefikService.status.loadBalancer.ingress[0].hostname,
},
{ provider }
)
)
);
}
sipNodes.apply((nodes) => {
nodes.forEach((node, index) => {
records.push(
pulumi.output(
new cloudflare.Record(
`sip-dns-record-${index}`,
{
zoneId: process.env.CLOUDFLARE_ZONE_ID!,
type: "A",
name: pulumi.interpolate`sip-${suffix}`,
value: node.publicIp,
},
{ provider }
)
)
);
});
});
export const urls = pulumi.all([records]).apply(([records]) => {
return {
lb: traefikService.status.loadBalancer.ingress[0].hostname,
public: records.map((r) => r.hostname),
};
});
little-cartoon-10569
07/03/2024, 8:23 PMnodes
is, but if it was an array of outputs, you could move the apply inside the loop, and you'd get a result of the right size.little-cartoon-10569
07/03/2024, 8:26 PMurls.public
in the Pulumi program, or via the program outputs? I would expect the program outputs to be correct, since (as I understand it) Pulumi waits for all `Output`s to be applied before building the program outpus.little-cartoon-10569
07/03/2024, 8:27 PMapply
to finish.orange-arm-29738
07/03/2024, 10:42 PMorange-arm-29738
07/03/2024, 10:42 PMconst sipNodes = sipNodegroup.nodeGroupName.apply(async (name) => {
const instances = await aws.ec2.getInstances({
filters: [
{
name: "tag:eks:nodegroup-name",
values: [name],
},
],
});
return instances.ids.map((id, index) => ({
instanceId: id,
privateIp: instances.privateIps[index],
publicIp: instances.publicIps[index],
}));
});
little-cartoon-10569
07/03/2024, 11:22 PMapply()
, and it's strongly recommended that you don't. In your first block of code, it seems like the only reason you're wrapping the Records in pulumi.output()
is as a side-effect of having an Output<string[]>
that you want to build into the loop. However, you can avoid that by getting those EC2 instance ids where they're needed, instead of earlier.
Essentially: don't grab the properties now because you will need them later, and build Output<YourOwnDataType[]> to contain those little pieces of information. Just pass the actual resources around, and let Pulumi worry about the outputs.little-cartoon-10569
07/03/2024, 11:23 PMlittle-cartoon-10569
07/03/2024, 11:25 PMlittle-cartoon-10569
07/03/2024, 11:26 PMlittle-cartoon-10569
07/03/2024, 11:29 PMoutputArrayOfString.apply((array) => array.forEach((str) => new Resource("x", { value: str })));
This is less bad:
for (const i = 0; i <= sizeOfArray; ++i) {
new Resource("x", { value: outputArrayOfString.apply((array) => array[i].str) });
}