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

Trying to resolve() a Construct at /securityGroups/0 #772

Closed
ygoodmn opened this issue Sep 25, 2018 · 3 comments
Closed

Trying to resolve() a Construct at /securityGroups/0 #772

ygoodmn opened this issue Sep 25, 2018 · 3 comments
Assignees
Labels
bug This issue is a bug.

Comments

@ygoodmn
Copy link

ygoodmn commented Sep 25, 2018

CDK Java version 0.9.2
As not many samples, creating a Launch configuration with 2 Security Groups, get the following error on cdk sythn cdk-sms104-NLB. When comment out the line it goes away, but don't have the security groups assigned.

Exception in thread "main" software.amazon.jsii.JsiiException: While synthesizing cdk-sms104-NLB/LaunchConfiguration: Trying to resolve() a Construct at /securityGroups/0
While synthesizing cdk-sms104-NLB/LaunchConfiguration: Trying to resolve() a Construct at /securityGroups/0
--- resource created at ---

Here is the code:

SecurityGroupIngressResource securityGroupIngressResourcePort80 = new SecurityGroupIngressResource(this,
               "Port80Ingress", SecurityGroupIngressResourceProps.builder()
               .withIpProtocol("tcp")
               .withFromPort(80)
               .withToPort(80)
               .withCidrIp(new FnSub("10.${ProjectID}.0.0/22")) //TODO put into Fn:Sub  //
               // #TODO Secure this to only the .3 and .2 private network only
               .build());

       SecurityGroupResource securityGroupResource80 = new SecurityGroupResource(this, "Port80SecurityGroup",
               SecurityGroupResourceProps.builder()
                       .withGroupDescription("Port80")
                       .withVpcId(new FnSub("SMS-${ProjectID}-VPC-VPCID"))
                       .withSecurityGroupIngress(Collections.singletonList(securityGroupIngressResourcePort80.getSecurityGroupIngressId()))
                       .build());

       SecurityGroupIngressResource securityGroupIngressResourcePort22 = new SecurityGroupIngressResource(this,
               "Port22Ingress", SecurityGroupIngressResourceProps.builder()
               .withIpProtocol("tcp")
               .withFromPort(22)
               .withToPort(22)
               .withCidrIp(new FnSub("10.${ProjectID}.0.0/22"))
               .build()); //FUTURE: Add tags ?

       SecurityGroupResource securityGroupResource22 = new SecurityGroupResource(this, "Port22SecurityGroup",
               SecurityGroupResourceProps.builder()
                       .withGroupDescription("Port22")
                       .withVpcId(new FnSub("SMS-${ProjectID}-VPC-VPCID"))
                       .withSecurityGroupIngress(Collections.singletonList(securityGroupIngressResourcePort22.getSecurityGroupIngressId()))
                       .build());

       List<Object> securityGroupList = new ArrayList(){{
           add(securityGroupResource80);
           add(securityGroupResource22);
       }};

       LaunchConfigurationResource launchConfigurationResource = new LaunchConfigurationResource(this, "LaunchConfiguration",
               LaunchConfigurationResourceProps.builder()
                       .withLaunchConfigurationName(new FnSub("SMS-${ProjectID}-LaunchConfiguration"))
                       .withImageId(amiIDParam.getValue().toString())
                       .withKeyName(keyNameParam.getValue().toString())
                       .withSecurityGroups(securityGroupList) //TODO ERRORS
                       .withInstanceType(instanceTypeParam.getValue().toString())
                       .withAssociatePublicIpAddress(false)
                       .build());

-Yaakov

@rix0rrr rix0rrr added the bug This issue is a bug. label Sep 25, 2018
@eladb eladb self-assigned this Sep 27, 2018
@eladb
Copy link
Contributor

eladb commented Sep 27, 2018

Hi @ygoodmn,

The error is due to the fact that the SecurityGroups property of LaunchConfiguration is expected to be a list of security group IDs and securityGroupList contains objects instead of strings. To fix this, use this:

List<String> securityGroupList = new ArrayList() {{
  add(securityGroupResource80.getSecurityGroupId());
  add(securityGroupResource22.getSecurityGroupId());
}};

Hope that helps.

On a side note, I was wondering why you chose to use the low-level cloudformation resources instead of the high-level constructs in the @aws-cdk/autoscaling library? One of the main benefits of using the higher level library is that the APIs are richer and strong-typed, so you won't have issues such as this.

If you find missing features in this library, we would love to know about it. We are also working on a nicer way to "escape hatch" (#606) from the higher-level libraries for specific cases where you have gaps that you need to work around. Would love your feedback!

@eladb eladb closed this as completed Sep 27, 2018
@ygoodmn
Copy link
Author

ygoodmn commented Oct 2, 2018

@eladb , As this is first experience with CDK, do not know what is the difference between high level and low level. Perhaps an example of the difference in Java would assist me in this understangin.
Issue resolved, thanks

@eladb
Copy link
Contributor

eladb commented Oct 2, 2018

No worries. We are aware that this is a bit confusing.
Would you be able to read this and let us know if it clarifies things a bit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants