Skip to content

Commit

Permalink
Merge pull request #6 from aws4embeddedlinux/iam-fix
Browse files Browse the repository at this point in the history
Add dynamic component to the VM Import role name
  • Loading branch information
nateglims authored Sep 8, 2023
2 parents 294ef0e + 7638e62 commit 7786c55
Show file tree
Hide file tree
Showing 3 changed files with 2,093 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/vm-import-bucket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as cdk from 'aws-cdk-lib/core';

const MAX_ALLOWED_LENGTH = 50;
/**
* ...
*/
Expand Down Expand Up @@ -31,10 +33,17 @@ export class VMImportBucket extends s3.Bucket {
],
});

const stackName = cdk.Stack.of(this).stackName;
const sanitizedName = stackName.substring(
0,
Math.min(stackName.length, MAX_ALLOWED_LENGTH)
);
const roleName = `vmimport-${sanitizedName}`;

new iam.Role(scope, 'VMImportRole', {
roleName: 'vmimport',
roleName: roleName,
assumedBy: new iam.ServicePrincipal('vmie.amazonaws.com'),
externalIds: ['vmimport'],
externalIds: [roleName],
inlinePolicies: { importPolicy },
});
}
Expand Down
Loading

0 comments on commit 7786c55

Please sign in to comment.