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/ec2 token resolve issues #3104

Closed
1 of 5 tasks
cmckni3 opened this issue Jun 27, 2019 · 4 comments
Closed
1 of 5 tasks

aws-cdk/ec2 token resolve issues #3104

cmckni3 opened this issue Jun 27, 2019 · 4 comments
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-reproduction This issue needs reproduction.

Comments

@cmckni3
Copy link
Contributor

cmckni3 commented Jun 27, 2019

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • 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?
    If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

I am using Fn.findInMap to resolve availability zones and private subnets to create a vpc. Problem arises from the use of tokens. For some reason, the subnet token is not resolved correctly and is placed into the synthesized template as an array of each character of the token name.

    const vpc = ec2.Vpc.fromVpcAttributes(this, 'VPC', {
      vpcId: Fn.findInMap(accountResourceMapping.logicalId, this.accountId, 'vpcId'),
      availabilityZones: [...Fn.findInMap(accountResourceMapping.logicalId, this.accountId, 'vpcAvailabilityZones')],
      privateSubnetIds: [...Fn.findInMap(accountResourceMapping.logicalId, this.accountId, 'privateAppSubnets')]
    });

Another problem arises from the use of Token it seems. I can place the literal array with subnet ids for privateSubnetIds but then I get an error that privateSubnetIds (2) must a multiple of availability zones (18). I only have 2 availability zones. I believe .length is called on the Token string itself which is of form the ${Token[Token.89]}.

  • What is the expected behavior (or behavior of feature suggested)?

Should resolve the availability zone and private subnet ids as string arrays.

  • What is the motivation / use case for changing the behavior or adding this feature?

Using this to deploy multiple environments.

  • Please tell us about your environment:

    • CDK CLI Version: 0.33.0
    • EC2 Module Version: 0.33.0
    • OS: OSX Mojave
    • Language: TypeScript
  • 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)

Might be related to #168?

#817

@cmckni3 cmckni3 added the needs-triage This issue or PR still needs to be triaged. label Jun 27, 2019
@NGL321 NGL321 added bug This issue is a bug. @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud needs-reproduction This issue needs reproduction. vpc and removed needs-triage This issue or PR still needs to be triaged. labels Jun 27, 2019
@cmckni3
Copy link
Contributor Author

cmckni3 commented Jun 30, 2019

@NGL321 do I need to provide an example other than the code snippet I provided?

@NGL321
Copy link
Contributor

NGL321 commented Jul 1, 2019

@cmckni3 That looks like it should be sufficient for repro, thank you for asking!

I'll let you know if I need any more information as soon as I am able to look into this in more depth!

@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 21, 2019

Not sure that your use case (deploy-time resolution of a list of subnet IDs) is going to work. There are some cases in which we need to know the number of availability zones at the time CDK code is executing, for example, and given that this construction makes it so that the AZs are only known at deploy time, that can never work properly. We would recommend doing the lookup at CDK execution time rather than CloudFormation deployment time.

Now, it might be that for your use case, you won't hit any of the problematic code paths, so you might still want to proceed with your approach.

The immediate issue you're hitting is that Fn.findInMap() is typed to return a string, and the string is subsequently treated as a collection of characters which are exploded into the array.

Converting to a list token will stop that from happening:

      availabilityZones: [...Token.asList(Fn.findInMap(accountResourceMapping.logicalId, this.accountId, 'vpcAvailabilityZones'))],

Closing this issue. If you feel this is closed in error, please reopen.

@rix0rrr rix0rrr closed this as completed Aug 21, 2019
@cmckni3
Copy link
Contributor Author

cmckni3 commented Aug 21, 2019

Thanks! That's what I needed. I am doing the lookup at CDK execution time.

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-reproduction This issue needs reproduction.
Projects
None yet
Development

No branches or pull requests

4 participants