Skip to content

Commit

Permalink
Merge branch 'main' into update-npm-scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
alinadima authored Sep 14, 2023
2 parents 03d568f + e0f3686 commit 935e0c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
12 changes: 2 additions & 10 deletions lib/demo-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { SourceRepo, ProjectKind } from './constructs/source-repo';
import { VMImportBucket } from './vm-import-bucket';
import { Asset } from 'aws-cdk-lib/aws-s3-assets';

const MAX_ALLOWED_LENGTH = 50;

/**
* Properties to allow customizing the build.
*/
Expand Down Expand Up @@ -72,24 +70,18 @@ export class DemoPipelineStack extends cdk.Stack {
const dlFS = this.addFileSystem('Downloads', props.vpc, projectSg);
const tmpFS = this.addFileSystem('Temp', props.vpc, projectSg);

let artifactBucket: IBucket;
let artifactBucket: IBucket | VMImportBucket;
let environmentVariables = {};
let scriptAsset!: Asset;

if (props.projectKind && props.projectKind == ProjectKind.PokyAmi) {
const stackName = id || 'aws4embeddedlinux-ci';
const sanitizedName =
'vmimport-' +
stackName.substring(0, Math.min(stackName.length, MAX_ALLOWED_LENGTH));

scriptAsset = new Asset(this, 'CreateAMIScript', {
path: path.join(__dirname, '../assets/create-ec2-ami.sh'),
});

artifactBucket = new VMImportBucket(this, 'DemoArtifact', {
versioned: true,
enforceSSL: true,
sanitizedRoleName: sanitizedName,
});
environmentVariables = {
IMPORT_BUCKET: {
Expand All @@ -98,7 +90,7 @@ export class DemoPipelineStack extends cdk.Stack {
},
ROLE_NAME: {
type: BuildEnvironmentVariableType.PLAINTEXT,
value: sanitizedName,
value: (artifactBucket as VMImportBucket).roleName,
},
SCRIPT_URL: {
type: BuildEnvironmentVariableType.PLAINTEXT,
Expand Down
7 changes: 5 additions & 2 deletions lib/vm-import-bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const TAG = 'aws4embeddedlinux-ci';

export interface VMImportBucketProps extends s3.BucketProps {
/** The sanitized role name */
readonly sanitizedRoleName: string;
readonly sanitizedRoleName?: string;
}

/**
* ...
*/
export class VMImportBucket extends s3.Bucket {
public readonly roleName: string;
constructor(scope: Construct, id: string, props: VMImportBucketProps) {
super(scope, id, {
...props,
Expand Down Expand Up @@ -48,11 +49,13 @@ export class VMImportBucket extends s3.Bucket {
],
});

new iam.Role(scope, 'VMImportRole', {
const importRole = new iam.Role(scope, 'VMImportRole', {
roleName: props.sanitizedRoleName,
assumedBy: new iam.ServicePrincipal('vmie.amazonaws.com'),
externalIds: ['vmimport'],
inlinePolicies: { importPolicy },
});

this.roleName = importRole.roleName;
}
}
10 changes: 6 additions & 4 deletions test/__snapshots__/demo-pipeline.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ exports[`Demo Pipeline Poky AMI Pipeline - check role name trim 1`] = `
{
"Name": "ROLE_NAME",
"Type": "PLAINTEXT",
"Value": "vmimport-PokyAmiPipeline2ExportsOutputFnGetAttPipelineVpc05",
"Value": {
"Ref": "VMImportRoleAC246CAD",
},
},
{
"Name": "SCRIPT_URL",
Expand Down Expand Up @@ -2085,7 +2087,6 @@ def handler(event, context):
"PolicyName": "importPolicy",
},
],
"RoleName": "vmimport-PokyAmiPipeline2ExportsOutputFnGetAttPipelineVpc05",
},
"Type": "AWS::IAM::Role",
},
Expand Down Expand Up @@ -2286,7 +2287,9 @@ exports[`Demo Pipeline Snapshot Poky AMI Pipeline 1`] = `
{
"Name": "ROLE_NAME",
"Type": "PLAINTEXT",
"Value": "vmimport-MyTestStack",
"Value": {
"Ref": "VMImportRoleAC246CAD",
},
},
{
"Name": "SCRIPT_URL",
Expand Down Expand Up @@ -4205,7 +4208,6 @@ def handler(event, context):
"PolicyName": "importPolicy",
},
],
"RoleName": "vmimport-MyTestStack",
},
"Type": "AWS::IAM::Role",
},
Expand Down

0 comments on commit 935e0c5

Please sign in to comment.