https://pulumi.com logo
#automation-api
Title
# automation-api
b

bright-flag-46266

01/19/2023, 9:39 AM
Hello, I am trying to create multiple dns records in cloudflare using the automation api. And as such have a
List<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:
Copy code
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();
    }
As far as I can see Pulumi suggests using an apply themselves in one of their examples here, but I would love to hear if there is a better way, that may not give incorrect results for preview https://github.com/pulumi/examples/blob/258d3bad0a00020704743e37911c51be63c06bb4/classic-azure-cs-msi-keyvault-rbac/AppStack.cs#L180