Web Server Using Azure Virtual Machine
Basic example of an Azure web server accessible over HTTP
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set azure-py-webservercd pulumi-examples/azure-py-webserverThis example deploys an Azure Virtual Machine and starts an HTTP server on it.
Prerequisites#
Deploying and running the program#
-
Create a new stack:
Terminal window pulumi stack init dev -
Set the required configuration for this example. This example requires you to supply a username and password to the virtual machine that we are going to create.
$ pulumi config set azure-native:location westus # any valid Azure region will do$ pulumi config set username webmaster$ pulumi config set password --secret <your-password>Note that
--secretensures your password is encrypted safely. -
Run
pulumi upto preview and deploy the changes:$ pulumi updatePreviewing update (azuredev):Type Name Plan+ pulumi:pulumi:Stack azure-py-webserver-azuredev create+ ├─ azure-native:core:ResourceGroup server create+ ├─ azure-native:network:VirtualNetwork server-network create+ ├─ azure-native:network:PublicIp server-ip create+ ├─ azure-native:network:Subnet server-subnet create+ ├─ azure-native:network:NetworkInterface server-nic create+ └─ azure-native:compute:VirtualMachine server-vm createResources:+ 7 to createDo you want to perform this update? yesUpdating (azuredev):Type Name Status+ pulumi:pulumi:Stack azure-py-webserver-azuredev created+ ├─ azure-native:core:ResourceGroup server created+ ├─ azure-native:network:VirtualNetwork server-network created+ ├─ azure-native:network:PublicIp server-ip created+ ├─ azure-native:network:Subnet server-subnet created+ ├─ azure-native:network:NetworkInterface server-nic created+ └─ azure-native:compute:VirtualMachine server-vm createdOutputs:public_ip: "137.117.15.111"Resources:+ 7 createdDuration: 2m55sPermalink: https://app.pulumi.com/swgillespie/azure-py-webserver/azuredev/updates/3 -
Get the IP address of the newly-created instance from the stack’s outputs:
Terminal window pulumi stack output public_ip137.117.15.111 -
Check to see that your server is now running:
$ curl http://$(pulumi stack output public_ip)Hello, World! -
Destroy the stack:
Terminal window ▶ pulumi destroy --yesPreviewing destroy (azuredev):Type Name Plan- pulumi:pulumi:Stack azure-py-webserver-azuredev delete- ├─ azure-native:compute:VirtualMachine server-vm delete- ├─ azure-native:network:NetworkInterface server-nic delete- ├─ azure-native:network:Subnet server-subnet delete- ├─ azure-native:network:PublicIp server-ip delete- ├─ azure-native:network:VirtualNetwork server-network delete- └─ azure-native:core:ResourceGroup server deleteResources:- 7 to deleteDestroying (azuredev):Type Name Status- pulumi:pulumi:Stack azure-py-webserver-azuredev deleted- ├─ azure-native:compute:VirtualMachine server-vm deleted- ├─ azure-native:network:NetworkInterface server-nic deleted- ├─ azure-native:network:Subnet server-subnet deleted- ├─ azure-native:network:VirtualNetwork server-network deleted- ├─ azure-native:network:PublicIp server-ip deleted- └─ azure-native:core:ResourceGroup server deletedResources:- 7 deletedDuration: 3m49sPermalink: https://app.pulumi.com/swgillespie/azure-py-webserver/azuredev/updates/4