-
Notifications
You must be signed in to change notification settings - Fork 879
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
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
commit aca9d1283e65b15457855e72ef37d3af558941ec
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` | ||
|
||
Login to Azure CLI (you will be prompted to do this during deployment if you forget): | ||
|
||
``` | ||
$ az login | ||
``` | ||
|
||
Preview the deployment of the application: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 &`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to add a line for |
||
|
||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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