Add nextgen examples for Azure WebServer
* Add nextgen examples for Azure WebServer
Currently in Python and TypeScript.
MODIFY
.gitignore
.gitignore
@@ -6,6 +6,7 @@ build/
node_modules/
*.pyc
.Python
+venv/
include/
lib/
yarn.lock

ADD
azure-nextgen-py-webserver/Pulumi.yaml
+name: azure-py-webserver
+runtime: python
+description: Basic example of an Azure web server accessible over HTTP
+template:
+ config:
+ location:
+ description: The Azure location to deploy to
+ default: westus
+ username:
+ description: The username used to configure the Virtual Machine
+ password:
+ description: The password used to configure the Virtual Machine
+ secret: true

ADD
azure-nextgen-py-webserver/__main__.py
+# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
+
+import base64
+from pulumi import Config, Output, export
+from pulumi_azure_nextgen.compute import latest as compute
+from pulumi_azure_nextgen.network import latest as network
+from pulumi_azure_nextgen.resources import latest as resources
+
+config = Config()
+location = config.get("location") or "westus"
+username = config.require("username")
+password = config.require("password")
+
+resource_group = resources.ResourceGroup("server",
+ resource_group_name="server",
+ location=location)
+
+net = network.VirtualNetwork(
+ "server-network",
+ resource_group_name=resource_group.name,
+ location=location,
+ virtual_network_name="server-network",
+ address_space=network.AddressSpaceArgs(
+ address_prefixes=["10.0.0.0/16"],
+ ),
+ subnets=[network.SubnetArgs(
+ name="default",
+ address_prefix="10.0.1.0/24",
+ )])
+
+public_ip = network.PublicIPAddress(
+ "server-ip",
+ resource_group_name=resource_group.name,
+ location=location,
+ public_ip_address_name="server-ip",
+ public_ip_allocation_method="Dynamic")
+
+network_iface = network.NetworkInterface(
+ "server-nic",
+ resource_group_name=resource_group.name,
+ location=resource_group.location,
+ network_interface_name="server-nic",
+ ip_configurations=[network.NetworkInterfaceIPConfigurationArgs(
+ name="webserveripcfg",
+ subnet=network.SubnetArgs(id=net.subnets[0].id),
+ private_ip_allocation_method="Dynamic",
+ public_ip_address=network.PublicIPAddressArgs(id=public_ip.id),
+ )])
+
+init_script = """#!/bin/bash
+
+echo "Hello, World!" > index.html
+nohup python -m SimpleHTTPServer 80 &"""
+
+vm = compute.VirtualMachine(
+ "server-vm",
+ resource_group_name=resource_group.name,
+ location=location,
+ vm_name="server-vm",
+ network_profile=compute.NetworkProfileArgs(
+ network_interfaces=[
+ compute.NetworkInterfaceReferenceArgs(id=network_iface.id),
+ ],
+ ),
+ hardware_profile=compute.HardwareProfileArgs(
+ vm_size="Standard_A0",
+ ),
+ os_profile=compute.OSProfileArgs(
+ computer_name="hostname",
+ admin_username=username,
+ admin_password=password,
+ custom_data=base64.b64encode(init_script.encode("ascii")).decode("ascii"),
+ linux_configuration=compute.LinuxConfigurationArgs(
+ disable_password_authentication=False,
+ ),
+ ),
+ storage_profile=compute.StorageProfileArgs(
+ os_disk=compute.OSDiskArgs(
+ create_option="FromImage",
+ name="myosdisk1",
+ ),
+ image_reference=compute.ImageReferenceArgs(
+ publisher="canonical",
+ offer="UbuntuServer",
+ sku="16.04-LTS",
+ version="latest",
+ ),
+ ))
+
+combined_output = Output.all(vm.id, public_ip.name, resource_group.name)
+public_ip_addr = combined_output.apply(
+ lambda lst: network.get_public_ip_address(
+ public_ip_address_name=lst[1],
+ resource_group_name=lst[2]))
+export("public_ip", public_ip_addr.ip_address)

ADD
azure-nextgen-py-webserver/requirements.txt
+pulumi>=2.0.0,<3.0.0
+pulumi-azure-nextgen>=0.1.0

ADD
azure-nextgen-ts-webserver/Pulumi.yaml
+name: azure-nextgen-ts-webserver
+runtime: nodejs
+description: Basic example of an Azure web server accessible over HTTP
+template:
+ config:
+ location:
+ description: The Azure location to deploy to
+ default: westus
+ username:
+ description: The username used to configure the Virtual Machine
+ password:
+ description: The password used to configure the Virtual Machine
+ secret: true

ADD
azure-nextgen-ts-webserver/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Web Server Using Azure Virtual Machine
+
+This example provisions a Linux web server in an Azure Virtual Machine and gives it a public IP address.
+
+## Prerequisites
+
+- [Node.js](https://nodejs.org/en/download/)
+- [Download and install the Pulumi CLI](https://www.pulumi.com/docs/get-started/install/)
+- [Connect Pulumi with your Azure account](https://www.pulumi.com/docs/intro/cloud-providers/azure/setup/) (if your `az` CLI is configured, no further changes are required)
+
+## Running the App
+
+1. Create a new stack:
+
+ ```
+ $ pulumi stack init dev
+ ```
+
+1. Configure the app deployment. The username and password here will be used to configure the Virtual Machine. The
+ password must adhere to the [Azure restrictions on VM passwords](
+ https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq#what-are-the-password-requirements-when-creating-a-vm).
+
+ ```
+ $ pulumi config set location westus # any valid Azure region will do
+ $ pulumi config set username webmaster
+ $ pulumi config set password <your-password> --secret
+ ```
+
+ Note that `--secret` ensures your password is encrypted safely.
+
+1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
+
+ ```
+ $ az login
+ ```
+
+1. Restore NPM dependencies:
+
+ ```
+ $ npm install
+ ```
+
+1. Run `pulumi up` to preview and deploy changes:
+
+ ```
+ $ pulumi up
+ Previewing changes:
+ ...
+
+ Performing changes:
+ ...
+ info: 7 changes performed:
+ + 7 resources created
+ Update duration: 2m38s
+ ```
+
+1. Check the IP address:
+
+ ```
+ $ pulumi stack output ipAddress
+ 40.112.181.239
+ ```

ADD
azure-nextgen-ts-webserver/index.ts
+// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
+
+import * as pulumi from "@pulumi/pulumi";
+
+import * as compute from "@pulumi/azure-nextgen/compute/latest";
+import * as network from "@pulumi/azure-nextgen/network/latest";
+import * as resources from "@pulumi/azure-nextgen/resources/latest";
+
+// Get the desired username and password for our VM.
+const config = new pulumi.Config();
+const location = config.get("location") || "westus";
+const username = config.require("username");
+const password = config.requireSecret("password");
+
+// All resources will share a resource group.
+const resourceGroupName = new resources.ResourceGroup("server-rg", {
+ resourceGroupName: "server-rg",
+ location,
+}).name;
+
+// Create a network and subnet for all VMs.
+const virtualNetwork = new network.VirtualNetwork("server-network", {
+ resourceGroupName,
+ location,
+ virtualNetworkName: "server-network",
+ addressSpace: { addressPrefixes: ["10.0.0.0/16"] },
+ subnets: [{
+ name: "default",
+ addressPrefix: "10.0.1.0/24",
+ }],
+});
+
+// Now allocate a public IP and assign it to our NIC.
+const publicIp = new network.PublicIPAddress("server-ip", {
+ resourceGroupName,
+ location,
+ publicIpAddressName: "server-ip",
+ publicIPAllocationMethod: "Dynamic",
+});
+
+const networkInterface = new network.NetworkInterface("server-nic", {
+ resourceGroupName,
+ location,
+ networkInterfaceName: "server-nic",
+ ipConfigurations: [{
+ name: "webserveripcfg",
+ subnet: { id: virtualNetwork.subnets[0].id },
+ privateIPAllocationMethod: "Dynamic",
+ publicIPAddress: { id: publicIp.id },
+ }],
+});
+
+const initScript = `#!/bin/bash\n
+echo "Hello, World!" > index.html
+nohup python -m SimpleHTTPServer 80 &`;
+
+// Now create the VM, using the resource group and NIC allocated above.
+const vm = new compute.VirtualMachine("server-vm", {
+ resourceGroupName,
+ location,
+ vmName: "server-vm",
+ networkProfile: {
+ networkInterfaces: [{ id: networkInterface.id }],
+ },
+ hardwareProfile: {
+ vmSize: "Standard_A0",
+ },
+ osProfile: {
+ computerName: "hostname",
+ adminUsername: username,
+ adminPassword: password,
+ customData: Buffer.from(initScript).toString("base64"),
+ linuxConfiguration: {
+ disablePasswordAuthentication: false,
+ },
+ },
+ storageProfile: {
+ osDisk: {
+ createOption: "FromImage",
+ name: "myosdisk1",
+ },
+ imageReference: {
+ publisher: "canonical",
+ offer: "UbuntuServer",
+ sku: "16.04-LTS",
+ version: "latest",
+ },
+ },
+});
+
+// The public IP address is not allocated until the VM is running, so wait for that
+// resource to create, and then lookup the IP address again to report its public IP.
+const done = pulumi.all({ _: vm.id, name: publicIp.name, resourceGroupName: resourceGroupName });
+
+export const ipAddress = done.apply(async (d) => {
+ return network.getPublicIPAddress({
+ resourceGroupName: d.resourceGroupName,
+ publicIpAddressName: d.name,
+ }).then(ip => ip.ipAddress);
+});

ADD
azure-nextgen-ts-webserver/package.json
+{
+ "name": "azure-nextgen-ts-webserver",
+ "version": "0.1.0",
+ "devDependencies": {
+ "@types/node": "^14.11.1"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "^2.0.0",
+ "@pulumi/azure-nextgen": "^0.1.0"
+ }
+}

ADD
azure-nextgen-ts-webserver/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es2016",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "forceConsistentCasingInFileNames": true,
+ },
+ "files": [
+ "index.ts",
+ ]
+}

Add nextgen examples for Azure WebServer (#799)

* Add nextgen examples for Azure WebServer

Currently in Python and TypeScript.

Co-authored-by: Mikhail Shilkov <github@mikhail.io>