> ## Documentation Index
> Fetch the complete documentation index at: https://docs.use.observer/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy to Azure

> An ARM template that runs the agent on a small Linux VM in your own Azure network.

The template puts the Observer Agent on a small Linux VM in a subnet
you choose, or in a new network of its own. From there the agent
checks what that subnet can reach, such as private databases, internal
APIs and Prometheus. It only makes outbound calls: no inbound port is
open. Your cloud's pricing applies to everything the template creates.

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fuseobserver%2Fagent%2Fmain%2Fdeploy%2Fazure%2Fazuredeploy.json)

## What the template creates

All resources are named after `observer-agent`:

* A Linux VM `observer-agent`: Ubuntu 24.04 LTS, `Standard_B1s` by
  default, a Standard SSD OS disk.
* A network interface `observer-agent-nic` with the network security
  group `observer-agent-nsg`. The group has no rules of its own, so
  Azure's default rules deny inbound traffic from the internet.
* A static public IP `observer-agent-ip` for outbound traffic, unless
  you turn it off. Nothing listens on it.
* With no subnet given, a virtual network `observer-agent-vnet`
  (`10.250.0.0/24`) with one subnet, `agent`.
* A Custom Script extension, `observer-agent-install`, that runs the
  [install script](https://docs.use.observer/agent/reference/install-script.md) once. The script
  installs the agent binary as the `observer-agent` systemd service.

The agent key reaches the VM in the extension's protected settings,
which Azure encrypts and never returns. The VM gets a generated admin
password because Azure requires one; no sign-in port is open.

## Before you start

* Create the agent in Observer: **Agents**, **Add agent**, then
  **Cloud platforms**. Copy the key. Observer shows it once.
* To check private services, find the subnet in their virtual network.
  The VM goes in the same subscription and region as that network. The
  subnet needs outbound internet access: keep the public IP on, or put
  the VM in a subnet that already has outbound access through a NAT
  gateway or a firewall.
* Use a new resource group for the agent, in the region of that
  network. Deleting the group later removes the agent cleanly.

To print a subnet's resource ID:

```bash theme={null}
az network vnet subnet show --resource-group my-network-rg \
  --vnet-name my-vnet --name my-subnet --query id --output tsv
```

## Parameters

| Parameter | Portal label | Default | Notes |
| - | - | - | - |
| `agentKey` | Agent Key | | The key from Observer (`obs_live_...`). |
| `cloudServerUrl` | Cloud Server Url | `https://use.observer` | Leave as is. |
| `subnetId` | Subnet Id | empty | Resource ID of a subnet in the network of the services to check. Empty creates a new network for the agent, which reaches only the internet until you peer it. |
| `publicIp` | Public Ip | `true` | Turn it off only when the subnet already has outbound access. |
| `vmSize` | Vm Size | `Standard_B1s` | `Standard_B1ls`, `Standard_B1s` or `Standard_B1ms`. |
| `location` | Location | the resource group's region | |
| `adminPassword` | Admin Password | generated | Leave the generated value. |

## Deploy with the button

**1. Open the template**

Choose **Deploy to Azure** above and sign in. The portal opens a
custom deployment with the template loaded.

**2. Pick the subscription and resource group**

Choose the subscription of the network. Under **Resource group**,
choose **Create new** (for example `observer-agent`) and pick the
region of the network.

**3. Fill in the parameters**

Paste the key into **Agent Key**. Paste the subnet's resource ID into
**Subnet Id**, or leave it empty for a new network. Set **Public Ip**
to `false` only for a subnet that already has outbound access.

**4. Create it**

Choose **Review + create**, then **Create**. The deployment finishes
in a few minutes.

## Deploy with the Azure CLI

```bash theme={null}
az group create --name observer-agent --location westeurope
az deployment group create --resource-group observer-agent \
  --template-uri https://raw.githubusercontent.com/useobserver/agent/main/deploy/azure/azuredeploy.json \
  --parameters agentKey="obs_live_..." \
    subnetId="/subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Network/virtualNetworks/<vnet>/subnets/<subnet>"
```

Drop `subnetId` for a new network. Add `publicIp=false` or
`vmSize=Standard_B1ms` to change the other parameters.

## Check that it connected

A few minutes after the deployment finishes, the Add agent screen shows
**Connected** and the Agents page marks the agent as **running**.

If it does not connect, read the agent's logs. The deployment's
`logs` output (in the portal: the resource group, **Deployments**, the
deployment, **Outputs**) holds the command:

```bash theme={null}
az vm run-command invoke --resource-group observer-agent --name observer-agent \
  --command-id RunShellScript \
  --scripts "journalctl -u observer-agent -n 100 --no-pager" \
  --query "value[0].message" --output tsv
```

The agent logs every failed call to Observer with the reason. The most
common cause is a wrong or replaced agent key.

If the install itself failed, the deployment reports the
`observer-agent-install` extension as failed. Its output is on the VM
in `/var/lib/waagent/custom-script/download/0/` (`stdout` and
`stderr`); read it with the same `run-command` and
`cat /var/lib/waagent/custom-script/download/0/stderr`. The usual cause
is a subnet without outbound internet access.

## Add settings and secrets

The agent reads its environment from `/etc/observer-agent/agent.env`.
To add a variable, such as `PROMETHEUS_SERVER_URL` or a secret that a
probe references by name (`connection_string_ref` and the like),
append it to the file and restart the service:

```bash theme={null}
az vm run-command invoke --resource-group observer-agent --name observer-agent \
  --command-id RunShellScript \
  --scripts "echo 'PROMETHEUS_SERVER_URL=http://10.0.0.5:9090' >> /etc/observer-agent/agent.env && systemctl restart observer-agent"
```

After a [key rotation](https://docs.use.observer/agent/guides/rotate-agent-key.md), replace
`AGENT_KEY` in the same file the same way. See
[Environment variables](https://docs.use.observer/agent/reference/environment-variables.md) for
every setting.

## Upgrades

The template installs the agent binary with the install script. To
upgrade, run the script again on the VM. It replaces the binary,
restarts the service, and keeps the key and your settings:

```bash theme={null}
az vm run-command invoke --resource-group observer-agent --name observer-agent \
  --command-id RunShellScript \
  --scripts "curl -fsSL https://use.observer/install.sh | sh"
```

To install a given release, use `sh -s -- --version <X.Y.Z>` in place
of `sh`.

## Remove

Delete the resource group:

```bash theme={null}
az group delete --name observer-agent
```

Or open the resource group in the portal and choose **Delete resource
group**. Delete the agent in Observer (**Agents**) too if you no longer
need it.

> [!WARNING]
>
> **Shared resource groups**
>
> Deleting a resource group deletes everything in it. If you deployed
> into a group that holds other resources, delete only the agent's: the
> VM `observer-agent` (its OS disk and network interface go with it),
> then `observer-agent-ip`, `observer-agent-nsg` and, if the template
> created it, `observer-agent-vnet`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.