pulumi / pulumi-awsx

AWS infrastructure best practices in component form!
https://www.pulumi.com/docs/guides/crosswalk/aws/
Apache License 2.0
218 stars 105 forks source link

VPC 1.0: Multiple types of the same subnet will throw an exception if name is not explicitly specified #909

Open jkodroff opened 1 year ago

jkodroff commented 1 year ago

If we create multiple instances of the same subnet type (public, private, isolated) without specifying a name, we get an exception.

The following program:

"""A Python Pulumi program"""

import pulumi_awsx as awsx

awsx.ec2.Vpc(
    "my-vpc",
    awsx.ec2.VpcArgs(
        subnet_specs=[
            awsx.ec2.SubnetSpecArgs(
                cidr_mask=24,
                type=awsx.ec2.SubnetType.ISOLATED,
            ),
            awsx.ec2.SubnetSpecArgs(
                cidr_mask=24,
                type=awsx.ec2.SubnetType.ISOLATED,
            ),
        ],
        nat_gateways=awsx.ec2.NatGatewayConfigurationArgs(
            strategy=awsx.ec2.NatGatewayStrategy.NONE,
        ),
    )
)

Results in the following error:

Previewing update (dev)

View Live: https://app.pulumi.com/jkodroff/awsx-subnet-resize/dev/previews/80f1d146-f2aa-4ecd-97ef-17fb0d035d88

     Type                     Name                    Plan       Info
 +   pulumi:pulumi:Stack      awsx-subnet-resize-dev  create     1 error
 +   └─ awsx:ec2:Vpc          my-vpc                  create     
 +      └─ aws:ec2:Vpc        my-vpc                  create     
 +         ├─ aws:ec2:Subnet  my-vpc-isolated-2       create     1 error
 +         └─ aws:ec2:Subnet  my-vpc-isolated-3       create     

Diagnostics:
  aws:ec2:Subnet (my-vpc-isolated-2):
    error: Duplicate resource URN 'urn:pulumi:dev::awsx-subnet-resize::awsx:ec2:Vpc$aws:ec2/vpc:Vpc$aws:ec2/subnet:Subnet::my-vpc-isolated-2'; try giving it a unique name

  pulumi:pulumi:Stack (awsx-subnet-resize-dev):
    error: Resource monitor has terminated, shutting down

It would be reasonable IMO to close this as "by design", but it might be better to either attempt to auto-name the subnet resources better or to provide an immediate validation error.

jkodroff commented 1 year ago

Thinking about this some more, it might be a better design to do subnets as a map rather than an array. Make the name (the key) required, and make the key subnetSpec minus the name. Just an idea.