Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization error while trying to use pulumi-awsgateway #594

Closed
Tracked by #598
slnowak opened this issue May 16, 2022 · 19 comments · Fixed by #602
Closed
Tracked by #598

Deserialization error while trying to use pulumi-awsgateway #594

slnowak opened this issue May 16, 2022 · 19 comments · Fixed by #602
Assignees
Labels
area/sdks kind/bug Some behavior is incorrect or out of spec language/java resolution/fixed This issue was fixed
Milestone

Comments

@slnowak
Copy link

slnowak commented May 16, 2022

What happened?

When trying to run a minimalistic example with aws-apigateway, pulumi throws the following error:

➜  java git:(master) ✗ pulumi up -y
Please choose a stack, or create a new one: dev
Previewing update (dev)

View Live: https://app.pulumi.com/slnowak/iac-workshop-lambda-api-gateway/dev/previews/c164ea18-8eca-49fd-a031-75c4ad640d60

     Type                             Name                                 Plan       Info
 +   pulumi:pulumi:Stack              iac-workshop-lambda-api-gateway-dev  create     2 errors; 16 messages
 +   ├─ aws:iam:Role                  lambdaRole                           create     
 +   ├─ aws:iam:RolePolicyAttachment  basicExecutionRole                   create     
 +   ├─ aws:lambda:Function           helloWorldFunction                   create     
 +   └─ apigateway:index:RestAPI      helloWorldApi                        create     
 +      ├─ aws:apigateway:RestApi     helloWorldApi                        create     
 +      ├─ aws:apigateway:Deployment  helloWorldApi                        create     
 +      ├─ aws:lambda:Permission      helloWorldApi-fa520765               create     
 +      └─ aws:apigateway:Stage       helloWorldApi                        create     
 
Diagnostics:
  pulumi:pulumi:Stack (iac-workshop-lambda-api-gateway-dev):
    error: Running program [PID: 13747](/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/bin/java -classpath /usr/local/Cellar/maven/3.8.5/libexec/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/usr/local/Cellar/maven/3.8.5/libexec/bin/m2.conf -Dmaven.home=/usr/local/Cellar/maven/3.8.5/libexec -Dlibrary.jansi.path=/usr/local/Cellar/maven/3.8.5/libexec/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/snowak/work/internal/pulumi/python_course/lambda/module2/java org.codehaus.plexus.classworlds.launcher.Launcher --quiet --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.api; Expected 'com.pulumi.aws.apigateway.RestApi' but got 'com.pulumi.resources.DependencyResource' while deserializing.
        at com.pulumi.serialization.internal.Converter.tryEnsureType(Converter.java:458)
        at com.pulumi.serialization.internal.Converter.tryConvertObjectInner(Converter.java:247)
        at com.pulumi.serialization.internal.Converter.convertObjectUntyped(Converter.java:105)
        at com.pulumi.serialization.internal.Converter.convertValue(Converter.java:80)
        at com.pulumi.core.internal.OutputCompletionSource.setValue(OutputCompletionSource.java:95)
        at com.pulumi.deployment.internal.DeploymentImpl$ReadOrRegisterResource.lambda$completeResourceAsync$0(DeploymentImpl.java:1162)
        at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
        at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
    error: an unhandled error occurred: '/usr/local/bin/mvn /usr/local/bin/mvn --quiet --no-transfer-progress compile exec:java' exited with non-zero exit code: 32
 
    May 16, 2022 6:29:22 PM com.pulumi.deployment.internal.DeploymentImpl$DefaultEngineLogger errorAsync
    SEVERE: Running program [PID: 13747](/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/bin/java -classpath /usr/local/Cellar/maven/3.8.5/libexec/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/usr/local/Cellar/maven/3.8.5/libexec/bin/m2.conf -Dmaven.home=/usr/local/Cellar/maven/3.8.5/libexec -Dlibrary.jansi.path=/usr/local/Cellar/maven/3.8.5/libexec/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/snowak/work/internal/pulumi/python_course/lambda/module2/java org.codehaus.plexus.classworlds.launcher.Launcher --quiet --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.api; Expected 'com.pulumi.aws.apigateway.RestApi' but got 'com.pulumi.resources.DependencyResource' while deserializing.
        at com.pulumi.serialization.internal.Converter.tryEnsureType(Converter.java:458)
        at com.pulumi.serialization.internal.Converter.tryConvertObjectInner(Converter.java:247)
        at com.pulumi.serialization.internal.Converter.convertObjectUntyped(Converter.java:105)
        at com.pulumi.serialization.internal.Converter.convertValue(Converter.java:80)
        at com.pulumi.core.internal.OutputCompletionSource.setValue(OutputCompletionSource.java:95)
        at com.pulumi.deployment.internal.DeploymentImpl$ReadOrRegisterResource.lambda$completeResourceAsync$0(DeploymentImpl.java:1162)
        at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
        at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Steps to reproduce

Use the following code snippet:

package myproject;

import com.pulumi.Pulumi;
import com.pulumi.asset.AssetArchive;
import com.pulumi.asset.StringAsset;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicyAttachment;
import com.pulumi.aws.iam.RolePolicyAttachmentArgs;
import com.pulumi.aws.iam.enums.ManagedPolicy;
import com.pulumi.aws.lambda.Function;
import com.pulumi.aws.lambda.FunctionArgs;
import com.pulumi.aws.lambda.enums.Runtime;
import com.pulumi.awsapigateway.RestAPI;
import com.pulumi.awsapigateway.RestAPIArgs;
import com.pulumi.awsapigateway.enums.Method;
import com.pulumi.awsapigateway.inputs.RouteArgs;

import java.util.Map;

public class App1 {

    public static void main(String[] args) {
        Pulumi.run(ctx -> {
            var role = new Role("lambdaRole", RoleArgs.builder()
                    .assumeRolePolicy("""
                            {
                              "Version": "2012-10-17",
                              "Statement": [
                                {
                                  "Effect": "Allow",
                                  "Principal": {
                                    "Service": "lambda.amazonaws.com"
                                  },
                                  "Action": "sts:AssumeRole"
                                }
                              ]
                            }""")
                    .build()
            );

            var lambdaBasicExecutionRole = new RolePolicyAttachment("basicExecutionRole", RolePolicyAttachmentArgs.builder()
                    .role(role.name())
                    .policyArn(ManagedPolicy.AWSLambdaBasicExecutionRole.getValue())
                    .build());

            var api = new RestAPI("helloWorldApi", RestAPIArgs.builder()
                    .routes(
                            RouteArgs.builder()
                                    .path("/")
                                    .method(Method.GET)
                                    .eventHandler(
                                            new Function("helloWorldFunction", FunctionArgs.builder()
                                                    .role(role.arn())
                                                    .handler("index.handler")
                                                    .runtime(Runtime.NodeJS12dX)
                                                    .code(new AssetArchive(Map.of("index.js", new StringAsset("""
                                                            exports.handler = async (event) => {
                                                                return {
                                                                    statusCode: 200,
                                                                    body: "Hello, world!",
                                                                };
                                                            }"""))))
                                                    .build()))
                                    .build()
                    )
                    .build());

        });
    }
}

maven dependencies:

    <dependencies>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>pulumi</artifactId>
            <version>0.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>aws</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>aws</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>aws-apigateway</artifactId>
            <version>0.0.7</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>awsx</artifactId>
            <version>1.0.0-beta.1</version>
        </dependency>
    </dependencies>

Both awsx and aws-apigateway artifacts were built locally from the following git commit:

commit 40c68a28d140422dc77759fb48ae3d5a3540749e (HEAD -> main, tag: aws-apigateway/v0.0.7, origin/main, origin/HEAD)
Author: Paweł Prażak <pawelprazak@users.noreply.github.com>
Date:   Thu May 12 08:47:11 2022 +0200

    Fix version typo (#587)
    
    * Fix #586 - version typo
    
    * Revert redundant provider deletion

Expected Behavior

Successfull execution

Actual Behavior

Execution error

Versions used

No response

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@slnowak slnowak added the kind/bug Some behavior is incorrect or out of spec label May 16, 2022
@pawelprazak pawelprazak self-assigned this May 16, 2022
@pawelprazak
Copy link
Contributor

I wasn't able to reproduce this yet, but my working assumption is that:

  • com.pulumi.serialization.internal.ResourcePackages#tryConstruct returns Optional.empty()
  • as a consequence com.pulumi.serialization.internal.Deserializer#tryDeserializeResource returns DependencyResource

@pawelprazak pawelprazak mentioned this issue May 17, 2022
3 tasks
@pawelprazak
Copy link
Contributor

An ongoing effort at reproducing and fixing is being done here:
#597

@pawelprazak
Copy link
Contributor

We've managed get a new error and more debugging info:

...
debug: Registering resource monitor end: t=aws-apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=true
    debug: Read response for resource: t=aws-apigateway:index:RestAPI, name=helloWorldApi, urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI::helloWorldApi, id=, remote=true
    debug: Deserialize/ResourcePackages: searching for type=aws:apigateway/restApi:RestApi version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi
    debug: Deserialize/ResourcePackages: constructing type=aws:apigateway/restApi:RestApi version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi
    debug: Reading existing resource: t=aws:apigateway/restApi:RestApi, name=helloWorldApi, urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi, remote=false
    debug: Invoking function: token='pulumi:pulumi:getResource' asynchronously
    debug: Serialize property[invoke:pulumi:pulumi:getResource.urn]: Recursion into InputOutput
    debug: Serialize property[invoke:pulumi:pulumi:getResource.urn.id]: primitive=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi
    debug: Invoke RPC prepared: token='pulumi:pulumi:getResource', obj='com.pulumi.serialization.internal.PropertiesSerializer$SerializationResult@4caa0879'
    debug: Deserialize/ResourcePackages: searching for type=apigateway:index:RestAPI version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI::helloWorldApi
    debug: Deserialize/ResourcePackages: can't find a resource: 'apigateway:index:RestAPI' version: 'Deserialize/ResourcePackages: can't find a resource: 'apigateway:index:RestAPI' version: '; Available resources type names:
    ...
    aws-apigateway:index:RestAPI
    ...
    aws:apigateway/restApi:RestApi
    ...

So this one worked:

debug: Deserialize/ResourcePackages: searching for type=aws:apigateway/restApi:RestApi version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi
debug: Deserialize/ResourcePackages: constructing type=aws:apigateway/restApi:RestApi version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi

And this one failed:

debug: Deserialize/ResourcePackages: searching for type=apigateway:index:RestAPI version= urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI::helloWorldApi
debug: Deserialize/ResourcePackages: can't find a resource: 'apigateway:index:RestAPI' version: 'Deserialize/ResourcePackages: can't find a resource: 'apigateway:index:RestAPI' version: '

@pawelprazak
Copy link
Contributor

The resources themselves are:

@ResourceType(type="aws-apigateway:index:RestAPI")
public class RestAPI extends com.pulumi.resources.ComponentResource
@ResourceType(type="aws:apigateway/restApi:RestApi")
public class RestApi extends com.pulumi.resources.CustomResource

So the ResourcePackages picked the resource correctly, but maybe somewhere the aws- got removed.

@pawelprazak
Copy link
Contributor

pawelprazak commented May 17, 2022

This is interesting:

    debug: Got parent urn: t=aws-apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=true
    debug: Prepared resource: t=aws-apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=true
    debug: Registering resource monitor start: t=aws-apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=true
    ...
    debug: Registering resource: t=apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=false
    debug: RegisterResource RPC prepared: t=apigateway:index:RestAPI, name=helloWorldApi

Looks like we send aws-apigateway:index:RestAPI to gRPC endpoint, and the engine gets apigateway:index:RestAPI.

Is that possible?

Edit:
I see the code that prints debug: Registering resource: t is in nodejs, is it possible that the project has some dirty state? from porting nodejs to java and reusing state somehow?

@pawelprazak
Copy link
Contributor

pawelprazak commented May 17, 2022

Also, later in the logs, now the stack trace is slightly different:

    debug: Read response for resource: t=aws:apigateway/restApi:RestApi, name=helloWorldApi, urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi, id=, remote=false
    error: Running program [PID: 25091](/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/bin/java -classpath /usr/local/Cellar/maven/3.8.5/libexec/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/usr/local/Cellar/maven/3.8.5/libexec/bin/m2.conf -Dmaven.home=/usr/local/Cellar/maven/3.8.5/libexec -Dlibrary.jansi.path=/usr/local/Cellar/maven/3.8.5/libexec/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/snowak/work/internal/pulumi/python_course/lambda/module2/java org.codehaus.plexus.classworlds.launcher.Launcher --quiet --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.deployment; Expected 'com.pulumi.aws.apigateway.Deployment' but got 'com.pulumi.resources.DependencyResource' while deserializing.
    	at com.pulumi.serialization.internal.Converter.tryEnsureType(Converter.java:458)
    	at com.pulumi.serialization.internal.Converter.tryConvertObjectInner(Converter.java:247)
    	at com.pulumi.serialization.internal.Converter.convertObjectUntyped(Converter.java:105)
    	at com.pulumi.serialization.internal.Converter.convertValue(Converter.java:80)
    	at com.pulumi.core.internal.OutputCompletionSource.setValue(OutputCompletionSource.java:95)
    	at com.pulumi.deployment.internal.DeploymentImpl$ReadOrRegisterResource.lambda$completeResourceAsync$0(DeploymentImpl.java:1162)
    	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
    	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
    	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

The type is com.pulumi.aws.apigateway.Deployment instead of com.pulumi.aws.apigateway.RestApi as before.

The com.pulumi.awsapigateway.RestAPI fields:

@Export(name="api", type=RestApi.class, parameters={})
private Output<RestApi> api;

and

@Export(name="deployment", type=Deployment.class, parameters={})
private Output<Deployment> deployment;

Might be just accidentally different ordering of setting the RestAPI fields.

@pawelprazak
Copy link
Contributor

Looks like an upstream issue: pulumi/pulumi-aws-apigateway#21

@pawelprazak pawelprazak added the blocked The issue cannot be resolved without 3rd party action. label May 18, 2022
@pawelprazak
Copy link
Contributor

Patch was merged upstream, we're waiting for the provider release v0.0.8.

pawelprazak added a commit that referenced this issue May 19, 2022
@pawelprazak
Copy link
Contributor

pawelprazak commented May 20, 2022

We have a new error:

May 19, 2022 6:16:36 PM com.pulumi.deployment.internal.DeploymentImpl$DefaultEngineLogger errorAsync
    SEVERE: Running program [PID: 48794](/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/bin/java -classpath /usr/local/Cellar/maven/3.8.5/libexec/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/usr/local/Cellar/maven/3.8.5/libexec/bin/m2.conf -Dmaven.home=/usr/local/Cellar/maven/3.8.5/libexec -Dlibrary.jansi.path=/usr/local/Cellar/maven/3.8.5/libexec/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/snowak/work/internal/pulumi/python_course/lambda/module2/java org.codehaus.plexus.classworlds.launcher.Launcher --quiet --no-transfer-progress compile exec:java) failed with an unhandled exception:
    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.deployment; Expected 'com.pulumi.aws.apigateway.Deployment' but got 'com.pulumi.awsapigateway.RestAPI' while deserializing.
    	at com.pulumi.serialization.internal.Converter.tryEnsureType(Converter.java:463)
    	at com.pulumi.serialization.internal.Converter.tryConvertObjectInner(Converter.java:252)
    	at com.pulumi.serialization.internal.Converter.convertObjectUntyped(Converter.java:110)
    	at com.pulumi.serialization.internal.Converter.convertValue(Converter.java:81)
    	at com.pulumi.core.internal.OutputCompletionSource.setValue(OutputCompletionSource.java:95)
    	at com.pulumi.deployment.internal.DeploymentImpl$ReadOrRegisterResource.lambda$completeResourceAsync$0(DeploymentImpl.java:1162)
    	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
    	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
    	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label May 20, 2022
@mikhailshilkov mikhailshilkov added this to the 0.73 milestone May 23, 2022
@pawelprazak
Copy link
Contributor

Auto-closed by the fix addressing the previous issue, re-opening.

@pawelprazak pawelprazak reopened this May 23, 2022
@pawelprazak pawelprazak removed the resolution/fixed This issue was fixed label May 23, 2022
@pawelprazak
Copy link
Contributor

pawelprazak commented May 23, 2022

I can see no other reason for this than the provider returning the wrong object then a bug:

debug: Read response for resource: t=aws-apigateway:index:RestAPI, name=helloWorldApi, urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI::helloWorldApi, id=, remote=true, data=fields {
      key: "api"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "id"
            value {
              string_value: ""
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi"
            }
          }
        }
      }
    }
    fields {
      key: "deployment"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI::helloWorldApi"
            }
          }
        }
      }
    }
    fields {
      key: "stage"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "id"
            value {
              string_value: ""
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI$aws:apigateway/stage:Stage::helloWorldApi"
            }
          }
        }
      }
    }

@pawelprazak
Copy link
Contributor

I've reported upstream: pulumi/pulumi-aws-apigateway#41

@t0yv0
Copy link
Member

t0yv0 commented May 23, 2022

I'm trying to follow the discussion but only the issue description from @slnowak is making sense to me.

I can reproduce with:

    <dependencies>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>aws-apigateway</artifactId>
            <version>0.0.8</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>pulumi</artifactId>
            <version>0.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.pulumi</groupId>
            <artifactId>aws</artifactId>
            <version>5.4.0</version>
        </dependency>
    </dependencies>

Which gives me the original exception:

    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.api; Expected 'com.pulumi.aws.apigateway.RestApi' but got 'com.pulumi.resources.DependencyResource' while deserializing.
        at com.pulumi.serialization.internal.Converter.tryEnsureType(Converter.java:458)
        at com.pulumi.serialization.internal.Converter.tryConvertObjectInner(Converter.java:247)
        at com.pulumi.serialization.internal.Converter.convertObjectUntyped(Converter.java:105)
        at com.pulumi.serialization.internal.Converter.convertValue(Converter.java:80)
        at com.pulumi.core.internal.OutputCompletionSource.setValue(OutputCompletionSource.java:95)
        at com.pulumi.deployment.internal.DeploymentImpl$ReadOrRegisterResource.lambda$completeResourceAsync$0(DeploymentImpl.java:1162)
        at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
        at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

@t0yv0
Copy link
Member

t0yv0 commented May 23, 2022

I can confirm I get this when upgrading SDK to the tip of main

    java.lang.UnsupportedOperationException: com.pulumi.awsapigateway.RestAPI.deployment; Expected 'com.pulumi.aws.apigateway.Deployment' but got 'com.pulumi.awsapigateway.RestAPI' while deserializing.

@pawelprazak
Copy link
Contributor

I can see no other reason for this than the provider returning the wrong object then a bug:

debug: Read response for resource: t=aws-apigateway:index:RestAPI, name=helloWorldApi, urn=urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI::helloWorldApi, id=, remote=true, data=fields {
      key: "api"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "id"
            value {
              string_value: ""
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi"
            }
          }
        }
      }
    }
    fields {
      key: "deployment"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI::helloWorldApi"
            }
          }
        }
      }
    }
    fields {
      key: "stage"
      value {
        struct_value {
          fields {
            key: "4dabf18193072939515e22adb298388d"
            value {
              string_value: "5cf8f73096256a8f31e491e813e4eb8e"
            }
          }
          fields {
            key: "id"
            value {
              string_value: ""
            }
          }
          fields {
            key: "urn"
            value {
              string_value: "urn:pulumi:dev::iac-workshop-lambda-api-gateway::aws-apigateway:index:RestAPI$aws:apigateway/stage:Stage::helloWorldApi"
            }
          }
        }
      }
    }

yes, this is what we've got from the provider, the URN is wrong for deployment

@pawelprazak
Copy link
Contributor

Reproducing with latest versions from main:
https://gist.github.com/pawelprazak/59f5b8aaafef459b0b0029acb02f0e3a

@pawelprazak
Copy link
Contributor

Adding more debugging messages reveal this raw RegisterResourceResponse:

debug: Registering resource monitor end: t=aws-apigateway:index:RestAPI, name=helloWorldApi, custom=false, remote=true, result=urn: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI::helloWorldApi"
    object {
      fields {
        key: "api"
        value {
          struct_value {
            fields {
              key: "4dabf18193072939515e22adb298388d"
              value {
                string_value: "5cf8f73096256a8f31e491e813e4eb8e"
              }
            }
            fields {
              key: "id"
              value {
                string_value: ""
              }
            }
            fields {
              key: "urn"
              value {
                string_value: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi"
              }
            }
          }
        }
      }
      fields {
        key: "deployment"
        value {
          struct_value {
            fields {
              key: "4dabf18193072939515e22adb298388d"
              value {
                string_value: "5cf8f73096256a8f31e491e813e4eb8e"
              }
            }
            fields {
              key: "urn"
              value {
                string_value: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI::helloWorldApi"
              }
            }
          }
        }
      }
      fields {
        key: "stage"
        value {
          struct_value {
            fields {
              key: "4dabf18193072939515e22adb298388d"
              value {
                string_value: "5cf8f73096256a8f31e491e813e4eb8e"
              }
            }
            fields {
              key: "id"
              value {
                string_value: ""
              }
            }
            fields {
              key: "urn"
              value {
                string_value: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI$aws:apigateway/stage:Stage::helloWorldApi"
              }
            }
          }
        }
      }
    }
    propertyDependencies {
      key: "api"
      value {
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws:lambda/function:Function::helloWorldFunction"
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::helloWorldApi"
      }
    }
    propertyDependencies {
      key: "deployment"
      value {
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI::helloWorldApi"
      }
    }
    propertyDependencies {
      key: "stage"
      value {
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws:lambda/function:Function::helloWorldFunction"
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI$aws:apigateway/stage:Stage::helloWorldApi"
      }
    }
    propertyDependencies {
      key: "url"
      value {
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws:lambda/function:Function::helloWorldFunction"
        urns: "urn:pulumi:pulumi-594-private::pulumi-594::aws-apigateway:index:RestAPI$aws:apigateway/deployment:Deployment::helloWorldApi"
      }
    }

What I found interesting is that propertyDependencies for deployment has only two entries, while others have 2 entries.

@pawelprazak
Copy link
Contributor

We have this if:

if (remote && options instanceof ComponentResourceOptions) {

And according to the logs aws-apigateway:index:RestAPI fits the criteria: remote and component resource.
This might be the differentiator that makes this resource unique. If true this might help narrow down the code.

@t0yv0
Copy link
Member

t0yv0 commented Jul 20, 2022

Debugging this further I believe this is a bug in the provider. Legit looks like a typo. I cannot reproduce after this fix:
pulumi/pulumi-aws-apigateway#56

Stay tuned for an updated version of the provider after my fix is reviewed and released.

@t0yv0 t0yv0 closed this as completed Jul 20, 2022
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jul 20, 2022
@t0yv0 t0yv0 removed the blocked The issue cannot be resolved without 3rd party action. label Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks kind/bug Some behavior is incorrect or out of spec language/java resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants