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

VpcNetwork return error of its subnet properties #2362

Closed
McDoit opened this issue Apr 23, 2019 · 1 comment · Fixed by aws/jsii#703
Closed

VpcNetwork return error of its subnet properties #2362

McDoit opened this issue Apr 23, 2019 · 1 comment · Fixed by aws/jsii#703
Assignees
Labels
bug This issue is a bug. language/dotnet Related to .NET bindings p0

Comments

@McDoit
Copy link
Contributor

McDoit commented Apr 23, 2019

Describe the bug
Subnets configurations from a newly created VPC throws Type reference has a fully qualified name, but is neither a class nor an enum Parameter name: reference when trying to access the xSubnets properties of the vpc object

To Reproduce
Creating a new VPC with

var subnets = new ISubnetConfiguration[]
{
    new SubnetConfiguration { CidrMask = 28, Name = "Public", SubnetType = SubnetType.Public },
    new SubnetConfiguration { CidrMask = 28, Name = "Private", SubnetType = SubnetType.Private },
    new SubnetConfiguration { CidrMask = 28, Name = "Db", SubnetType = SubnetType.Private },
};

var vpc = new VpcNetwork(this, "vpc", new VpcNetworkProps
{
    Cidr = "172.30.0.0/22",
    EnableDnsHostnames = true,
    EnableDnsSupport = true,
    NatGatewaySubnets = new SubnetSelection
    {
        SubnetType = SubnetType.Public
    },
    SubnetConfiguration = subnets,
    NatGateways = 1,
    MaxAZs = 2
});

Then try to access the vpc.PrivateSubnets property

Expected behavior
To get the array of the different subnet types

Version:

  • Windows 10
  • C#/dotnet core 2.1
  • CDK 0.28
@McDoit McDoit added the bug This issue is a bug. label Apr 23, 2019
@fulghum fulghum added language/dotnet Related to .NET bindings p0 labels Apr 24, 2019
@McDoit
Copy link
Contributor Author

McDoit commented May 8, 2019

Found a workaround, given that you want the subnets named Private you can use this method:

            private IEnumerable<T> GetSubnetsByName<T>(IIVpcNetwork vpc, string subnetName) where T : class
            {
                return Enumerable.Range(1, vpc.AvailabilityZones.Length).Select(s => $"{subnetName}Subnet{s}")
                    .Select(s => vpc.Node.FindChild(s) as T);
            }

and then use this snippet in your code:

 var privateSubnetIds = GetSubnetsByName<VpcPrivateSubnet>(vpc, "Private").Select(s => s.SubnetId).ToArray();

RomainMuller pushed a commit to aws/jsii that referenced this issue Aug 16, 2019
Add support for return type being array of interfaces.

Tested with the customer code. 

https://docs.aws.amazon.com/cdk/api/latest/dotnet/api/Amazon.CDK.AWS.EC2.Vpc.html#Amazon_CDK_AWS_EC2_Vpc_PrivateSubnets

This was not supported by the runtime, as it only allowed for classes and enums:

```
public virtual IISubnet[] PrivateSubnets { get; }
```

Fixes aws/aws-cdk#2362
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. language/dotnet Related to .NET bindings p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants