Bicep resource definition
The virtualMachines/runCommands resource type can be deployed with operations that target:
For a list of changed properties in each API version, see change log.
To create a Microsoft.Compute/virtualMachines/runCommands resource, add the following Bicep to your template.
resource symbolicname 'Microsoft.Compute/virtualMachines/runCommands@2021-07-01' = {
parent: resourceSymbolicName
___location: 'string'
name: 'string'
properties: {
asyncExecution: bool
errorBlobUri: 'string'
outputBlobUri: 'string'
parameters: [
{
name: 'string'
value: 'string'
}
]
protectedParameters: [
{
name: 'string'
value: 'string'
}
]
runAsPassword: 'string'
runAsUser: 'string'
source: {
commandId: 'string'
script: 'string'
scriptUri: 'string'
}
timeoutInSeconds: int
}
tags: {
{customized property}: 'string'
}
}
Property Values
Microsoft.Compute/virtualMachines/runCommands
| Name |
Description |
Value |
| ___location |
Resource ___location |
string (required) |
| name |
The resource name |
string (required) |
| parent |
In Bicep, you can specify the parent resource for a child resource. You only need to add this property when the child resource is declared outside of the parent resource.
For more information, see Child resource outside parent resource. |
Symbolic name for resource of type: virtualMachines |
| properties |
Describes the properties of a Virtual Machine run command. |
VirtualMachineRunCommandProperties |
| tags |
Resource tags |
Dictionary of tag names and values. See Tags in templates |
| Name |
Description |
Value |
| name |
The run command parameter name. |
string (required) |
| value |
The run command parameter value. |
string (required) |
VirtualMachineRunCommandProperties
| Name |
Description |
Value |
| asyncExecution |
Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete. |
bool |
| errorBlobUri |
Specifies the Azure storage blob where script error stream will be uploaded. |
string |
| outputBlobUri |
Specifies the Azure storage blob where script output stream will be uploaded. |
string |
| parameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| protectedParameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| runAsPassword |
Specifies the user account password on the VM when executing the run command. |
string |
| runAsUser |
Specifies the user account on the VM when executing the run command. |
string |
| source |
The source of the run command script. |
VirtualMachineRunCommandScriptSource |
| timeoutInSeconds |
The timeout in seconds to execute the run command. |
int |
VirtualMachineRunCommandScriptSource
| Name |
Description |
Value |
| commandId |
Specifies a commandId of predefined built-in script. |
string |
| script |
Specifies the script content to be executed on the VM. |
string |
| scriptUri |
Specifies the script download ___location. |
string |
Usage Examples
Azure Quickstart Samples
The following Azure Quickstart templates contain Bicep samples for deploying this resource type.
| Bicep File |
Description |
| GitLab Omnibus |
This template simplifies the deployment of GitLab Omnibus on a Virtual Machine with a public DNS, leveraging the public IP's DNS. It utilizes the Standard_F8s_v2 instance size, which aligns with reference architecture and supports up to 1000 users (20 RPS). The instance is pre-configured to use HTTPS with a Let's Encrypt certificate for secure connections. |
ARM template resource definition
The virtualMachines/runCommands resource type can be deployed with operations that target:
For a list of changed properties in each API version, see change log.
To create a Microsoft.Compute/virtualMachines/runCommands resource, add the following JSON to your template.
{
"type": "Microsoft.Compute/virtualMachines/runCommands",
"apiVersion": "2021-07-01",
"name": "string",
"___location": "string",
"properties": {
"asyncExecution": "bool",
"errorBlobUri": "string",
"outputBlobUri": "string",
"parameters": [
{
"name": "string",
"value": "string"
}
],
"protectedParameters": [
{
"name": "string",
"value": "string"
}
],
"runAsPassword": "string",
"runAsUser": "string",
"source": {
"commandId": "string",
"script": "string",
"scriptUri": "string"
},
"timeoutInSeconds": "int"
},
"tags": {
"{customized property}": "string"
}
}
Property Values
Microsoft.Compute/virtualMachines/runCommands
| Name |
Description |
Value |
| apiVersion |
The api version |
'2021-07-01' |
| ___location |
Resource ___location |
string (required) |
| name |
The resource name |
string (required) |
| properties |
Describes the properties of a Virtual Machine run command. |
VirtualMachineRunCommandProperties |
| tags |
Resource tags |
Dictionary of tag names and values. See Tags in templates |
| type |
The resource type |
'Microsoft.Compute/virtualMachines/runCommands' |
| Name |
Description |
Value |
| name |
The run command parameter name. |
string (required) |
| value |
The run command parameter value. |
string (required) |
VirtualMachineRunCommandProperties
| Name |
Description |
Value |
| asyncExecution |
Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete. |
bool |
| errorBlobUri |
Specifies the Azure storage blob where script error stream will be uploaded. |
string |
| outputBlobUri |
Specifies the Azure storage blob where script output stream will be uploaded. |
string |
| parameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| protectedParameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| runAsPassword |
Specifies the user account password on the VM when executing the run command. |
string |
| runAsUser |
Specifies the user account on the VM when executing the run command. |
string |
| source |
The source of the run command script. |
VirtualMachineRunCommandScriptSource |
| timeoutInSeconds |
The timeout in seconds to execute the run command. |
int |
VirtualMachineRunCommandScriptSource
| Name |
Description |
Value |
| commandId |
Specifies a commandId of predefined built-in script. |
string |
| script |
Specifies the script content to be executed on the VM. |
string |
| scriptUri |
Specifies the script download ___location. |
string |
Usage Examples
Azure Quickstart Templates
The following Azure Quickstart templates deploy this resource type.
| Template |
Description |
GitLab Omnibus
 |
This template simplifies the deployment of GitLab Omnibus on a Virtual Machine with a public DNS, leveraging the public IP's DNS. It utilizes the Standard_F8s_v2 instance size, which aligns with reference architecture and supports up to 1000 users (20 RPS). The instance is pre-configured to use HTTPS with a Let's Encrypt certificate for secure connections. |
The virtualMachines/runCommands resource type can be deployed with operations that target:
For a list of changed properties in each API version, see change log.
To create a Microsoft.Compute/virtualMachines/runCommands resource, add the following Terraform to your template.
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Compute/virtualMachines/runCommands@2021-07-01"
name = "string"
parent_id = "string"
___location = "string"
tags = {
{customized property} = "string"
}
body = {
properties = {
asyncExecution = bool
errorBlobUri = "string"
outputBlobUri = "string"
parameters = [
{
name = "string"
value = "string"
}
]
protectedParameters = [
{
name = "string"
value = "string"
}
]
runAsPassword = "string"
runAsUser = "string"
source = {
commandId = "string"
script = "string"
scriptUri = "string"
}
timeoutInSeconds = int
}
}
}
Property Values
Microsoft.Compute/virtualMachines/runCommands
| Name |
Description |
Value |
| ___location |
Resource ___location |
string (required) |
| name |
The resource name |
string (required) |
| parent_id |
The ID of the resource that is the parent for this resource. |
ID for resource of type: virtualMachines |
| properties |
Describes the properties of a Virtual Machine run command. |
VirtualMachineRunCommandProperties |
| tags |
Resource tags |
Dictionary of tag names and values. |
| type |
The resource type |
"Microsoft.Compute/virtualMachines/runCommands@2021-07-01" |
| Name |
Description |
Value |
| name |
The run command parameter name. |
string (required) |
| value |
The run command parameter value. |
string (required) |
VirtualMachineRunCommandProperties
| Name |
Description |
Value |
| asyncExecution |
Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete. |
bool |
| errorBlobUri |
Specifies the Azure storage blob where script error stream will be uploaded. |
string |
| outputBlobUri |
Specifies the Azure storage blob where script output stream will be uploaded. |
string |
| parameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| protectedParameters |
The parameters used by the script. |
RunCommandInputParameter[] |
| runAsPassword |
Specifies the user account password on the VM when executing the run command. |
string |
| runAsUser |
Specifies the user account on the VM when executing the run command. |
string |
| source |
The source of the run command script. |
VirtualMachineRunCommandScriptSource |
| timeoutInSeconds |
The timeout in seconds to execute the run command. |
int |
VirtualMachineRunCommandScriptSource
| Name |
Description |
Value |
| commandId |
Specifies a commandId of predefined built-in script. |
string |
| script |
Specifies the script content to be executed on the VM. |
string |
| scriptUri |
Specifies the script download ___location. |
string |
Usage Examples
A basic example of deploying Virtual Machine Run Command.
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "___location" {
type = string
default = "eastus"
}
resource "azapi_resource" "resourceGroup" {
type = "Microsoft.Resources/resourceGroups@2020-06-01"
name = var.resource_name
___location = var.___location
}
resource "azapi_resource" "userAssignedIdentity" {
type = "Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31"
parent_id = azapi_resource.resourceGroup.id
name = "${var.resource_name}-uai"
___location = var.___location
}
resource "azapi_resource" "virtualNetwork" {
type = "Microsoft.Network/virtualNetworks@2024-05-01"
parent_id = azapi_resource.resourceGroup.id
name = "${var.resource_name}-vnet"
___location = var.___location
body = {
properties = {
addressSpace = {
addressPrefixes = ["10.0.0.0/16"]
}
dhcpOptions = {
dnsServers = []
}
privateEndpointVNetPolicies = "Disabled"
subnets = []
}
}
}
resource "azapi_resource" "subnet" {
type = "Microsoft.Network/virtualNetworks/subnets@2024-05-01"
parent_id = azapi_resource.virtualNetwork.id
name = "internal"
body = {
properties = {
addressPrefix = "10.0.2.0/24"
defaultOutboundAccess = true
delegations = []
privateEndpointNetworkPolicies = "Disabled"
privateLinkServiceNetworkPolicies = "Enabled"
serviceEndpointPolicies = []
serviceEndpoints = []
}
}
}
resource "azapi_resource" "networkInterface" {
type = "Microsoft.Network/networkInterfaces@2024-05-01"
parent_id = azapi_resource.resourceGroup.id
name = "${var.resource_name}-nic"
___location = var.___location
body = {
properties = {
enableAcceleratedNetworking = false
enableIPForwarding = false
ipConfigurations = [{
name = "internal"
properties = {
primary = false
privateIPAddressVersion = "IPv4"
privateIPAllocationMethod = "Dynamic"
subnet = {
id = azapi_resource.subnet.id
}
}
}]
}
}
}
resource "azapi_resource" "virtualMachine" {
type = "Microsoft.Compute/virtualMachines@2024-03-01"
parent_id = azapi_resource.resourceGroup.id
name = "${var.resource_name}-vm"
___location = var.___location
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [azapi_resource.userAssignedIdentity.id]
}
body = {
properties = {
additionalCapabilities = {}
applicationProfile = {
galleryApplications = []
}
diagnosticsProfile = {
bootDiagnostics = {
enabled = false
storageUri = ""
}
}
extensionsTimeBudget = "PT1H30M"
hardwareProfile = {
vmSize = "Standard_B2s"
}
networkProfile = {
networkInterfaces = [{
id = azapi_resource.networkInterface.id
properties = {
primary = true
}
}]
}
osProfile = {
adminPassword = "Pa-tn93e"
adminUsername = "adminuser"
allowExtensionOperations = true
computerName = "${var.resource_name}-vm"
linuxConfiguration = {
disablePasswordAuthentication = false
patchSettings = {
assessmentMode = "ImageDefault"
patchMode = "ImageDefault"
}
provisionVMAgent = true
ssh = {
publicKeys = []
}
}
secrets = []
}
priority = "Regular"
storageProfile = {
dataDisks = []
imageReference = {
offer = "0001-com-ubuntu-server-jammy"
publisher = "Canonical"
sku = "22_04-lts"
version = "latest"
}
osDisk = {
caching = "ReadWrite"
createOption = "FromImage"
managedDisk = {
storageAccountType = "Premium_LRS"
}
osType = "Linux"
writeAcceleratorEnabled = false
}
}
}
}
}
resource "azapi_resource" "runCommand" {
type = "Microsoft.Compute/virtualMachines/runCommands@2023-03-01"
parent_id = azapi_resource.virtualMachine.id
name = "${var.resource_name}-runcommand"
___location = var.___location
body = {
properties = {
asyncExecution = false
errorBlobUri = ""
outputBlobUri = ""
parameters = []
protectedParameters = []
runAsPassword = ""
runAsUser = ""
source = {
script = "echo 'hello world'"
}
timeoutInSeconds = 1200
treatFailureAsDeploymentFailure = true
}
}
}