Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure version of webserver #27

Merged
merged 2 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add Azure version of webserver
Initial example using Azure package.  Similar to the webserver example, but with differences related to how Azure manages VMs.
  • Loading branch information
lukehoban committed Mar 28, 2018
commit aca9d1283e65b15457855e72ef37d3af558941ec
6 changes: 6 additions & 0 deletions webserver-azure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.pulumi/
/bin/
/node_modules/
/yarn.lock
/package-lock.json
/Pulumi.*.yaml
3 changes: 3 additions & 0 deletions webserver-azure/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: webserver-azure
runtime: nodejs
description: Basic example of an Azure web server accessible over HTTP.
56 changes: 56 additions & 0 deletions webserver-azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Pulumi web server (Azure)

Starting point for building the Pulumi web server sample in Azure.

## Running the App

Create a new stack:

```
$ pulumi stack init --local
Enter a stack name: testing
```

Configure the app deployment:

```
$ pulumi config set azure:environment public
$ pulumi config set username testuser
$ pulumi config set --secret password <yourpassword>
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should explain that this is the username and password for the VM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to link to the password requirements. Got an error after deploying, since my password was not sufficiently complex. Article: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq#what-are-the-password-requirements-when-creating-a-vm


Login to Azure CLI (you will be prompted to do this during deployment if you forget):

```
$ az login
```

Preview the deployment of the application:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a step to restore NPM packages.


```
$ pulumi preview
Previewing changes:
[76 lines elided...]
info: 7 changes previewed:
+ 7 resources to create
```

Perform the deployment:

```
$ pulumi update
Performing changes:
[135 lines elided...]
info: 7 changes performed:
+ 7 resources created
Update duration: 2m38.391208237s
```

Check the IP address:

```
$ pulumi stack output privateIP
10.0.2.4
```

*TODO*: Expose the Public IP address as well so that the VM can be SSH'd into or CURL'd directly.
84 changes: 84 additions & 0 deletions webserver-azure/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"use strict";

const pulumi = require("@pulumi/pulumi");
const azure = require("@pulumi/azure");

let config = new pulumi.Config("webserver-azure");
let username = config.require("username");
let password = config.require("password");

let resourceGroup = new azure.core.ResourceGroup("server", {
location: "West US",
});

let network = new azure.network.VirtualNetwork("server-network", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
addressSpaces: ["10.0.0.0/16"],
// Workaround two issues:
// (1) The Azure API recently regressed and now fails when no subnets are defined at Network creation time.
// (2) The Azure Terraform provider does not return the ID of the created subnets - so this cannot actually be used.
subnets: [{
name: "default",
addressPrefix: "10.0.1.0/24",
}],
});

let subnet = new azure.network.Subnet("server-subnet", {
resourceGroupName: resourceGroup.name,
virtualNetworkName: network.name,
addressPrefix: "10.0.2.0/24",
});

let publicIP = new azure.network.PublicIp("server-ip", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
publicIpAddressAllocation: "Dynamic",
});

let networkInterface = new azure.network.NetworkInterface("server-nic", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
ipConfigurations: [{
name: "webserveripcfg",
subnetId: subnet.id,
privateIpAddressAllocation: "Dynamic",
publicIpAddressId: publicIP.id,
}],
});

let userData =
`#!/bin/bash
nohup python -m SimpleHTTPServer 80 &`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to add a line for echo "Hello, World!" > index.html


let vm = new azure.compute.VirtualMachine("server-vm", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
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",
},
});

// Note - due to a bug in the terraform-provider-azurerm, the public IP address is not yet populated corerctly.
exports.publicIP = publicIP.ipAddress;
exports.privateIP = networkInterface.privateIpAddress;
9 changes: 9 additions & 0 deletions webserver-azure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "webserver-azure",
"version": "0.1.0",
"main": "index.js",
"dependencies": {
"@pulumi/pulumi": "^0.11.0",
"@pulumi/azure": "^0.11.0"
}
}