|
{ |
|
"$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)]" |
|
} |
|
} |
|
} |