cdklabs / cdklabs/cdk-stacksets
StackSet asset deployment dependency not correctly set in construct
- Dominant language
- TypeScript
- Stars
- 118
- Forks
- 25
- Avg merge
- 33m
- Merged PRs (30d)
- 4
Description
If the `StackSet` and `StackSetStack` are nested in a construct, the `StackSet` will not have a dependency set on the `AssetBucketDeployment`, as the `StackSetStack` places the deployment in the scope of its parent stack, but the StackSet checks for the children of its current scope: https://github.com/cdklabs/cdk-stacksets/blob/main/src/stackset.ts#L662-L666
Minimal Reproduction:
```typescript
import { App, Stack } from 'aws-cdk-lib';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { StackSet, StackSetStack, StackSetTarget, StackSetTemplate } from 'cdk-stacksets';
import { Construct } from 'constructs';
const app = new App();
const stack = new Stack(app, 'ParentStack');
const construct = new Construct(stack, 'Construct');
const assetBucket = new Bucket(construct, 'AssetBucket', { bucketName: 'prefix-us-east-1' });
const stackSetStack = new StackSetStack(construct, 'StackSetStack', {
assetBuckets: [assetBucket],
assetBucketPrefix: 'prefix',
});
new Function(stackSetStack, 'TestLambda', {
code: Code.fromAsset('path/to/lambda/code'),
handler: 'index.handler',
runtime: Runtime.NODEJS_20_X,
});
new StackSet(construct, 'MyStackSet', {
target: StackSetTarget.fromOrganizationalUnits({
regions: ['us-east-1'],
organizationalUnits: ['ou-abc123'],
}),
template: StackSetTemplate.fromStackSetStack(stackSetStack),
});
app.synth();
```
Potential Fix:
```typescript
for (const fileAssetResourceName of cdkStacksets.fileAssetResourceNames) {
const fileAssetResource = Stack.of(this).node.tryFindChild(fileAssetResourceName);
fileAssetResource && this.node.addDependency(fileAssetResource);
}
```
Though it is probably better to pass a reference to the AssetBucketDeployment instead of relying on assumptions about the construct tree.
Contributor guide
Research direction
Start with src/stackset.ts at lines 662-666 and run the minimal reproduction through app.synth(). Trace where StackSetStack places AssetBucketDeployment relative to the parent stack and where StackSet searches for file asset resources. Done means the synthesized StackSet has the required dependency when these resources are nested in a construct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100