Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ec2): non-agnostic stack throws error with availability zones def…
…ined in VPC (#25468) ## Changes Made The existing code calls a get availabilityZones method off of the stack. If no context is provided, then two possible return values are possible: 1) The stack is deemed agnostic, i.e., the stack has no defined environment, or the environment only contains just an account or just a region. In this case, the return value will be an array of unresolved tokens. 2) The stack is deemed non-agnostic. In this case, the return value will be ['dummy1a', 'dummy1b', 'dummy1c'] In the event of case 1, the filter method is called off of the array of unresolved tokens and attempts to create a new array of 'resolved stack AZs'. However, since the array that filter is called off of contains unresolved tokens, the result is an empty array. Moving forward, the value 'areGivenAzsSubsetOfStack' will be true only because 'resolvedStackAzs' is of length 0. In the event of case 2, the filter method is called off of the array containing dummy values - ['dummy1a', 'dummy1b', 'dummy1c']. Since each element in this array will be considered resolved, the resulting array will also just be ['dummy1a', 'dummy1b', 'dummy1c']. Moving forward from this, the value 'areGivenAzsSubsetOfStack' will be false assuming the user is providing actual availability zones, i.e., 'us-east-1a', 'us-east-1b', etc. The previously mentioned error will then be thrown which is unhelpful for the user as the validation done in this case isn't helpful. As a result, the only useful validation that can occur is in the case that a context has been provided that contains one of two keys: 1) availability-zones:account=${account}:region=${region} 2) aws:cdk:availability-zones:fallback I've updated the validation logic to check for one of these two keys - it first checks for key 1 and then checks for the availability-zones fallback key (key 2). If either of the two keys is found then 'stackAzs' will be equal to the associated key's value. If neither key is found then 'stackAzs' will be undefined. From here, we check if 'stackAzs' is undefined, and if it is then no useful validation can be done so 'areGivenAzsSubsetOfStackAzs' will be true and we will move on without validation. If 'stackAzs' is not undefined, then we can check that each given availability zone exists within the'stackAzs' array. The error mentioned above will only be thrown if 'areGivenAzsSubsetOfStackAzs' if false. Closes #21690 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information