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

fix(core): move mountable's asset to scope of target #369

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/aws-rfdk/lib/core/lib/mountable-ebs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class MountableBlockVolume implements IMountableLinuxFilesystem {

this.grantRequiredPermissions(target);

const mountScriptAsset = this.mountAssetSingleton();
const mountScriptAsset = this.mountAssetSingleton(target);
mountScriptAsset.grantRead(target.grantPrincipal);
const mountScriptZip: string = target.userData.addS3DownloadCommand({
bucket: mountScriptAsset.bucket,
Expand Down Expand Up @@ -189,8 +189,8 @@ export class MountableBlockVolume implements IMountableLinuxFilesystem {
/**
* Fetch the Asset singleton for the Volume mounting scripts, or generate it if needed.
*/
protected mountAssetSingleton(): Asset {
const stack = Stack.of(this.scope);
protected mountAssetSingleton(scope: IConstruct): Asset {
const stack = Stack.of(scope);
const uuid = '01ca4aa6-d440-4f83-84d8-80a5a21fd0e3';
const uniqueId = 'MountableBlockVolumeAsset' + uuid.replace(/[-]/g, '');
return (stack.node.tryFindChild(uniqueId) as Asset) ?? new Asset(stack, uniqueId, {
Expand Down
7 changes: 4 additions & 3 deletions packages/aws-rfdk/lib/core/lib/mountable-efs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@aws-cdk/aws-s3-assets';
import {
Construct,
IConstruct,
IResolvable,
Stack,
isResolvableObject,
Expand Down Expand Up @@ -136,7 +137,7 @@ export class MountableEfs implements IMountableLinuxFilesystem {

target.connections.allowTo(this.props.filesystem, this.props.filesystem.connections.defaultPort as Port);

const mountScriptAsset = this.mountAssetSingleton();
const mountScriptAsset = this.mountAssetSingleton(target);
mountScriptAsset.grantRead(target.grantPrincipal);
const mountScript: string = target.userData.addS3DownloadCommand({
bucket: mountScriptAsset.bucket,
Expand Down Expand Up @@ -214,8 +215,8 @@ export class MountableEfs implements IMountableLinuxFilesystem {
/**
* Fetch the Asset singleton for the EFS mounting scripts, or generate it if needed.
*/
protected mountAssetSingleton(): Asset {
const stack = Stack.of(this.scope);
protected mountAssetSingleton(scope: IConstruct): Asset {
const stack = Stack.of(scope);
const uuid = '2b31c419-5b0b-4bb8-99ad-5b2575b2c06b';
const uniqueId = 'MountableEfsAsset' + uuid.replace(/[-]/g, '');
return (stack.node.tryFindChild(uniqueId) as Asset) ?? new Asset(stack, uniqueId, {
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-rfdk/lib/core/lib/mountable-filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import {
IConnectable,
} from '@aws-cdk/aws-ec2';
import {
IConstruct,
} from '@aws-cdk/core';

import { IScriptHost } from './script-assets';

Expand All @@ -14,7 +17,7 @@ import { IScriptHost } from './script-assets';
* {@link https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Instance.html|EC2 Instance}
* or an {@link https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-autoscaling.AutoScalingGroup.html|EC2 Auto Scaling Group}
*/
export interface IMountingInstance extends IConnectable, IScriptHost {
export interface IMountingInstance extends IConnectable, IConstruct, IScriptHost {
}

/**
Expand Down