https://pulumi.com logo
Title
e

early-plastic-49211

12/05/2022, 5:01 PM
What would be the proper way to write this without hackily discarding the
apply
return value in
recordsets.apply
?
const recordsets = privateEndpoint.customDnsConfigs.apply(x => {
  if (typeof x === 'undefined') {
      return [];
  }

  const result = [];
  for (const dnsConfig of x) {
      const name = dnsConfig.fqdn!.split('.')[0];
      const ipAddresses = dnsConfig.ipAddresses!.map(x => {
          return {ipv4Address: x};
      });

      result.push({
          name: name,
          ipAddresses: ipAddresses
      });
  }

  return result;
});

recordsets.apply(rs => {
  for (const x of rs) {
      new network.PrivateRecordSet(`resource-pe-dns-${name}`, {
          privateZoneName: zone.name,
          recordType: "A",
          relativeRecordSetName: x.name,
          resourceGroupName: resourceGroup,
          ttl: 300,
          aRecords: x.ipAddresses
      });
  }

  return true;
});
g

green-kilobyte-86931

12/06/2022, 9:55 AM
Good question, I've also created resources inside of apply, because that was the only way I could figure out how to iterate over an output value. I had to discard the output of that apply in an unsightly way...