sparse-intern-71089
11/13/2018, 10:13 AMcold-coat-35200
11/13/2018, 10:14 AMerror: Error serializing '() => provider': index.js(19,37)
'() => provider': index.js(19,37): captured
variable 'provider' which indirectly referenced
function '<anonymous>': dns.ts(17,22): which could not be serialized because
arrow function captured 'this'. Assign 'this' to another name outside function and capture that.
Function code:
(inputs) => __awaiter(this, void 0, void 0, function* () {
yield this.init();
const record = {
type: inputs.type,
name: inputs.name,
...
error: an unhandled error occurred: Program exited with non-zero exit code: 1
cold-coat-35200
11/13/2018, 10:15 AMstocky-spoon-28903
11/13/2018, 10:16 AMcold-coat-35200
11/13/2018, 10:17 AMstocky-spoon-28903
11/13/2018, 10:17 AMcold-coat-35200
11/13/2018, 10:18 AMcold-coat-35200
11/13/2018, 10:22 AMbig-piano-35669
this
is not available in the same way other captured variables are). We've been eeking by without hitting this very often -- and I keep hoping we will find a long-term solution (our old solution was to maintain a fork of V8 which wasn't sustainable when you factor in all the different versions). I had hoped Node.js 11 would solve this but alas, it hasn't.
cc @lemon-spoon-91807cold-coat-35200
11/13/2018, 4:39 PMcold-coat-35200
11/13/2018, 4:41 PM// @ts-ignore
import * as cloudflare from 'cloudflare'
import * as pulumi from '@pulumi/pulumi'
import * as dynamic from '@pulumi/pulumi/dynamic'
import { RunError } from '@pulumi/pulumi/errors'
class DNSProvider implements dynamic.ResourceProvider {
create = async (inputs: any) => {
let client = new cloudflare({
email: process.env.CLOUDFLARE_EMAIL as string,
key: process.env.CLOUDFLARE_TOKEN as string
})
let domains = await getDomains(client)
const record = {
type: inputs.type,
name: inputs.name,
content: inputs.content,
ttl: inputs.ttl,
priority: inputs.priority,
proxied: inputs.proxied
}
const zoneID = domains[inputs.domain]
let res
try {
res = await client.dnsRecords.add(zoneID, record)
} catch (e) {
throw new RunError(`Unable to add DNS record: ${e}`)
}
return {
id: `dns:${zoneID}:${res.result.id}`
}
}
delete = async (id: pulumi.ID, props: any) => {
const data = await parseID(id)
let client = new cloudflare({
email: process.env.CLOUDFLARE_EMAIL as string,
key: process.env.CLOUDFLARE_TOKEN as string
})
try {
await client.dnsRecords.del(data.zoneID, data.recordID)
} catch (e) {
throw new RunError(`Unable to delete DNS record: ${e}`)
}
}
}
export interface DNSRecordArgs {
domain: pulumi.Input<string>
type: pulumi.Input<string>
name: pulumi.Input<string>
content: pulumi.Input<string>
ttl?: pulumi.Input<string>
priority?: pulumi.Input<string>
proxied?: pulumi.Input<string>
}
export class DNSRecord extends pulumi.dynamic.Resource {
constructor(name: string, args: DNSRecordArgs, opts?: pulumi.CustomResourceOptions) {
super(new DNSProvider(), name, args, opts)
}
}
async function getDomains(client: cloudflare) {
let domains: {
[domain: string]: string
} = {}
let zones
try {
zones = await client.zones.browse()
} catch (e) {
throw new RunError(`Exception happened when retrieving zone information: ${e}`)
}
for (let zone of zones.result) {
domains[zone.name] = zone.id
}
return domains
}
function parseID(id: string) {
const parts = id.split(':')
if (parts.length !== 3) {
throw new RunError(`Invalid id: ${id}`)
}
return {
zoneID: parts[1],
recordID: parts[2]
}
}
cold-coat-35200
11/13/2018, 4:44 PMdynamic.ResourceProvider
is not a ProviderResource
cold-coat-35200
11/13/2018, 4:46 PMDNSRecordArgs
, because those args will be persisted in the state, getting from the env works, but would be better to provide this data from the outside, without storing in the state