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

Java Error TransitGateway new Attachment #2030

Closed
evildani opened this issue Mar 17, 2019 · 3 comments · Fixed by #2033 · May be fixed by MechanicalRock/account-reaper#6
Closed

Java Error TransitGateway new Attachment #2030

evildani opened this issue Mar 17, 2019 · 3 comments · Fixed by #2033 · May be fixed by MechanicalRock/account-reaper#6

Comments

@evildani
Copy link

evildani commented Mar 17, 2019

Hello,

I have an error when I create a TransitGateway attachment with a very simple code

SubnetConfiguration pub = SubnetConfiguration.builder()
	             .withSubnetType(SubnetType.Public)
	             .withCidrMask(24)
	             .withName("Public")
	             .build();
    	vpc1 = new VpcNetwork(this, "vpc1", VpcNetworkProps.builder()
    			.withCidr("192.168.0.0/20")
    			.withEnableDnsHostnames(true)
    			.withEnableDnsSupport(true)
    			.withMaxAZs(1)
    			.withSubnetConfiguration(Arrays.asList(pub))
    		    .build());
	CfnTransitGateway tgw = new CfnTransitGateway(this, "TGW", tgprop);
    	CfnTransitGatewayAttachmentProps tgwattprops1 = CfnTransitGatewayAttachmentProps.builder()
    			.withVpcId(vpc1.getVpcId())
    			.withSubnetIds(Arrays.asList(vpc1.getPublicSubnets().get(0)))
    			.withTransitGatewayId(tgw.getTransitGatewayId())
    			.build();
//this line fails....
CfnTransitGatewayAttachment tgwAtt1 = new CfnTransitGatewayAttachment(this, "tgwattachments1", tgwattprops1);

I create a VPC with one subnet, create a transit gateway and attach the VPC. Simple.
The Java Exception is:

software.amazon.jsii.JsiiException: While synthesizing TGWStack/tgwattachments1: Unable to resolve object tree with circular reference. Path: /subnetIds/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots.....
  --- resource created at ---
  at s._wrapSandboxCode (/private/var/folders/sf/g067b5ws2ds2cstktk40x_4d5sw0rx/T/jsii-java-runtime8579796281364426405/jsii-runtime.js:1:86832)
  at i.then.e (/private/var/folders/sf/g067b5ws2ds2cstktk40x_4d5sw0rx/T/jsii-java-runtime8579796281364426405/jsii-runtime.js:1:78834)
  --- problem discovered at ---
    at resolve (/private/var/folders/sf/g067b5ws2ds2cstktk40x_4d5sw0rx/T/jsii-kernel-JeWZCg/node_modules/@aws-cdk/cdk/lib/core/tokens/resolve.js:19:15)
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project my_stack_tgw: An exception occured while executing the Java class. While synthesizing TGWStack/tgwattachments1: Unable to resolve object tree with circular reference. Path: /subnetIds/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/0/dependencyRoots/

Is there anything I can do? is there anything I am doing wrong? BTW I am not sure if this is relevant, but maven compile works just fine. Its the synth where things go wrong.

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 18, 2019

I'd have a suspicion the problem is in this line:

    			.withSubnetIds(Arrays.asList(vpc1.getPublicSubnets().get(0)))

SubnetIds requires a list of strings, and you're giving a list of subnet objects.

The problem is we're still accepting Token, which we shouldn't.

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 18, 2019

Aha, here is the issue:

interface {
   someProperty: string;

   // but
   someProperty: Array<string | Token>;
}

rix0rrr added a commit that referenced this issue Mar 18, 2019
Because of accepted Tokenized values, cfn2ts previously translated a
string and string array into:

    interface Props {
        someString: string;
        stringArray: Array<string | Token> | Token;
    }

The latter was not intended. We now emit:

    interface Props {
        someString: string;
        stringArray: string[];
    }

Since the Token will be typed as `Object` in Java, this change now makes
it impossible to mistakenly pass any old java Object. A typical case
would be pass a `Subnet` where a `string subnetId` was expected, failing
in a nonobvious way.

Fixes #2030.
@evildani
Copy link
Author

Correct, the subnet id should be a string and not a subnet object.

@rix0rrr rix0rrr reopened this Mar 18, 2019
rix0rrr added a commit that referenced this issue Mar 18, 2019
Because of accepted Tokenized values, cfn2ts previously translated a
string and string array into:

    interface Props {
        someString: string;
        stringArray: Array<string | Token> | Token;
    }

The latter was not intended. We now emit:

    interface Props {
        someString: string;
        stringArray: string[];
    }

Since the Token will be typed as `Object` in Java, this change now makes
it impossible to mistakenly pass any old java Object. A typical case
would be pass a `Subnet` where a `string subnetId` was expected, failing
in a nonobvious way.

Fixes #2030.
rix0rrr added a commit to alex-berger/aws-cdk that referenced this issue Mar 19, 2019
Because of accepted Tokenized values, cfn2ts previously translated a
string and string array into:

    interface Props {
        someString: string;
        stringArray: Array<string | Token> | Token;
    }

The latter was not intended. We now emit:

    interface Props {
        someString: string;
        stringArray: string[];
    }

Since the Token will be typed as `Object` in Java, this change now makes
it impossible to mistakenly pass any old java Object. A typical case
would be pass a `Subnet` where a `string subnetId` was expected, failing
in a nonobvious way.

Fixes aws#2030.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants