bright-flag-46266
01/19/2023, 9:39 AMList<string>
of ips that should be
mapped to a single domain, this is entirely supported by Cloudflare by just creating multiple records. However as the Ip's comes in as an
Input<List<string>>
because I first have to provision the necessary infrastructure I have no other choice but to use an apply
to get the
underlying Ip's to be able to create the records. However, as per the documentation for apply (https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#apply)
it specifically recommends against doing this. How would I go about creating a list of DNS records based on a variable amount of Ip's when the
Cloudflare record type does not accept a list of Ip's but only a Input<string>
(https://www.pulumi.com/registry/packages/cloudflare/api-docs/record/#properties)?
My code looks like this:
public ClusterDnsComponent(string name, Input<List<string>> externalIps, DeploymentRegion region,
ComponentResourceOptions? options = null)
: base("dgz:cloudflare:clusterdns", name, options)
{
var opts = new CustomResourceOptions()
{
Parent = this
};
var dnsNames = externalIps.Apply(e => e.Select((externalIp, index) =>
{
var record = new Cloudflare.Record($"cluster-dns-{index}", new Cloudflare.RecordArgs()
{
ZoneId = "",
Name = NamingHelper.GetClusterDnsName(region),
Value = externalIp,
Type = Constants.Domain.DsnTypes.ARecord,
}, opts);
return record.Name;
})
);
DnsNames = dnsNames.Apply(o => Output.All(o).Apply(s => s));
RegisterOutputs();
}