currently I have this dynamic provider to handle C...
# general
c
currently I have this dynamic provider to handle Cloudflare DNS operations,
pulumi up
and
pulumi destroy
works fine, but
pulumi up --refresh
dies
Copy code
Previewing update (dev):

     Type                               Name        Plan        Info
 ~   pulumi:pulumi:Stack                dliver-dev  refresh     7 messages
 ~   └─ pulumi-nodejs:dynamic:Resource  testdns     refresh     1 error
 
Diagnostics:
  pulumi:pulumi:Stack (dliver-dev):
    Error: Unexpected struct type.: Error: Unexpected struct type.
        at Function.proto.google.protobuf.Value.fromJavaScript (/home/ncsibra/dev/prmrgt-infra/pulumi/dliver/node_modules/google-protobuf/google/protobuf/struct_pb.js:804:13)
        at Function.proto.google.protobuf.Struct.fromJavaScript (/home/ncsibra/dev/prmrgt-infra/pulumi/dliver/node_modules/google-protobuf/google/protobuf/struct_pb.js:870:51)
        at Object.<anonymous> (/home/ncsibra/dev/prmrgt-infra/pulumi/dliver/node_modules/@pulumi/pulumi/cmd/dynamic-provider/index.js:179:55)
        at Generator.next (<anonymous>)
        at fulfilled (/home/ncsibra/dev/prmrgt-infra/pulumi/dliver/node_modules/@pulumi/pulumi/cmd/dynamic-provider/index.js:17:58)
        at process.internalTickCallback (internal/process/next_tick.js:77:7)
 
  pulumi-nodejs:dynamic:Resource (testdns):
    error: Preview failed: Unexpected struct type.
 
error: an error occurred while advancing the preview
If I remove the
read
function, it works, but of course not updates the resource
if I modify the create method return from this:
Copy code
return {
      id: `dns:${zoneID}:${res.result.id}`,
      outs: inputs
    }
to this:
Copy code
return {
      id: `dns:${zoneID}:${res.result.id}`,
      outs: record
    }
I got the same "Unexpected struct type" error
w
Cc @microscopic-florist-22719 who should be able to help here.
m
@cold-coat-35200 from a glance at the protobuf sources, it looks like this could happen if any element in the data you're passing back in
outs
or
props
is a function. However, the data you're returning in
record
doesn't seem like it contains any function values. What do you see if you
console.log(JSON.stringify(record))
?
c
Copy code
{
  "type": "CNAME",
  "name": "test",
  "content": "<http://test.com|test.com>",
  "ttl": 1,
  "proxied": true
}
nothing special, just the expected, it does not contains a function
m
I wonder if
record
has a key
priority
with the value
undefined
. That might also cause this.
Can you try
console.log(JSON.stringify(Object.keys(record)))
?
c
Copy code
["type","name","content","ttl","priority","proxied"]
it does
m
Ok, that's probably the issue.
If you don't have nested properties, you can filter out the `undefined`s with this one-liner:
Copy code
const outs = Object.keys(record).filter(k => record[k] !== undefined).reduce((acc, k) => ({ ...acc, [k]: record[k] }), {});
Similar code will work for
Read
.
We should make this easier in the dynamic provider itself.
c
thanks @microscopic-florist-22719, it solves the problem
m
Glad to hear it!