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

Unable to reference subnet group name tag on an imported VPC #7580

Closed
dassowmd opened this issue Apr 23, 2020 · 1 comment · Fixed by #7770
Closed

Unable to reference subnet group name tag on an imported VPC #7580

dassowmd opened this issue Apr 23, 2020 · 1 comment · Fixed by #7770
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@dassowmd
Copy link

I am not able to reference a custom subnet group name on an imported VPC. I have tried to reference both the default tag (aws-cdk:subnet-name) and also by passing the a custom tag key to the vpc.from_lookup() method. Both to no avail unless I manually prebuild my cdk.context.json and commit to my repo.

This issue seems related to #3650 which is marked as resolved, but does not appear to be functioning as expected.

Reproduction Steps

` vpc = aws_ec2.Vpc.from_lookup(self
, "VPC"
, vpc_name='VPC1'
, subnet_group_name_tag='custom-subnet-group-tag-name'
)

    host = aws_ec2.Instance(<my_stack>
                            ,windows_powerbi_gateway_server_name,
                            instance_type=ec2.InstanceType(
                            instance_type_identifier='t2.large'),
                            instance_name='some_name',
                            machine_image=<windows_ami>,
                            vpc=vpc,
                            key_name='some_key',
                            vpc_subnets=ec2.SubnetSelection(subnet_group_name="application_layer")
                       )

`

Error Log

If I run the above code with an empty context I get the following error:
vpc_subnets=ec2.SubnetSelection(subnet_group_name="application") File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_runtime.py", line 66, in __call__ inst = super().__call__(*args, **kwargs) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\aws_cdk\aws_ec2\__init__.py", line 22158, in __init__ jsii.create(Instance, self, [scope, id, props]) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\__init__.py", line 229, in create interfaces=[iface.__jsii_type__ for iface in getattr(klass, "__jsii_ifaces__", [])], File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\providers\process.py", line 333, in create return self._process.send(request, CreateResponse) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\providers\process.py", line 318, in send raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: Cannot read property 'subnetId' of undefined Subprocess exited with error 1

If I prebuild my cdk.context.json and rerun it successfully builds. While I recognize this work around fixes the immediate issue, it also creates technical debt because now any time I deploy the stack to a new account or region I have to update my cdk.context.json manually.

Environment

  • **CLI Version :1.33.0
  • **Framework Version :
  • **OS : Windows 10
  • **Language :Python 3.7.6

Other

I believe that the issue is that the CDK is relying on the dummy vpc instead of making the call to get the context before trying to make the aws_ec2.Instance() call. If it were to instead fetch the context first I believe it would fix the issue.


This is 🐛 Bug Report

@dassowmd dassowmd added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 23, 2020
@jeremywitte
Copy link
Contributor

jeremywitte commented Apr 23, 2020

I am experiencing the same issue with a Python CDK app. We would like to use the Vpc.from_lookup() with a specified subnet group name tag since we have multiple PRIVATE subnet tiers/groups within our VPC.

ec2.Vpc.from_lookup(
    self, "VPC", vpc_name="vpc-name", subnet_group_name_tag="custom-tag-name"
)

We then try to use the ec2.SubnetSelection() reference with a valid subnet_group_name:

vpc_subnets=ec2.SubnetSelection(subnet_group_name="app-tier")

This does not work for a synth if the context does not yet exist but will work just fine if the context is already populated from an earlier successful Vpc.from_lookup().

This seems to be a problem only for the first synth when trying to use the subnet selection based on a supplied group name. As long as we have a context and do not clear it going forward, the subnet selection reference will work as expected.

@SomayaB SomayaB added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Apr 29, 2020
rix0rrr added a commit that referenced this issue May 4, 2020
Selecting by `subnetGroupName` in a looked up VPC may produce 0 subnets
on the first run of the app, if the actual lookup hasn't been performed
yet.

Rather than throwing an exception (which will fail the execution
outright and never even get to perform the lookup), add a construct
error. On the next run the lookup will have been performed and
the validation will no longer fail.

Fixes #7580.
@mergify mergify bot closed this as completed in #7770 May 4, 2020
mergify bot pushed a commit that referenced this issue May 4, 2020
Selecting by `subnetGroupName` in a looked up VPC may produce 0 subnets
on the first run of the app, if the actual lookup hasn't been performed
yet.

Rather than throwing an exception (which will fail the execution
outright and never even get to perform the lookup), add a construct
error. On the next run the lookup will have been performed and
the validation will no longer fail.

Fixes #7580.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants