aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Java Error TransitGateway new Attachment

Open evildani opened this issue 7 years ago • 3 comments

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.

evildani avatar Mar 17 '19 17:03 evildani

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 avatar Mar 18 '19 09:03 rix0rrr

Aha, here is the issue:

interface {
   someProperty: string;

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

rix0rrr avatar Mar 18 '19 09:03 rix0rrr

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

evildani avatar Mar 18 '19 12:03 evildani