forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (69 loc) · 2.25 KB
/
index.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
const pulumi = require("@pulumi/pulumi");
const azure = require("@pulumi/azure");
let config = new pulumi.Config();
let username = config.require("username");
let password = config.require("password");
let resourceGroup = new azure.core.ResourceGroup("server", {
location: azure.Locations.WestUS,
});
let network = new azure.network.VirtualNetwork("server-network", {
resourceGroupName: resourceGroup.name,
addressSpaces: ["10.0.0.0/16"],
subnets: [{
name: "default",
addressPrefix: "10.0.1.0/24",
}],
});
let publicIP = new azure.network.PublicIp("server-ip", {
resourceGroupName: resourceGroup.name,
allocationMethod: "Dynamic",
});
let networkInterface = new azure.network.NetworkInterface("server-nic", {
resourceGroupName: resourceGroup.name,
ipConfigurations: [{
name: "webserveripcfg",
subnetId: network.subnets[0].id,
privateIpAddressAllocation: "Dynamic",
publicIpAddressId: publicIP.id,
}],
});
let userData =
`#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`;
let vm = new azure.compute.VirtualMachine("server-vm", {
resourceGroupName: resourceGroup.name,
networkInterfaceIds: [networkInterface.id],
vmSize: "Standard_A0",
deleteDataDisksOnTermination: true,
deleteOsDiskOnTermination: true,
osProfile: {
computerName: "hostname",
adminUsername: username,
adminPassword: password,
customData: userData,
},
osProfileLinuxConfig: {
disablePasswordAuthentication: false,
},
storageOsDisk: {
createOption: "FromImage",
name: "myosdisk1",
},
storageImageReference: {
publisher: "canonical",
offer: "UbuntuServer",
sku: "16.04-LTS",
version: "latest",
},
});
// The public IP address is not allocated until the VM is running, so we wait
// for that resource to create, and then lookup the IP address again to report
// its public IP.
exports.publicIP = pulumi.all({ id: vm.id, name: publicIP.name, resourceGroupName: publicIP.resourceGroupName }).apply(ip =>
azure.network.getPublicIP({
name: ip.name,
resourceGroupName: ip.resourceGroupName,
}, { async: true }).then(ip => ip.ipAddress)
);