Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Azure VM scale sets

Basic example of nginx deployed in Azure VM Scale Sets written in Python

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set classic-azure-py-vm-scaleset
cd pulumi-examples/classic-azure-py-vm-scaleset

This example provisions a Scale Set of Linux web servers with nginx deployed, configures auto-scaling based on CPU load, puts a Load Balancer in front of them, and gives it a public IP address.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Python

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):

    Terminal window
    az login
  3. Configure the app deployment:

    Terminal window
    pulumi config set azure:location westus # any valid Azure region will do
    pulumi config set azure:subscriptionId <YOUR_SUBSCRIPTION_ID>

    Optionally, configure the username and password for the admin user. Otherwise, they will be auto-generated. Note that --secret ensures your password is encrypted safely.

    Terminal window
    pulumi config set adminUser webmaster
    pulumi config set adminPassword <your-password> --secret
  4. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  5. Run pulumi up to preview and deploy changes:

    Terminal window
    pulumi up
    Previewing update:
    ...
    Updating:
    ...
    Resources:
    13 created
    Update duration: 2m19s
  6. Check the domain name of the PIP:

    Terminal window
    pulumi stack output publicAddress
    curl http://$(pulumi stack output publicAddress)
    dsuv3vqbgi.westeurope.cloudapp.azure.com
    #nginx welcome screen HTML is returned

Cleaning up#

Once you are done, destroy the stack and remove it:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.