Web server using Azure Virtual Machine with ComponentResource
An Azure example using Python to provision a webserver using ComponentResource
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 classic-azure-py-webserver-componentcd pulumi-examples/classic-azure-py-webserver-componentThis example uses pulumi.ComponentResource as described here
to create and deploy an Azure Virtual Machine and starts a HTTP server on it.
The use of pulumi.ComponentResource demonstrates how multiple low-level resources
can be composed into a higher-level, reusable abstraction.
Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init -
Set the Azure environment and subscription:
Terminal window pulumi config set azure:environment publicpulumi config set azure:subscriptionId <YOUR_SUBSCRIPTION_ID> -
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. The password is a secret, so we ask Pulumi to encrypt the configuration:
Terminal window pulumi config set username myusernamepulumi config set --secret password Hunter2hunter2 -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Run
pulumi upto preview and deploy the changes:Terminal window pulumi upUpdating (dev):Type Name Status+ pulumi:pulumi:Stack azure-py-webserver-component-dev created+ ├─ custom:app:WebServer server created+ │ ├─ azure:network:PublicIp server-ip created+ │ ├─ azure:network:NetworkInterface server-nic created+ │ └─ azure:compute:VirtualMachine server-vm created+ └─ azure:core:ResourceGroup server created+ └─ azure:network:VirtualNetwork server-network created+ └─ azure:network:Subnet server-subnet createdOutputs:public_ip: "13.64.196.146"Resources:+ 8 createdDuration: 2m9s -
Get the IP address of the newly-created instance from the stack’s outputs, and check that your server is running:
Terminal window pulumi stack output public_ipcurl http://$(pulumi stack output public_ip)13.64.196.146Hello, World!
Cleaning up#
Once you are done, destroy the stack and remove it:
pulumi destroypulumi stack rm