-
Notifications
You must be signed in to change notification settings - Fork 880
/
index.ts
51 lines (41 loc) · 1.57 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
const baseTags = {
project: `${pulumi.getProject()}-${pulumi.getStack()}`,
};
const ubuntuAmiId = aws.ec2.getAmi({
mostRecent: true,
nameRegex: "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
owners: ["099720109477"],
}, { async: true }).then(ami => ami.id);
const nginxUserData =
`#!/bin/bash
apt -y update
apt -y install nginx
# Note: This is AWS-specific. This will fail if the example is modified for another provider.
curl http://169.254.169.254/latest/meta-data/instance-id > /var/www/html/index.html
`;
const nginxSecGroup = new aws.ec2.SecurityGroup("nginx", {
description: "admin access",
ingress: [
{ protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] },
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
],
egress: [
{ protocol: "-1", fromPort: 0, toPort: 0, cidrBlocks: ["0.0.0.0/0"] },
],
tags: Object.assign({ Name: `nginx` }, baseTags),
});
const nginxInstances = [];
for (let i = 0; i < 3; i++) {
const nginxInstance = new aws.ec2.Instance(`nginx-${i}`, {
ami: ubuntuAmiId,
instanceType: "t2.medium",
tags: Object.assign({ Name: `nginx-${i}` }, baseTags),
vpcSecurityGroupIds: [nginxSecGroup.id],
userData: nginxUserData,
});
nginxInstances.push(nginxInstance);
}
export const instancePublicIps = nginxInstances.map(instance => instance.publicIp.apply(x => x));