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
67 changes: 47 additions & 20 deletions platform/src/components/aws/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ export interface VpcArgs {
* ```
*/
ami?: Input<string>;
/**
* The ARN of an existing IAM role to use for the NAT instance.
*
* By default, a new IAM role with SSM managed instance core permissions is created.
* Use this to provide a custom role with additional permissions or to comply with
* organizational policies.
*
* @default A new IAM role is created
* @example
* ```ts
* {
* nat: {
* ec2: {
* role: "arn:aws:iam::123456789012:role/my-nat-instance-role"
* }
* }
* }
* ```
*/
role?: Input<string>;
}>;
}
>;
Expand Down Expand Up @@ -725,7 +745,7 @@ export class Vpc extends Component implements Link.Linkable {
if (nat === "ec2") {
return {
type: "ec2" as const,
ec2: { instance: "t4g.nano", ami: undefined },
ec2: { instance: "t4g.nano", ami: undefined, role: undefined },
};
}
if (nat) {
Expand Down Expand Up @@ -938,28 +958,35 @@ export class Vpc extends Component implements Link.Linkable {
),
);

const role = new iam.Role(
`${name}NatInstanceRole`,
{
assumeRolePolicy: iam.getPolicyDocumentOutput({
statements: [
{
actions: ["sts:AssumeRole"],
principals: [
const role = nat.ec2.role
? iam.Role.get(
`${name}NatInstanceRole`,
nat.ec2.role,
{},
{ parent: self },
)
: new iam.Role(
`${name}NatInstanceRole`,
{
assumeRolePolicy: iam.getPolicyDocumentOutput({
statements: [
{
type: "Service",
identifiers: ["ec2.amazonaws.com"],
actions: ["sts:AssumeRole"],
principals: [
{
type: "Service",
identifiers: ["ec2.amazonaws.com"],
},
],
},
],
},
],
}).json,
managedPolicyArns: [
interpolate`arn:${partition}:iam::aws:policy/AmazonSSMManagedInstanceCore`,
],
},
{ parent: self },
);
}).json,
managedPolicyArns: [
interpolate`arn:${partition}:iam::aws:policy/AmazonSSMManagedInstanceCore`,
],
},
{ parent: self },
);

const instanceProfile = new iam.InstanceProfile(
`${name}NatInstanceProfile`,
Expand Down