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

cold-coat-35200

11/14/2018, 1:41 PM
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

white-balloon-205

11/14/2018, 2:57 PM
Cc @microscopic-florist-22719 who should be able to help here.
m

microscopic-florist-22719

11/14/2018, 6:37 PM
@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

cold-coat-35200

11/14/2018, 8:04 PM
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

microscopic-florist-22719

11/14/2018, 9:08 PM
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

cold-coat-35200

11/14/2018, 9:17 PM
Copy code
["type","name","content","ttl","priority","proxied"]
it does
m

microscopic-florist-22719

11/14/2018, 9:34 PM
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

cold-coat-35200

11/15/2018, 7:29 AM
thanks @microscopic-florist-22719, it solves the problem
m

microscopic-florist-22719

11/15/2018, 6:19 PM
Glad to hear it!