---
title: "Virtual Machine on Azure"
description: "Deploy an Azure virtual machine with Pulumi and Azure Virtual Machines in TypeScript, Python, Go, C#, YAML, or HCL."
url: "https://www.pulumi.com/dev/templates/virtual-machine/azure/"
image: "https://www.pulumi.com/assets/og/dev/templates/virtual-machine/azure.png"
---

# Virtual Machine on Azure

Deploy an Azure virtual machine with Pulumi and Azure Virtual Machines in TypeScript, Python, Go, C#, YAML, or HCL.

The Azure Virtual Machine template scaffolds a Pulumi project that provisions an [Azure virtual machine](https://www.pulumi.com/registry/packages/azure-native/api-docs/compute/virtualmachine/) inside a new [Azure Virtual Network](https://www.pulumi.com/registry/packages/azure-native/api-docs/network/virtualnetwork/). The instance boots an HTTP server on port 80 from a small init script, so the project deploys end to end out of the box. Use it as a starting point for a web application, backend service, or database VM.

![An architecture diagram of the Azure Virtual Machine template](./architecture.png)

## Using this template

To use this template to deploy your own virtual machine, make sure you've [installed Pulumi](https://www.pulumi.com/docs/install/) and [configured your Azure credentials](https://www.pulumi.com/registry/packages/azure-native/installation-configuration#credentials), then create a new [project](https://www.pulumi.com/docs/iac/concepts/projects/) using the template in the language of your choice:

**TypeScript**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-typescript
```

**Python**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-python
```

**Go**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-go
```

**C#**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-csharp
```

**YAML**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-yaml
```

**HCL**

```bash
mkdir my-virtual-machine && cd my-virtual-machine
pulumi new vm-azure-hcl
```

Follow the prompts to complete the new-project wizard. When it's done, you'll have a complete Pulumi project that's ready to deploy and configured with the most common settings. Feel free to inspect the code in `index.ts` for a closer look.

## Deploying the project

The template requires no additional configuration. Once the new project is created, you can deploy it immediately with [`pulumi up`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_up):

```bash
$ pulumi up
```

When the deployment completes, Pulumi exports the following [stack output](https://www.pulumi.com/docs/iac/concepts/stacks/#outputs) values:

**TypeScript / Python / Go / C# / YAML**

**`ip`**

The IP address of the virtual machine.

**`hostname`**

The provider-assigned hostname of the virtual machine.

**`url`**

The fully-qualified HTTP URL of the HTTP server running on the virtual machine.

**HCL**

**`ip`**

The IP address of the virtual machine.

**`hostname`**

The provider-assigned hostname of the virtual machine.

**`url`**

The fully-qualified HTTP URL of the HTTP server running on the virtual machine.

**`private_key`**

The PEM-encoded private key for SSH access to the VM. This value is a secret.

Output values like these are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed `url`, for example, can be used from the command line to open the newly deployed website in your favorite web browser:

```bash
$ open $(pulumi stack output url)
```

## Customizing the project

Projects created with the Virtual Machine template expose the following [configuration](https://www.pulumi.com/docs/iac/concepts/config/) settings:

**TypeScript / Python / Go / C# / YAML**

**`adminUsername`**

The user account to create on the VM. Defaults to `pulumiuser`.

**`vmName`**

The DNS hostname prefix to use for the VM. Defaults to `my-server`.

**`vmSize`**

The machine size to use for the VM. Defaults to `Standard_A1_v2`.

**`osImage`**

The Azure URN of the base image to use for the VM. Defaults to `Debian:debian-11:11:latest`.

**`servicePort`**

The HTTP service port to expose on the VM. Defaults to `80`.

**`sshPublicKey`**

The public key data to use for SSH authentication.

**HCL**

**`admin_username`**

The user account to create on the VM. Defaults to `pulumiuser`.

**`vm_name`**

The DNS hostname prefix to use for the VM. Defaults to `my-server`.

**`vm_size`**

The machine size to use for the VM. Defaults to `Standard_A1_v2`.

**`os_image`**

The Azure image reference (publisher:offer:sku:version) to use for the VM. Defaults to `Debian:debian-11:11:latest`.

**`service_port`**

The HTTP service port to expose on the VM. Defaults to `80`.

All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, `Pulumi.dev.yaml`) or by changing their values with [`pulumi config set`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_config_set):

## Cleaning up

You can cleanly destroy the stack and all of its infrastructure with [`pulumi destroy`](https://www.pulumi.com/docs/iac/cli/commands/pulumi_destroy):

```bash
$ pulumi destroy
```

## Learn more

- Browse other architecture templates in the [Templates gallery](https://www.pulumi.com/templates).
- Explore the [Azure Native provider API docs](https://www.pulumi.com/registry/packages/azure-native) in the Pulumi Registry.
- Walk through Pulumi from the ground up in [Pulumi Tutorials](https://www.pulumi.com/dev/browse/?type=tutorial).
- Read the latest [Azure posts on the Pulumi blog](https://www.pulumi.com/blog/tag/azure).
