UNPKG

limgen

Version:

Infrastructure as Code generator

69 lines (68 loc) 3.08 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BastionEc2 = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const aws = __importStar(require("@pulumi/aws")); const zod_1 = require("zod"); const prefixed_1 = require("../utils/prefixed"); const bastionEc2Args = zod_1.z.object({ ami: zod_1.z.string().default("ami-055e3d4f0bbeb5878"), instanceType: zod_1.z.string().default("t2.micro"), vpc: zod_1.z.object({ vpcId: zod_1.z.union([zod_1.z.string(), zod_1.z.any()]), privateSubnetIds: zod_1.z.union([zod_1.z.array(zod_1.z.string()), zod_1.z.any()]), }), securityGroups: zod_1.z.array(zod_1.z.instanceof(aws.ec2.SecurityGroup)), }); class BastionEc2 extends pulumi.ComponentResource { constructor(name, args, opts) { super("custom:BastionEc2", name, {}, opts); this._args = bastionEc2Args.parse(args); const role = new aws.iam.Role(`${name}-role`, { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "ec2.amazonaws.com" }), }); new aws.iam.RolePolicyAttachment(`${name}RolePolicyAttachment`, { role: role, policyArn: "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore", }); const instanceProfile = new aws.iam.InstanceProfile(`${name}-instance-profile`, { role: role }); this.instance = new aws.ec2.Instance(name, { ami: this._args.ami, instanceType: this._args.instanceType, subnetId: this._args.vpc.privateSubnetIds[0], vpcSecurityGroupIds: this._args.securityGroups.map(sg => sg.id), iamInstanceProfile: instanceProfile.name, userData: `#!/bin/bash sudo yum install -y amazon-ssm-agent sudo systemctl enable amazon-ssm-agent sudo systemctl start amazon-ssm-agent`, tags: { Name: (0, prefixed_1.prefixed)('bastion'), }, }, { parent: this }); } } exports.BastionEc2 = BastionEc2;