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

feat: add file asset support #106

Merged
merged 9 commits into from
Jun 1, 2023
Merged

feat: add file asset support #106

merged 9 commits into from
Jun 1, 2023

Conversation

josh-demuth
Copy link
Contributor

@josh-demuth josh-demuth commented May 6, 2023

Fixes #58

Mimics file asset support from the Service Catalog L2 construct. Uses the S3 bucket deployment construct called in the parent stack to send artifacts to an S3 bucket passed a prop to the StackSet stack. The bucket deployment and resources needed to faciliate it are siblings to the AWS::CloudFormation::StackSet resource in the synthesized CloudFormation template. The asset bucket must be outside the CDK-owned asset bucket process and is passed as a prop.

We also need to ensure the bucket deployment process finishes before we try to run the StackSet so there is a dependency added after the creation of the StackSet resource. This is done using a construct name shared across the synthesis and StackSet creation processes. I'm open to feedback on if there is a better way to do this. But we do need to ensure the bucket deployment finishes before CloudFormation creates/updates the StackSet resource.

There is also potential to create another type of StackSynthesizer and let StackSet and Service Catalog share it since this logic is very similar to how service catalog does it.

I also plan to add some additional integration tests to validate more features of the file asset process but wanted to open the pull request to get eyes and feedback on the approach while finishing up the tests. I also think more scenarios could be added to the README to clear up any complexity.

@josh-demuth josh-demuth changed the title Add file asset support feat: add file asset support May 6, 2023
private physicalNameOfBucket(bucket: IBucket) {
let resolvedName;
if (Resource.isOwnedResource(bucket)) {
resolvedName = Stack.of(bucket).resolve((bucket.node.defaultChild as CfnBucket).bucketName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the service catalog L2 had this but i'm not sure why it is needed vs just using bucket.bucketName. this part fails an integration test i had when creating a bucket and passing to the construct vs doing a bucket import. it wasn't able to get the name from the token - but this logic works in an actual cdk deploy.

import { Construct } from 'constructs';

export const fileAssetResourceName = 'StackSetAssetsBucketDeployment';
Copy link
Contributor Author

@josh-demuth josh-demuth May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed so we can export the construct name so we can find it after creating our StackSet resource so we can add a dependency. the bucket deployment must finish before the StackSet resource is created. Open to ideas on better naming conventions and/or better ways to accomplish this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the bucketDeployment property public and then we could access
it.

(Stack.of(this).synthesizer as StackSetStackSynthesizer).bucketDeployment


// the file asset bucket deployment needs to complete before the stackset can deploy
const fileAssetResource = scope.node.tryFindChild(fileAssetResourceName);
fileAssetResource && stackSet.node.addDependency(fileAssetResource);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking about forcing a dependency on all sibling resources to the StackSet resource here. but opted for this more targeted approach. but i still like the idea of forcing the StackSet resource to always be last in the deployment if there is a clean way to do that.

@@ -5,12 +5,12 @@ const project = new CdklabsConstructLibrary({
projenrcTs: true,
author: 'AWS',
authorAddress: 'aws-cdk-dev@amazon.com',
cdkVersion: '2.45.0',
cdkVersion: '2.77.0',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bucket deployment process complained about the addSource call when building the bucket deployment object. upgrading the CDK version fixed that - but i'm not sure if this is truly required. but didn't think it would cause other harm.

@gfawcett22
Copy link

Perhaps request @otaviomacedo and @corymhall to review?

Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I just have 1 minor comment

src/stackset-stack.ts Outdated Show resolved Hide resolved
import { Construct } from 'constructs';

export const fileAssetResourceName = 'StackSetAssetsBucketDeployment';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the bucketDeployment property public and then we could access
it.

(Stack.of(this).synthesizer as StackSetStackSynthesizer).bucketDeployment

@mergify mergify bot merged commit 792f280 into cdklabs:main Jun 1, 2023
@josh-demuth josh-demuth deleted the file-assets branch June 1, 2023 20:58
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

Successfully merging this pull request may close these issues.

(stacksets)feat: Add support for Assets for stacksets construct
3 participants