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

aws_cdk.aws_ec2.Vpc: max_a_zs ignored? #3110

Closed
1 of 5 tasks
dhx-mike-palandra opened this issue Jun 27, 2019 · 2 comments
Closed
1 of 5 tasks

aws_cdk.aws_ec2.Vpc: max_a_zs ignored? #3110

dhx-mike-palandra opened this issue Jun 27, 2019 · 2 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-reproduction This issue needs reproduction. package/tools Related to AWS CDK Tools or CLI

Comments

@dhx-mike-palandra
Copy link

  • I'm submitting a ...

    • πŸͺ² bug report
    • πŸš€ feature request
    • πŸ“š construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    For the code below, it seems as if the synthesized template includes only 4 subnets (2 public and 2 private) even if max_a_zs value and subnet configuration would allow for more in the affected region.

If the current behavior is a πŸͺ²bugπŸͺ²: Please provide the steps to reproduce
Consider this code:

import sys
from aws_cdk import core
from aws_cdk import aws_ec2 as ec2

app = core.App()

env = core.Environment(region = 'us-east-2')
stack = core.Stack(app, 'vpc-test-cdk036', env = env)
vpc = ec2.Vpc(stack, 'vpc', cidr='10.173.128.0/17', max_a_zs=3,
    subnet_configuration = [
        ec2.SubnetConfiguration(name='pub', subnetType=ec2.SubnetType.PUBLIC),
        ec2.SubnetConfiguration(name='prv', subnetType=ec2.SubnetType.PRIVATE),
    ]
)

print(f'Region: {stack.region}', file=sys.stderr)
print(f'Availability Zones: {stack.availability_zones}', file=sys.stderr)
for subnet_type in ('public', 'private'):
    subnets_attr = f'{subnet_type}_subnets'
    print(f'{subnet_type}: {len(getattr(vpc, subnets_attr))}', file=sys.stderr)

app.synth()

Then, run the CLI like so:
$ cdk synth --json | jq '.Resources | to_entries | [.[] | select(.value.Type == "AWS::EC2::Subnet")] | length'

The jq filter simply counts subnet resources declared in the synthesized template.

  • What is the expected behavior (or behavior of feature suggested)?
    Six subnets should have been created. I can't seem to create more than 4. Note that us-east-2 has at least 3 AZs. Also, I notice that no context values were saved by the CLI after a synth command.

I reviewed CHANGELOG.md and commits on master since v0.36.0 but didn't notice anything relevant. I feel like I may have missed something here (sincerest apologies if so), as this kind of issue seems fairly easy to encounter, so I'd be surprised somewhat if indeed this is a bug and I am the first to report it.

  • What is the motivation / use case for changing the behavior or adding this feature?
    I'd like to create more than 4 subnets and preserve my existing VPC stacks having more than 4 subnets. Unless I misunderstood something, I'm pretty sure this is a regression because I don't recall having such a problem in v0.34.0. When I run cdk diff from v0.36.0 against similar VPC stacks created by v0.34.0, results indicate a reduction to 4 subnets and change of the remaining subnets to a reduced CIDR prefix (quite disruptive).

  • Please tell us about your environment:

    • CDK CLI Version: 0.36.0 (build 6d38487)
    • Module Version: 0.36.0
    • OS: cpe:/o:fedoraproject:fedora:30
    • Language: Python
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

@NGL321 NGL321 added bug This issue is a bug. @aws-cdk/core Related to core CDK functionality package/tools Related to AWS CDK Tools or CLI needs-reproduction This issue needs reproduction. labels Jun 27, 2019
@mhuebner
Copy link

Have a look at #3083

@dhx-mike-palandra
Copy link
Author

Thank you @mhuebner. This worked as I expected when I replaced:

env = core.Environment(region = 'us-east-2')

with:

import os
env = core.Environment(
        account = os.environ.get('CDK_DEFAULT_ACCOUNT'),
        region = 'us-east-2'
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-reproduction This issue needs reproduction. package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

3 participants