https://pulumi.com logo
#dotnet
Title
# dotnet
c

cuddly-smartphone-15267

12/02/2020, 11:20 AM
i was trying to convert a typescript example to .net but couldn't quite work out how - the combination of
reduce
and
apply
just confused me a lot.. the example is basically creating some dns records for a certificate validation
Copy code
const exampleRecord: aws.route53.Record[];
        for (const range of Object.entries(exampleCertificate.domainValidationOptions.apply(domainValidationOptions => domainValidationOptions.reduce((__obj, dvo) => { ...__obj, [dvo.domainName]: {
            name: dvo.resourceRecordName,
            record: dvo.resourceRecordValue,
            type: dvo.resourceRecordType,
        } }))).map(([k, v]) => {key: k, value: v})) {
            exampleRecord.push(new aws.route53.Record(`exampleRecord-${range.key}`, {
                allowOverwrite: true,
                name: range.value.name,
                records: [range.value.record],
                ttl: 60,
                type: range.value.type,
                zoneId: exampleZone.then(exampleZone => exampleZone.zoneId),
            }));
        }
        const exampleCertificateValidation = new aws.acm.CertificateValidation("exampleCertificateValidation", {
            certificateArn: exampleCertificate.arn,
            validationRecordFqdns: exampleRecord.apply(exampleRecord => exampleRecord.map(record => record.fqdn)),
        });
anybody that is more familiar with typescript than me perhaps suggest how to port it to the equivalent c# code?
t

tall-librarian-49374

12/02/2020, 11:43 AM
I don’t think this TypeScript example is actually valid. Here is my take in C#:
Copy code
var exampleRecordFqdns = exampleCertificate.DomainValidationOptions.Apply(dvos =>
{
    var fqdns = new List<Output<string>>();
    foreach (var dvo in dvos)
    {
        var record = new Record($"exampleRecord-{dvo.DomainName}", new RecordArgs
        {
            AllowOverwrite = true,
            Name = dvo.ResourceRecordName,
            Records = { dvo.ResourceRecordValue },
            Ttl = 60,
            Type = dvo.ResourceRecordType,
            ZoneId = exampleZone.then(exampleZone => exampleZone.zoneId),
        });
        fqdns.Add(record.Fqdn);
    }

    return Output.All(fqdns);
});

var exampleCertificateValidation = new CertificateValidation("exampleCertificateValidation", new CertificateValidationArgs
{
    CertificateArn = exampleCertificate.Arn,
    ValidationRecordFqdns = exampleRecordFqdns
});
(warning: I haven’t tested it)
c

cuddly-smartphone-15267

12/02/2020, 11:55 AM
thanks @tall-librarian-49374 that's definitely a good frame of reference! I'll take a closer look at your code
your code is a lot simpler than what i'd come up with (i 'hacked' it a bit temporarily to just use the first DomainValidationOptions object in the list).. but i'm getting the same result.. which is that the recordname / recordvalue / recordtype don't seem to be getting properly set and i get this error when i run pulumi up
Copy code
aws:route53:Record (validationRecord-pulumitest.keypay.dev):
        error: aws:route53/record:Record resource 'validationRecord-pulumitest.keypay.dev' has a problem: Required attribute is not set
        error: aws:route53/record:Record resource 'validationRecord-pulumitest.keypay.dev' has a problem: Required attribute is not set
t

tall-librarian-49374

12/02/2020, 12:15 PM
Hmm… to debug this further - could you try deploying all resources without
CertificateValidation
first, and then deploy again with it?
Oh, sorry, without
Record
resources then
c

cuddly-smartphone-15267

12/02/2020, 12:44 PM
yep that works just fine if I do that Mikhail
t

tall-librarian-49374

12/02/2020, 2:54 PM
Have a look there for a workaround and please add your example in a comment
c

cuddly-smartphone-15267

12/02/2020, 9:10 PM
Will do, thanks