Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackSet asset deployment dependency not correctly set in construct #619

Open
cgatt opened this issue Oct 28, 2024 · 0 comments
Open

StackSet asset deployment dependency not correctly set in construct #619

cgatt opened this issue Oct 28, 2024 · 0 comments

Comments

@cgatt
Copy link

cgatt commented Oct 28, 2024

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:

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant