Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Last active September 23, 2025 20:18
Show Gist options
  • Select an option

  • Save kyletaylored/f554a6917b98ba48b4e93b3341517675 to your computer and use it in GitHub Desktop.

Select an option

Save kyletaylored/f554a6917b98ba48b4e93b3341517675 to your computer and use it in GitHub Desktop.
Azure VM on Datadog Example (Bicep)

Datadog Demo VM (Azure B1s)

This template deploys a minimal Ubuntu 22.04 VM (B1s) that:

  • Installs Nginx with a demo HTML page
  • Installs the Datadog Agent via VM Extension
  • Opens ports 22 (SSH) and 80 (HTTP)

One-Click Deploy

Deploy to Azure

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.37.4.10188",
"templateHash": "4989824174550685477"
}
},
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "demo-b1s",
"metadata": {
"description": "Name for the VM and all related resources (prefix)."
}
},
"adminUsername": {
"type": "string",
"defaultValue": "azureuser",
"metadata": {
"description": "Admin username for SSH login."
}
},
"sshPublicKey": {
"type": "securestring",
"metadata": {
"description": "Your public SSH key (e.g., contents of ~/.ssh/id_rsa.pub)."
}
},
"datadogApiKey": {
"type": "securestring",
"metadata": {
"description": "Datadog API key (for the Agent)."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Azure region to deploy into."
}
}
},
"variables": {
"vnetName": "[format('{0}-vnet', parameters('vmName'))]",
"subnetName": "subnet",
"nsgName": "[format('{0}-nsg', parameters('vmName'))]",
"pipName": "[format('{0}-pip', parameters('vmName'))]",
"nicName": "[format('{0}-nic', parameters('vmName'))]"
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2024-03-01",
"name": "[variables('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/24"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2024-03-01",
"name": "[variables('nsgName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "Allow-SSH-22",
"properties": {
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 1000,
"direction": "Inbound"
}
},
{
"name": "Allow-HTTP-80",
"properties": {
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "80",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 1010,
"direction": "Inbound"
}
}
]
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2024-03-01",
"name": "[variables('pipName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAllocationMethod": "Static"
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2024-03-01",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('pipName'))]"
},
"subnet": {
"id": "[reference(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName')), '2024-03-01').subnets[0].id]"
}
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]",
"[resourceId('Microsoft.Network/publicIPAddresses', variables('pipName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2024-03-01",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "Standard_B1s"
},
"storageProfile": {
"imageReference": {
"publisher": "Canonical",
"offer": "0001-com-ubuntu-server-jammy",
"sku": "22_04-lts",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
}
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[format('/home/{0}/.ssh/authorized_keys', parameters('adminUsername'))]",
"keyData": "[parameters('sshPublicKey')]"
}
]
}
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"name": "[format('{0}/{1}', parameters('vmName'), 'customscript')]",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"commandToExecute": "/bin/bash -c \"\\\n set -euxo pipefail; \\\n sudo apt-get update; \\\n sudo apt-get install -y nginx; \\\n sudo systemctl enable --now nginx; \\\n sudo tee /var/www/html/index.html > /dev/null << 'EOF'\\n\\\n<!doctype html>\\n<html lang=\\\"en\\\">\\n<head><meta charset=\\\"utf-8\\\"/><title>Datadog Azure Demo</title></head>\\n<body><h1>It works! 🚀</h1><p>Ubuntu 22.04 • Nginx • B1s VM</p><p>Datadog Agent installed too.</p></body>\\n</html>\\nEOF\\n\""
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"name": "[format('{0}/{1}', parameters('vmName'), 'datadogAgent')]",
"location": "[parameters('location')]",
"properties": {
"publisher": "Datadog.Agent",
"type": "DatadogLinuxAgent",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": {
"api_key": "[parameters('datadogApiKey')]",
"site": "us3.datadoghq.com",
"tags": [
"env:demo",
"workload:webserver",
"migrated:onprem-to-azure"
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
]
}
],
"outputs": {
"publicIp": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('pipName')), '2024-03-01').ipAddress]"
},
"httpUrl": {
"type": "string",
"value": "[format('http://{0}', reference(resourceId('Microsoft.Network/publicIPAddresses', variables('pipName')), '2024-03-01').ipAddress)]"
}
}
}
// Minimal Azure Linux VM (B1s) that auto-installs Nginx + Datadog Agent
// One-file Bicep you can deploy via the Portal, CLI, or a Deploy-to-Azure link
@description('Name for the VM and all related resources (prefix).')
param vmName string = 'demo-b1s'
@description('Admin username for SSH login.')
param adminUsername string = 'azureuser'
@description('Your public SSH key (e.g., contents of ~/.ssh/id_rsa.pub).')
@secure()
param sshPublicKey string
@description('Datadog API key (for the Agent).')
@secure()
param datadogApiKey string
@description('Azure region to deploy into.')
param location string = resourceGroup().location
// Networking
var vnetName = '${vmName}-vnet'
var subnetName = 'subnet'
var nsgName = '${vmName}-nsg'
var pipName = '${vmName}-pip'
var nicName = '${vmName}-nic'
resource vnet 'Microsoft.Network/virtualNetworks@2024-03-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [ '10.0.0.0/24' ]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: '10.0.0.0/24'
}
}
]
}
}
resource nsg 'Microsoft.Network/networkSecurityGroups@2024-03-01' = {
name: nsgName
location: location
properties: {
securityRules: [
{
name: 'Allow-SSH-22'
properties: {
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '22'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 1000
direction: 'Inbound'
}
}
{
name: 'Allow-HTTP-80'
properties: {
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '80'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 1010
direction: 'Inbound'
}
}
]
}
}
resource pip 'Microsoft.Network/publicIPAddresses@2024-03-01' = {
name: pipName
location: location
sku: { name: 'Standard' }
properties: {
publicIPAllocationMethod: 'Static'
}
}
resource nic 'Microsoft.Network/networkInterfaces@2024-03-01' = {
name: nicName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: { id: pip.id }
subnet: { id: vnet.properties.subnets[0].id }
}
}
]
networkSecurityGroup: { id: nsg.id }
}
}
resource vm 'Microsoft.Compute/virtualMachines@2024-03-01' = {
name: vmName
location: location
properties: {
hardwareProfile: { vmSize: 'Standard_B1s' }
storageProfile: {
imageReference: {
publisher: 'Canonical'
offer: '0001-com-ubuntu-server-jammy'
sku: '22_04-lts'
version: 'latest'
}
osDisk: {
createOption: 'FromImage'
managedDisk: { storageAccountType: 'Standard_LRS' }
}
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
linuxConfiguration: {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUsername}/.ssh/authorized_keys'
keyData: sshPublicKey
}
]
}
}
}
networkProfile: {
networkInterfaces: [ { id: nic.id } ]
}
}
}
// Extension 1: Custom Script installs Nginx + static HTML
resource customScript 'Microsoft.Compute/virtualMachines/extensions@2024-07-01' = {
parent: vm
name: 'customscript'
location: location
properties: {
publisher: 'Microsoft.Azure.Extensions'
type: 'CustomScript'
typeHandlerVersion: '2.1'
autoUpgradeMinorVersion: true
settings: {
commandToExecute: '''/bin/bash -c "\
set -euxo pipefail; \
sudo apt-get update; \
sudo apt-get install -y nginx; \
sudo systemctl enable --now nginx; \
sudo tee /var/www/html/index.html > /dev/null << 'EOF'\n\
<!doctype html>\n<html lang=\"en\">\n<head><meta charset=\"utf-8\"/><title>Datadog Azure Demo</title></head>\n<body><h1>It works! 🚀</h1><p>Ubuntu 22.04 • Nginx • B1s VM</p><p>Datadog Agent installed too.</p></body>\n</html>\nEOF\n"'''
}
}
}
// Extension 2: Datadog Linux Agent
resource datadogAgent 'Microsoft.Compute/virtualMachines/extensions@2024-07-01' = {
parent: vm
name: 'datadogAgent'
location: location
properties: {
publisher: 'Datadog.Agent'
type: 'DatadogLinuxAgent'
typeHandlerVersion: '1.0'
autoUpgradeMinorVersion: true
settings: {
api_key: datadogApiKey
site: 'us3.datadoghq.com' // change if using EU or other sites
tags: [
'env:demo'
'workload:webserver'
'migrated:onprem-to-azure'
]
}
}
}
output publicIp string = pip.properties.ipAddress
output httpUrl string = 'http://${pip.properties.ipAddress}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment