Microsoft.DocumentDB databaseAccounts/sqlDatabases/containers/userDefinedFunctions

Bicep resource definition

The databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource type can be deployed with operations that target:

For a list of changed properties in each API version, see change log.

Usage Examples

Bicep Samples

A basic example of deploying SQL User Defined Function.

param resourceName string = 'acctest0001'
param location string = 'westeurope'

resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2021-10-15' = {
  name: resourceName
  location: location
  kind: 'GlobalDocumentDB'
  properties: {
    capabilities: []
    consistencyPolicy: {
      defaultConsistencyLevel: 'Session'
      maxIntervalInSeconds: 5
      maxStalenessPrefix: 100
    }
    databaseAccountOfferType: 'Standard'
    defaultIdentity: 'FirstPartyIdentity'
    disableKeyBasedMetadataWriteAccess: false
    disableLocalAuth: false
    enableAnalyticalStorage: false
    enableAutomaticFailover: false
    enableFreeTier: false
    enableMultipleWriteLocations: false
    ipRules: []
    isVirtualNetworkFilterEnabled: false
    locations: [
      {
        failoverPriority: 0
        isZoneRedundant: false
        locationName: 'West Europe'
      }
    ]
    networkAclBypass: 'None'
    networkAclBypassResourceIds: []
    publicNetworkAccess: 'Enabled'
    virtualNetworkRules: []
  }
}

resource sqlDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2021-10-15' = {
  name: resourceName
  parent: databaseAccount
  properties: {
    options: {}
    resource: {
      id: resourceName
    }
  }
}

resource container 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-04-15' = {
  name: resourceName
  parent: sqlDatabase
  properties: {
    options: {}
    resource: {
      id: resourceName
      partitionKey: {
        kind: 'Hash'
        paths: [
          '/definition/id'
        ]
      }
    }
  }
}

resource userDefinedFunction 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions@2021-10-15' = {
  name: resourceName
  parent: container
  properties: {
    options: {}
    resource: {
      body: '''  	function test() {
		var context = getContext();
		var response = context.getResponse();
		response.setBody(''Hello, World'');
	}
'''
      id: resourceName
    }
  }
}

Azure Quickstart Samples

The following Azure Quickstart templates contain Bicep samples for deploying this resource type.

Bicep File Description
Create Azure Cosmos DB Core (SQL) API stored procedures This template creates an Azure Cosmos DB account for Core (SQL) API and a container with a stored procedure, trigger and user defined function.

Resource format

To create a Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource, add the following Bicep to your template.

resource symbolicname 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions@2026-04-01-preview' = {
  parent: resourceSymbolicName
  identity: {
    type: 'string'
    userAssignedIdentities: {
      {customized property}: 'string'
    }
  }
  location: 'string'
  name: 'string'
  properties: {
    resource: {
      body: 'string'
      id: 'string'
    }
  }
  tags: {
    {customized property}: 'string'
  }
}

Property Values

Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions

Name Description Value
identity Identity for the resource. ManagedServiceIdentity
location The location of the resource group to which the resource belongs. string
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: databaseAccounts/sqlDatabases/containers
properties The properties of an Azure Cosmos DB userDefinedFunction SqlUserDefinedFunctionGetProperties
tags Resource tags Dictionary of tag names and values. See Tags in templates

ManagedServiceIdentity

Name Description Value
type The type of identity used for the resource. The type 'SystemAssigned,UserAssigned' includes both an implicitly created identity and a set of user assigned identities. The type 'None' will remove any identities from the service. 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned'
userAssignedIdentities The list of user identities associated with resource. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'. Record

Record

Name Description Value

SqlUserDefinedFunctionGetProperties

Name Description Value
resource SqlUserDefinedFunctionGetPropertiesResource

SqlUserDefinedFunctionGetPropertiesResource

Name Description Value
body Body of the User Defined Function string
id Name of the Cosmos DB SQL userDefinedFunction string (required)

ARM template resource definition

The databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource type can be deployed with operations that target:

Usage Examples

Azure Quickstart Templates

The following Azure Quickstart templates deploy this resource type.

Template Description
Create Azure Cosmos DB Core (SQL) API stored procedures

Deploy to Azure
This template creates an Azure Cosmos DB account for Core (SQL) API and a container with a stored procedure, trigger and user defined function.

Resource format

To create a Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource, add the following JSON to your template.

{
  "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions",
  "apiVersion": "2026-04-01-preview",
  "name": "string",
  "identity": {
    "type": "string",
    "userAssignedIdentities": {
      "{customized property}": "string"
    }
  },
  "location": "string",
  "properties": {
    "resource": {
      "body": "string",
      "id": "string"
    }
  },
  "tags": {
    "{customized property}": "string"
  }
}

Property Values

Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions

Name Description Value
apiVersion The api version '2026-04-01-preview'
identity Identity for the resource. ManagedServiceIdentity
location The location of the resource group to which the resource belongs. string
name The resource name string (required)
properties The properties of an Azure Cosmos DB userDefinedFunction SqlUserDefinedFunctionGetProperties
tags Resource tags Dictionary of tag names and values. See Tags in templates
type The resource type 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions'

ManagedServiceIdentity

Name Description Value
type The type of identity used for the resource. The type 'SystemAssigned,UserAssigned' includes both an implicitly created identity and a set of user assigned identities. The type 'None' will remove any identities from the service. 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned'
userAssignedIdentities The list of user identities associated with resource. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'. Record

Record

Name Description Value

SqlUserDefinedFunctionGetProperties

Name Description Value
resource SqlUserDefinedFunctionGetPropertiesResource

SqlUserDefinedFunctionGetPropertiesResource

Name Description Value
body Body of the User Defined Function string
id Name of the Cosmos DB SQL userDefinedFunction string (required)

Terraform (AzAPI provider) resource definition

The databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource type can be deployed with operations that target:

  • Resource groups For a list of changed properties in each API version, see change log.

Usage Examples

Terraform Samples

A basic example of deploying SQL User Defined Function.

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 = "westeurope"
}

resource "azapi_resource" "resourceGroup" {
  type     = "Microsoft.Resources/resourceGroups@2020-06-01"
  name     = var.resource_name
  location = var.location
}

resource "azapi_resource" "databaseAccount" {
  type      = "Microsoft.DocumentDB/databaseAccounts@2021-10-15"
  parent_id = azapi_resource.resourceGroup.id
  name      = var.resource_name
  location  = var.location
  body = {
    kind = "GlobalDocumentDB"
    properties = {
      capabilities = [
      ]
      consistencyPolicy = {
        defaultConsistencyLevel = "Session"
        maxIntervalInSeconds    = 5
        maxStalenessPrefix      = 100
      }
      databaseAccountOfferType           = "Standard"
      defaultIdentity                    = "FirstPartyIdentity"
      disableKeyBasedMetadataWriteAccess = false
      disableLocalAuth                   = false
      enableAnalyticalStorage            = false
      enableAutomaticFailover            = false
      enableFreeTier                     = false
      enableMultipleWriteLocations       = false
      ipRules = [
      ]
      isVirtualNetworkFilterEnabled = false
      locations = [
        {
          failoverPriority = 0
          isZoneRedundant  = false
          locationName     = "West Europe"
        },
      ]
      networkAclBypass = "None"
      networkAclBypassResourceIds = [
      ]
      publicNetworkAccess = "Enabled"
      virtualNetworkRules = [
      ]
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource" "sqlDatabase" {
  type      = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2021-10-15"
  parent_id = azapi_resource.databaseAccount.id
  name      = var.resource_name
  body = {
    properties = {
      options = {
      }
      resource = {
        id = var.resource_name
      }
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource" "container" {
  type      = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2023-04-15"
  parent_id = azapi_resource.sqlDatabase.id
  name      = var.resource_name
  body = {
    properties = {
      options = {
      }
      resource = {
        id = var.resource_name
        partitionKey = {
          kind = "Hash"
          paths = [
            "/definition/id",
          ]
        }
      }
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource" "userDefinedFunction" {
  type      = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions@2021-10-15"
  parent_id = azapi_resource.container.id
  name      = var.resource_name
  body = {
    properties = {
      options = {
      }
      resource = {
        body = "  \tfunction test() {\n\t\tvar context = getContext();\n\t\tvar response = context.getResponse();\n\t\tresponse.setBody('Hello, World');\n\t}\n"
        id   = var.resource_name
      }
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

Resource format

To create a Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions resource, add the following Terraform to your template.

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions@2026-04-01-preview"
  name = "string"
  parent_id = "string"
  identity {
    type = "string"
    identity_ids = [
      "string"
    ]
  }
  location = "string"
  tags = {
    {customized property} = "string"
  }
  body = {
    properties = {
      resource = {
        body = "string"
        id = "string"
      }
    }
  }
}

Property Values

Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions

Name Description Value
identity Identity for the resource. ManagedServiceIdentity
location The location of the resource group to which the resource belongs. string
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: databaseAccounts/sqlDatabases/containers
properties The properties of an Azure Cosmos DB userDefinedFunction SqlUserDefinedFunctionGetProperties
tags Resource tags Dictionary of tag names and values.
type The resource type "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/userDefinedFunctions@2026-04-01-preview"

ManagedServiceIdentity

Name Description Value
type The type of identity used for the resource. The type 'SystemAssigned,UserAssigned' includes both an implicitly created identity and a set of user assigned identities. The type 'None' will remove any identities from the service. 'None'
'SystemAssigned'
'SystemAssigned,UserAssigned'
'UserAssigned'
userAssignedIdentities The list of user identities associated with resource. The user identity dictionary key references will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'. Record

Record

Name Description Value

SqlUserDefinedFunctionGetProperties

Name Description Value
resource SqlUserDefinedFunctionGetPropertiesResource

SqlUserDefinedFunctionGetPropertiesResource

Name Description Value
body Body of the User Defined Function string
id Name of the Cosmos DB SQL userDefinedFunction string (required)