aws / aws/aws-cdk

(aws-docdb): should not try to validate list of subnets if they are unresolved

Open
#14,262 7 comments 10 reactions 0 assignees View on GitHub
@aws-cdk/aws-docdb bug effort/small p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

When importing a VPC information from CloudFormation Export (using fn.import) the cluster constructor does not work.

The VPC.fromVPCAttribute reference the subnets using one "ImportedSubnet". When the DocumentCluster is constructed there is a check for the number of subnets (>=2). However in this case, the array of subnets contains only one object.

tried to comment the test in cluster.js and the CF template is properly created

### Reproduction Steps

Assuming there is a stack exporting the following

Networking-VPC-ID => "vpc-XXXX"
Networking-PrivateSubnets-IDs => "subnet-XXX,subnet-YYY,subnet-ZZZZ"

`
vpc=Vpc.fromVpcAttributes(this.scope, "ImportedVPC", {
vpcId: Fn.importValue("Networking-VPC-ID"),
availabilityZones: Fn.getAzs(Aws.REGION),
privateSubnetIds: Fn.split(",", Fn.importValue("Networking-PrivateSubnets-IDs")),
});

cluster = new DatabaseCluster(this, `DatabaseCluster`, {
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.MEDIUM),
engineVersion: "4.0.0",
masterUser: {
username: 'masterUser' // NOTE: 'admin' is reserved by DocumentDB
},
vpc: vpc,
vpcSubnets: {
subnetType: SubnetType.PRIVATE
}
});
`

Generate the following error:
`
Error: Cluster requires at least 2 subnets, got 1
.....
`

### What did you expect to happen?

I was expecting to create a stack with a SubnetGroup as follow
`
"Type": "AWS::DocDB::DBSubnetGroup",
"Properties": {
"DBSubnetGroupDescription": "Subnet group for DocumentDBConstruct-Database",
"SubnetIds": {
"Fn::Split": [
",",
{
"Fn::ImportValue": "Networking-PrivateSubnets-IDs"
}
]
}
},
`

### What actually happened?

Does not generate the stack. The test in cluster.js
`
if (subnetIds.length < 2) {
throw new Error(`Cluster requires at least 2 subnets, got ${subnetIds.length}`);
}
`

stop the synthetization of the stack

### Environment

- **CDK CLI Version : N/A**
- **Framework Version: 1.97.0**
- **Node.js Version: v15.11.0**
- **OS : Mac OS - N/A**
- **Language (Version): TypeScript **

### Other
Issue is not environement specific. I believe the test in cluster.js to prevent creating a cluster on a VPC with only one Subnet kinda make sense. However it does not take into account the case when the vpc is imported from a CloudFormation Import (Standard practice in CF)

---

This is :bug: Bug Report

Contributor guide

Open the contributing guide

Research direction

Start in cluster.js at the subnet-count validation mentioned in the issue, then review the DocumentCluster construction path for imported VPC attributes. Reproduce with Fn.importValue and Fn.split as shown, and synthesize the stack. Done means unresolved subnet references are accepted and the generated DBSubnetGroup retains the expected Fn::Split and Fn::ImportValue structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.