sparse-intern-71089
11/18/2019, 10:14 AMrhythmic-finland-36256
11/18/2019, 10:19 AMComponentResource
that gets the azure.dns.Zone
and a list of tuples like (domainName, ipAddress)
. To build this in a stable fashion (such that reordering of resources doesn’t lead to delete/replaces) I want to create the ARecord
pulumi resource name dynamically based on the domain and the zone’s name (with some sanitizing). This now leads me to the point that the zone’s name is of type pulumi.Output<string>
and I might do some interpolation but will end up in trouble when I want to use that as pulumi resource name.rhythmic-finland-36256
11/18/2019, 10:20 AMboundless-airport-99052
11/25/2019, 9:16 PMboundless-airport-99052
11/25/2019, 9:18 PM<output>.apply
bloc, but this prevents you to export it in outputs because, because export
should be at global levelboundless-airport-99052
11/25/2019, 9:18 PMrhythmic-finland-36256
12/02/2019, 10:05 AMrhythmic-finland-36256
12/18/2019, 4:19 PMrhythmic-finland-36256
12/18/2019, 4:21 PMimport * as azure from "@pulumi/azure";
import * as pulumi from "@pulumi/pulumi";
import { ComponentResource, ComponentResourceOptions } from "@pulumi/pulumi";
export interface ARecordEntry {
domain: string;
ip: string;
ttl?: number;
}
export interface ZonedEntriesArgs {
zone: azure.dns.Zone;
defaultTtl: number;
entries: ARecordEntry[];
}
export class ZonedEntries extends ComponentResource {
public readonly aRecords: azure.dns.ARecord[];
constructor(name: string, private args: ZonedEntriesArgs, opts: ComponentResourceOptions = {}) {
super("ajaegle:dns:ZonedEntries", name, {}, opts);
this.aRecords = this.args.entries.map(entry => this.createARecord(entry));
}
createARecord(entry: ARecordEntry) {
const sanitizedName = createSanitizedName(entry.domain, this.args.zone.name)
return new azure.dns.ARecord(sanitizedName, { // <-- this won't work with output value
name: entry.domain,
records: [entry.ip],
ttl: entry.ttl || this.args.defaultTtl,
zoneName: this.args.zone.name,
resourceGroupName: this.args.zone.resourceGroupName,
});
}
}
function createSanitizedName(domain: string, zoneName:pulumi.Output<string>) {
const sanitizedDomain = domain.replace("*", "wildcard").replace(/\./g, "-");
const sanitizedZone = zoneName.apply(name => name.replace(/\./g, "-"));
return pulumi.interpolate `${sanitizedDomain}-${sanitizedZone}`;
}
boundless-airport-99052
12/19/2019, 8:48 AMpulumi.Output<>
in the pulumi resource name, but you don’t need it. The pulumi resource name should be unique, so you just replace the zone name by the component name like that:
return new azure.dns.ARecord(`${entry.domain}-${name}, {
Or if you sanitize:
return new azure.dns.ARecord(createSanitizedName(entry.domain, name), { // <-- this won't work with output value
...
function createSanitizedName(domain: string, name:string): string {
const sanitizedDomain = domain.replace("*", "wildcard").replace(/\./g, "-");
return `${sanitizedDomain}-${name}`;
}
rhythmic-finland-36256
12/19/2019, 9:52 AM