---
title: "Web Server Component Using Azure Virtual Machine"
description: "Basic example of an Azure web server accessible over HTTP"
url: "https://www.pulumi.com/dev/examples/classic-azure-ts-webserver-component/"
image: "https://www.pulumi.com/assets/og/dev/examples/classic-azure-ts-webserver-component.png"
---

# Web Server Component Using Azure Virtual Machine

Basic example of an Azure web server accessible over HTTP

- Source on GitHub: https://github.com/pulumi/examples/tree/master/classic-azure-ts-webserver-component
- Deploy with Pulumi: https://app.pulumi.com/new?template=https%3A%2F%2Fgithub.com%2Fpulumi%2Fexamples%2Ftree%2Fmaster%2Fclassic-azure-ts-webserver-component

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/classic-azure-ts-webserver-component) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set classic-azure-ts-webserver-component
cd pulumi-examples/classic-azure-ts-webserver-component
```

This example provisions a configurable number of Linux web servers in an Azure Virtual Machine, and returns the
resulting public IP addresses. This example uses a reusable [Pulumi component](
https://www.pulumi.com/docs/intro/concepts/resources/#components) to simplify the creation of new virtual machines. By
defining a `WebServer` class, we can hide many details (see [here](https://github.com/pulumi/examples/tree/master/classic-azure-ts-webserver-component/webserver.ts) for its definition).

## 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:

    ```bash
    pulumi stack init dev
    ```

1. Configure the 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).

    ```bash
    pulumi config set azure:location westus  # any valid Azure region will do
    pulumi config set azure:subscriptionId <YOUR_SUBSCRIPTION_ID>
    pulumi config set username webmaster
    pulumi config set password <your-password> --secret
    pulumi config set count 5                # optional -- will default to 2 if left out
    ```

    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):

    ```bash
    az login
    ```

1. Restore NPM dependencies:

    ```bash
    npm install
    ```

1. Run `pulumi up` to preview and deploy changes:

    ```console
    $ pulumi up
    Previewing changes:
    ...

    Performing changes:
    ...
    info: 15 changes performed:
        + 15 resources created
    Update duration: 4m27s
    ```

1. Check the resulting IP addresses:

    ```console
    $ pulumi stack output ipAddresses
    [ 40.112.181.239, ..., 40.112.181.240 ]
    ```
