Bootstrap: bootstrapping multiple environments with same bootstrap-bucket-name causes inconsistent stack creation
- Dominant language
- TypeScript
- Stars
- 105
- Forks
- 122
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 71
Description
## Bootstrap fails when multiple environments are being bootstrapped with a custom bucketName
### Description
Users can pass in `BootstrappingParameters` to modify how resources are created during bootstrap:
https://github.com/aws/aws-cdk-cli/blob/7517ecc2ded9169028540bc3bfdc8e320b161043/packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts#L66-L72
If `bucketName` is passed in, bootstrap will attempt to create the bucket. If the bucket already exists, the bootstrap operation will fail.
When bootstrapping multiple environments, it is possible to pass in `bucketName`. However, this will cause at least one environment to fail bootstrapping. Assuming the bucket name is not already taken, the first environment that is bootstrapped will use that bucket name and succeed. All other environments will fail to bootstrap, since the bucket name is already taken.
### Reproduction
#### Command-line:
```
cdk bootstrap --all \
--bootstrap-bucket-name my-custom-parameters-bucket-481665128236 \
aws://481665128236/us-east-2 \
aws://481665128236/us-west-1
```
#### Result:
Only one environment is bootstrapped successfully.
### Proposed fix
`BootstrappingParameters` should be passed in per-environment. It should remain optional. The current CLI implementation is as follows:
https://github.com/aws/aws-cdk-cli/blob/7517ecc2ded9169028540bc3bfdc8e320b161043/packages/aws-cdk/lib/cli/cdk-toolkit.ts#L963-L989
`BootstrapEnvironmentOptions` is bootstrap-action-scoped (i.e. account-scoped), but it is passed into `bootstrapEnvironment`, an environment-scoped (i.e. region-scoped) function.
Consider something like the following as a param for bootstrap:
```
interface EnvironmentBootstrapConfig {
readonly environment: string; // The environment descriptor (e.g. 'aws://123456789012/us-east-1')
readonly parameters?: BootstrappingParameters;
// Other environment-specific options that were previously in BootstrapOptions
}
```
Contributor guide
Assessment
This issue has not been assessed yet.