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 the example#
-
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. Note that
--secretensures your password is encrypted safely.Terminal window pulumi config set azure-native:location westus # any valid Azure region will dopulumi config set username webmasterpulumi config set password --secret <your-password> -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Deploy the stack:
Terminal window pulumi upUpdating (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: 2m55s -
Get the IP address of the newly-created instance from the stack’s outputs:
Terminal window pulumi stack output public_ip -
Check to see that your server is now running:
Terminal window curl http://$(pulumi stack output public_ip)Hello, World!
Cleaning up#
Once you are finished, you can destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm