pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language 🚀
https://www.pulumi.com
Apache License 2.0
21.66k stars 1.11k forks source link

Unexpected unknown properties during final marshaling #251

Closed lukehoban closed 7 years ago

lukehoban commented 7 years ago

There are cases where computed<string> values are still making it through to the inputs to a create operation.

Below is an example that triggers this, I will look into narrowing this repro case down.

import * as lumi from "@lumi/lumi";
import * as aws from "@lumi/aws";

let policy = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}

let role = new aws.iam.Role("mylambdarole", {
  assumeRolePolicyDocument: policy,
  managedPolicyARNs: [aws.iam.AWSLambdaFullAccess],
});

let lambda = new aws.lambda.Function("mylambda", {
  code: new lumi.asset.AssetArchive({
    "index.js": new lumi.asset.String("exports.handler = (ev, ctx, cb) => cb('Hello, world!');"),
  }),
  role: role,
  handler: "index.handler",
  runtime: aws.lambda.NodeJS6d10Runtime,
});

let region = aws.config.requireRegion();

let swaggerSpec = {
  swagger: "2.0",
  info: { title: "myrestapi", version: "1.0" },
  paths: {
    "/bambam": {
      "x-amazon-apigateway-any-method": {
        "x-amazon-apigateway-integration": {
          uri: "arn:aws:apigateway:" + region + ":lambda:path/2015-03-31/functions/" + lambda.arn + "/invocations",
          passthroughBehavior: "when_no_match",
          httpMethod: "POST",
          type: "aws_proxy"
        }
      }
    }
  }
}

let restAPI = new aws.apigateway.RestAPI("myrestapi", {
  body: swaggerSpec
});

On lumi deploy, the above leads to:

...
Applying step #3 [create]
+ aws:apigateway/restAPI:RestAPI:
      [urn=test::serverless:index::aws:apigateway/restAPI:RestAPI::myrestapi]
      body            : {
          info   : {
              title  : "myrestapi"
              version: "1.0"
          }
          paths  : {
              /bambam: {
                  x-amazon-apigateway-any-method: {
                      x-amazon-apigateway-integration: {
                          httpMethod         : "POST"
                          passthroughBehavior: "when_no_match"
                          type               : "aws_proxy"
                          uri                : computed<string>
                      }
                  }
              }
          }
          swagger: "2.0"
      }
      name            : "myrestapi"
F0615 11:28:54.824113   79185 failfast.go:37] An assertion has failed: Unexpected unknown properties during final marshaling
goroutine 1 [running]:
github.com/golang/glog.stacks(0xc4201a6000, 0xc420162b40, 0x7d, 0x10c)
    /Users/luke/go/src/github.com/golang/glog/glog.go:769 +0xa7
github.com/golang/glog.(*loggingT).output(0x18fc9e0, 0xc400000003, 0xc420087130, 0x18ab031, 0xb, 0x25, 0x0)
    /Users/luke/go/src/github.com/golang/glog/glog.go:720 +0x36b
github.com/golang/glog.(*loggingT).printDepth(0x18fc9e0, 0x3, 0x1, 0xc423647540, 0x1, 0x1)
    /Users/luke/go/src/github.com/golang/glog/glog.go:646 +0x12d
github.com/golang/glog.(*loggingT).print(0x18fc9e0, 0x3, 0xc423647540, 0x1, 0x1)
    /Users/luke/go/src/github.com/golang/glog/glog.go:637 +0x5a
github.com/golang/glog.Fatal(0xc423647540, 0x1, 0x1)
    /Users/luke/go/src/github.com/golang/glog/glog.go:1128 +0x53
github.com/pulumi/lumi/pkg/util/contract.failfast(0xc4234a7d10, 0x4e)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/util/contract/failfast.go:37 +0x11f
github.com/pulumi/lumi/pkg/util/contract.Assertf(0xc4229f0b00, 0x163629d, 0x35, 0x0, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/util/contract/assert.go:34 +0x178
github.com/pulumi/lumi/pkg/resource/plugin.MarshalProperties(0xc4229f0b40, 0xc421031b00, 0x0, 0xc4236477c8)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/resource/plugin/rpc.go:67 +0x9b
github.com/pulumi/lumi/pkg/resource/plugin.(*provider).Create(0xc420f96090, 0xc4235f17a0, 0x1e, 0xc421031b00, 0xffffffffffffffff, 0x0, 0x0, 0xc423647930, 0x14ca741)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/resource/plugin/provider_plugin.go:130 +0x1f6
github.com/pulumi/lumi/pkg/resource/deploy.(*Step).Apply(0xc4221ca840, 0xc4221ca840, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/resource/deploy/step.go:113 +0x1d9
github.com/pulumi/lumi/pkg/resource/deploy.(*Plan).Apply(0xc4229f0b90, 0x18ba100, 0xc4231dabc0, 0x0, 0xc420d9d260, 0x0, 0x28, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/resource/deploy/plan_apply.go:51 +0xb2
main.deployLatest(0xc420077d40, 0xc4200efda0, 0x0, 0x1919770, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/cmd/lumi/deploy.go:134 +0x3e1
main.newDeployCmd.func1(0xc420077d40, 0x1919770, 0x0, 0x0, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/cmd/lumi/deploy.go:73 +0x1e5
github.com/pulumi/lumi/pkg/util/cmdutil.RunFunc.func1(0xc420077d40, 0x1919770, 0x0, 0x0)
    /Users/luke/go/src/github.com/pulumi/lumi/pkg/util/cmdutil/exit.go:33 +0x51
github.com/spf13/cobra.(*Command).execute(0xc420077d40, 0x1919770, 0x0, 0x0, 0xc420077d40, 0x1919770)
    /Users/luke/go/src/github.com/spf13/cobra/command.go:636 +0x231
github.com/spf13/cobra.(*Command).ExecuteC(0xc4200778c0, 0xc420150090, 0xc420150089, 0xc420150088)
    /Users/luke/go/src/github.com/spf13/cobra/command.go:722 +0x339
github.com/spf13/cobra.(*Command).Execute(0xc4200778c0, 0x0, 0x0)
    /Users/luke/go/src/github.com/spf13/cobra/command.go:681 +0x2b
main.main()
    /Users/luke/go/src/github.com/pulumi/lumi/cmd/lumi/main.go:24 +0x33
joeduffy commented 7 years ago

Thanks. I was able to repro this locally, so will start debugging now.

It looks like some map replacements aren't getting resolved for some reason.

For example, I ran with --logtostderr -v=9, and you can see some computed<string>s deep inside of the body and paths properties. Obviously not correct!

I0615 12:30:13.388876   87655 provider_plugin.go:127] resource[aws].Create(t=aws:apigateway/restAPI:RestAPI,#props=15) executing
I0615 12:30:13.388882   87655 rpc.go:47] Marshaling property for RPC: .ctor={<nil>}
I0615 12:30:13.388934   87655 rpc.go:47] Marshaling property for RPC: apiName={<nil>}
I0615 12:30:13.388938   87655 rpc.go:47] Marshaling property for RPC: body={map[swagger:{2.0} info:{map[title:{myrestapi} version:{1.0}]} paths:{map[/bambam:{map[x-amazon-apigateway-any-method:{map[x-amazon-apigateway-integration:{map[httpMethod:{POST} type:{aws_proxy} uri:computed<string>{} passthroughBehavior:{when_no_match}]}]}]}]}]}
I0615 12:30:13.388955   87655 rpc.go:47] Marshaling property for RPC: info={map[title:{myrestapi} version:{1.0}]}
I0615 12:30:13.388960   87655 rpc.go:47] Marshaling property for RPC: title={myrestapi}
I0615 12:30:13.388963   87655 rpc.go:47] Marshaling property for RPC: version={1.0}
I0615 12:30:13.388966   87655 rpc.go:47] Marshaling property for RPC: paths={map[/bambam:{map[x-amazon-apigateway-any-method:{map[x-amazon-apigateway-integration:{map[passthroughBehavior:{when_no_match} httpMethod:{POST} type:{aws_proxy} uri:computed<string>{}]}]}]}]}
I0615 12:30:13.388975   87655 rpc.go:47] Marshaling property for RPC: /bambam={map[x-amazon-apigateway-any-method:{map[x-amazon-apigateway-integration:{map[uri:computed<string>{} passthroughBehavior:{when_no_match} httpMethod:{POST} type:{aws_proxy}]}]}]}
I0615 12:30:13.389022   87655 rpc.go:47] Marshaling property for RPC: x-amazon-apigateway-any-method={map[x-amazon-apigateway-integration:{map[type:{aws_proxy} uri:computed<string>{} passthroughBehavior:{when_no_match} httpMethod:{POST}]}]}
I0615 12:30:13.389041   87655 rpc.go:47] Marshaling property for RPC: x-amazon-apigateway-integration={map[uri:computed<string>{} passthroughBehavior:{when_no_match} httpMethod:{POST} type:{aws_proxy}]}
I0615 12:30:13.389048   87655 rpc.go:47] Marshaling property for RPC: httpMethod={POST}
I0615 12:30:13.389052   87655 rpc.go:47] Marshaling property for RPC: passthroughBehavior={when_no_match}
I0615 12:30:13.389055   87655 rpc.go:47] Marshaling property for RPC: type={aws_proxy}
I0615 12:30:13.389057   87655 rpc.go:47] Marshaling property for RPC: uri=computed<string>{}
I0615 12:30:13.389075   87655 rpc.go:47] Marshaling property for RPC: swagger={2.0}
I0615 12:30:13.389080   87655 rpc.go:47] Marshaling property for RPC: bodyS3Location={<nil>}
I0615 12:30:13.389088   87655 rpc.go:47] Marshaling property for RPC: cloneFrom={<nil>}
I0615 12:30:13.389091   87655 rpc.go:47] Marshaling property for RPC: description={<nil>}
I0615 12:30:13.389093   87655 rpc.go:47] Marshaling property for RPC: failOnWarnings={<nil>}
I0615 12:30:13.389096   87655 rpc.go:47] Marshaling property for RPC: name={myrestapi}
I0615 12:30:13.389099   87655 rpc.go:47] Marshaling property for RPC: parameters={<nil>}
fatal: An assertion has failed: Unexpected unknown properties during final marshaling