Skip to content
Open
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
77 changes: 53 additions & 24 deletions platform/src/components/aws/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,33 +1183,62 @@ export class Vpc extends Component implements Link.Linkable {
),
);

const role = new iam.Role(
`${name}BastionRole`,
{
assumeRolePolicy: iam.getPolicyDocumentOutput({
statements: [
// Check if iamInstanceProfile is provided via transform
const bastionTransform = args.transform?.bastionInstance;
const hasCustomInstanceProfile =
bastionTransform &&
typeof bastionTransform === "object" &&
"iamInstanceProfile" in bastionTransform;

const instanceProfile = hasCustomInstanceProfile
? (() => {
const profile = (
bastionTransform as {
iamInstanceProfile: Input<string> | iam.InstanceProfile;
}
).iamInstanceProfile;
// If it's already an InstanceProfile resource, use it directly
if (profile instanceof iam.InstanceProfile) {
return profile;
}
// Otherwise it's a string name, get the existing instance profile
return iam.InstanceProfile.get(
`${name}BastionProfile`,
profile as Input<string>,
{},
{ parent: self },
);
})()
: (() => {
const role = new iam.Role(
`${name}BastionRole`,
{
actions: ["sts:AssumeRole"],
principals: [
{
type: "Service",
identifiers: ["ec2.amazonaws.com"],
},
assumeRolePolicy: iam.getPolicyDocumentOutput({
statements: [
{
actions: ["sts:AssumeRole"],
principals: [
{
type: "Service",
identifiers: ["ec2.amazonaws.com"],
},
],
},
],
}).json,
managedPolicyArns: [
interpolate`arn:${partition}:iam::aws:policy/AmazonSSMManagedInstanceCore`,
],
},
],
}).json,
managedPolicyArns: [
interpolate`arn:${partition}:iam::aws:policy/AmazonSSMManagedInstanceCore`,
],
},
{ parent: self },
);
const instanceProfile = new iam.InstanceProfile(
`${name}BastionProfile`,
{ role: role.name },
{ parent: self },
);
{ parent: self },
);
return new iam.InstanceProfile(
`${name}BastionProfile`,
{ role: role.name },
{ parent: self },
);
})();

const ami = ec2.getAmiOutput(
{
owners: ["amazon"],
Expand Down