Azure Batch Job

This page shows how to write Terraform and Azure Resource Manager for Batch Job and write them securely.

azurerm_batch_job (Terraform)

The Job in Batch can be configured in Terraform with the resource name azurerm_batch_job. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The following arguments are supported:

  • batch_pool_id - (Required) The ID of the Batch Pool. Changing this forces a new Batch Job to be created.

  • name - (Required) The name which should be used for this Batch Job. Changing this forces a new Batch Job to be created.


  • common_environment_properties - (Optional) Specifies a map of common environment settings applied to this Batch Job. Changing this forces a new Batch Job to be created.

  • display_name - (Optional) The display name of this Batch Job. Changing this forces a new Batch Job to be created.

  • task_retry_maximum - (Optional) The number of retries to each Batch Task belongs to this Batch Job. If this is set to 0, the Batch service does not retry Tasks. If this is set to -1, the Batch service retries Batch Tasks without limit. Default value is 0.

  • priority - (Optional) The priority of this Batch Job, possible values can range from -1000 (lowest) to 1000 (highest). Defaults to 0.

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Batch Job.

Explanation in Terraform Registry

Manages a Batch Job.

Microsoft.Batch/batchAccounts/pools (Azure Resource Manager)

The batchAccounts/pools in Microsoft.Batch can be configured in Azure Resource Manager with the resource name Microsoft.Batch/batchAccounts/pools. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Parameters

  • apiVersion required - string
  • identity optional
      • type required - string

        The type of identity used for the Batch Pool.

      • userAssignedIdentities optional - undefined

        The list of user identities associated with the Batch pool.

  • name required - string

    The pool name. This must be unique within the account.

  • properties required
      • applicationLicenses optional - array

        The list of application licenses must be a subset of available Batch service application licenses. If a license is requested which is not supported, pool creation will fail.

      • applicationPackages optional array
          • id required - string
          • version optional - string

            If this is omitted, and no default version is specified for this application, the request fails with the error code InvalidApplicationPackageReferences. If you are calling the REST API directly, the HTTP status code is 409.

      • certificates optional array
          • id required - string
          • storeLocation optional - string

            The default value is currentUser. This property is applicable only for pools configured with Windows nodes (that is, created with cloudServiceConfiguration, or with virtualMachineConfiguration using a Windows image reference). For Linux compute nodes, the certificates are stored in a directory inside the task working directory and an environment variable AZ_BATCH_CERTIFICATES_DIR is supplied to the task to query for this location. For certificates with visibility of 'remoteUser', a 'certs' directory is created in the user's home directory (e.g., /home/{user-name}/certs) and certificates are placed in that directory.

          • storeName optional - string

            This property is applicable only for pools configured with Windows nodes (that is, created with cloudServiceConfiguration, or with virtualMachineConfiguration using a Windows image reference). Common store names include: My, Root, CA, Trust, Disallowed, TrustedPeople, TrustedPublisher, AuthRoot, AddressBook, but any custom store name can also be used. The default value is My.

          • visibility optional - array
      • deploymentConfiguration optional
          • cloudServiceConfiguration optional
              • osFamily required - string

                Possible values are: 2 - OS Family 2, equivalent to Windows Server 2008 R2 SP1. 3 - OS Family 3, equivalent to Windows Server 2012. 4 - OS Family 4, equivalent to Windows Server 2012 R2. 5 - OS Family 5, equivalent to Windows Server 2016. 6 - OS Family 6, equivalent to Windows Server 2019. For more information, see Azure Guest OS Releases (https://azure.microsoft.com/documentation/articles/cloud-services-guestos-update-matrix/#releases).

              • osVersion optional - string

                The default value is * which specifies the latest operating system version for the specified OS family.

          • virtualMachineConfiguration optional
              • containerConfiguration optional
                  • containerImageNames optional - array

                    This is the full image reference, as would be specified to "docker pull". An image will be sourced from the default Docker registry unless the image is fully qualified with an alternative registry.

                  • containerRegistries optional array
                      • identityReference optional
                          • resourceId optional - string

                            The ARM resource id of the user assigned identity.

                      • password optional - string
                      • registryServer optional - string

                        If omitted, the default is "docker.io".

                      • username optional - string
                  • type required - string
              • dataDisks optional array
                  • caching optional - string

                    Values are: none - The caching mode for the disk is not enabled. readOnly - The caching mode for the disk is read only. readWrite - The caching mode for the disk is read and write. The default value for caching is none. For information about the caching options see: https://blogs.msdn.microsoft.com/windowsazurestorage/2012/06/27/exploring-windows-azure-drives-disks-and-images/.

                  • diskSizeGB required - integer
                  • lun required - integer

                    The lun is used to uniquely identify each data disk. If attaching multiple disks, each should have a distinct lun. The value must be between 0 and 63, inclusive.

                  • storageAccountType optional - string

                    If omitted, the default is "Standard_LRS". Values are: Standard_LRS - The data disk should use standard locally redundant storage. Premium_LRS - The data disk should use premium locally redundant storage.

              • diskEncryptionConfiguration optional
                  • targets optional - array

                    On Linux pool, only "TemporaryDisk" is supported; on Windows pool, "OsDisk" and "TemporaryDisk" must be specified.

              • extensions optional array
                  • autoUpgradeMinorVersion optional - boolean

                    Indicates whether the extension should use a newer minor version if one is available at deployment time. Once deployed, however, the extension will not upgrade minor versions unless redeployed, even with this property set to true.

                  • name required - string
                  • protectedSettings optional - object

                    The extension can contain either protectedSettings or protectedSettingsFromKeyVault or no protected settings at all.

                  • provisionAfterExtensions optional - array

                    Collection of extension names after which this extension needs to be provisioned.

                  • publisher required - string
                  • settings optional - object
                  • type required - string
                  • typeHandlerVersion optional - string
              • imageReference required
                  • id optional - string

                    This property is mutually exclusive with other properties. The Shared Image Gallery image must have replicas in the same region as the Azure Batch account. For information about the firewall settings for the Batch node agent to communicate with the Batch service see https://docs.microsoft.com/en-us/azure/batch/batch-api-basics#virtual-network-vnet-and-firewall-configuration.

                  • offer optional - string

                    For example, UbuntuServer or WindowsServer.

                  • publisher optional - string

                    For example, Canonical or MicrosoftWindowsServer.

                  • sku optional - string

                    For example, 18.04-LTS or 2019-Datacenter.

                  • version optional - string

                    A value of 'latest' can be specified to select the latest version of an image. If omitted, the default is 'latest'.

              • licenseType optional - string

                This only applies to images that contain the Windows operating system, and should only be used when you hold valid on-premises licenses for the nodes which will be deployed. If omitted, no on-premises licensing discount is applied. Values are: Windows_Server - The on-premises license is for Windows Server. Windows_Client - The on-premises license is for Windows Client.

              • nodeAgentSkuId required - string

                The Batch node agent is a program that runs on each node in the pool, and provides the command-and-control interface between the node and the Batch service. There are different implementations of the node agent, known as SKUs, for different operating systems. You must specify a node agent SKU which matches the selected image reference. To get the list of supported node agent SKUs along with their list of verified image references, see the 'List supported node agent SKUs' operation.

              • nodePlacementConfiguration optional
                  • policy optional - string

                    Allocation policy used by Batch Service to provision the nodes. If not specified, Batch will use the regional policy.

              • osDisk optional
              • windowsConfiguration optional
                  • enableAutomaticUpdates optional - boolean

                    If omitted, the default value is true.

      • displayName optional - string

        The display name need not be unique and can contain any Unicode characters up to a maximum length of 1024.

      • interNodeCommunication optional - string

        This imposes restrictions on which nodes can be assigned to the pool. Enabling this value can reduce the chance of the requested number of nodes to be allocated in the pool. If not specified, this value defaults to 'Disabled'.

      • metadata optional array
          • name required - string
          • value required - string
      • mountConfiguration optional array
          • azureBlobFileSystemConfiguration optional
              • accountKey optional - string

                This property is mutually exclusive with both sasKey and identity; exactly one must be specified.

              • accountName required - string
              • blobfuseOptions optional - string

                These are 'net use' options in Windows and 'mount' options in Linux.

              • containerName required - string
              • identityReference optional
                  • resourceId optional - string

                    The ARM resource id of the user assigned identity.

              • relativeMountPath required - string

                All file systems are mounted relative to the Batch mounts directory, accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable.

              • sasKey optional - string

                This property is mutually exclusive with both accountKey and identity; exactly one must be specified.

          • azureFileShareConfiguration optional
              • accountKey required - string
              • accountName required - string
              • azureFileUrl required - string

                This is of the form 'https://{account}.file.core.windows.net/'.

              • mountOptions optional - string

                These are 'net use' options in Windows and 'mount' options in Linux.

              • relativeMountPath required - string

                All file systems are mounted relative to the Batch mounts directory, accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable.

          • cifsMountConfiguration optional
              • mountOptions optional - string

                These are 'net use' options in Windows and 'mount' options in Linux.

              • password required - string
              • relativeMountPath required - string

                All file systems are mounted relative to the Batch mounts directory, accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable.

              • source required - string
              • username required - string
          • nfsMountConfiguration optional
              • mountOptions optional - string

                These are 'net use' options in Windows and 'mount' options in Linux.

              • relativeMountPath required - string

                All file systems are mounted relative to the Batch mounts directory, accessible via the AZ_BATCH_NODE_MOUNTS_DIR environment variable.

              • source required - string
      • networkConfiguration optional
          • endpointConfiguration optional
              • inboundNatPools required array
                  • backendPort required - integer

                    This must be unique within a Batch pool. Acceptable values are between 1 and 65535 except for 22, 3389, 29876 and 29877 as these are reserved. If any reserved values are provided the request fails with HTTP status code 400.

                  • frontendPortRangeEnd required - integer

                    Acceptable values range between 1 and 65534 except ports from 50000 to 55000 which are reserved by the Batch service. All ranges within a pool must be distinct and cannot overlap. If any reserved or overlapping values are provided the request fails with HTTP status code 400.

                  • frontendPortRangeStart required - integer

                    Acceptable values range between 1 and 65534 except ports from 50000 to 55000 which are reserved. All ranges within a pool must be distinct and cannot overlap. If any reserved or overlapping values are provided the request fails with HTTP status code 400.

                  • name required - string

                    The name must be unique within a Batch pool, can contain letters, numbers, underscores, periods, and hyphens. Names must start with a letter or number, must end with a letter, number, or underscore, and cannot exceed 77 characters. If any invalid values are provided the request fails with HTTP status code 400.

                  • networkSecurityGroupRules optional array
                      • access required - string
                      • priority required - integer

                        Priorities within a pool must be unique and are evaluated in order of priority. The lower the number the higher the priority. For example, rules could be specified with order numbers of 150, 250, and 350. The rule with the order number of 150 takes precedence over the rule that has an order of 250. Allowed priorities are 150 to 4096. If any reserved or duplicate values are provided the request fails with HTTP status code 400.

                      • sourceAddressPrefix required - string

                        Valid values are a single IP address (i.e. 10.10.10.10), IP subnet (i.e. 192.168.1.0/24), default tag, or * (for all addresses). If any other values are provided the request fails with HTTP status code 400.

                      • sourcePortRanges optional - array

                        Valid values are '' (for all ports 0 - 65535) or arrays of ports or port ranges (i.e. 100-200). The ports should in the range of 0 to 65535 and the port ranges or ports can't overlap. If any other values are provided the request fails with HTTP status code 400. Default value will be .

                  • protocol required - string
          • publicIPAddressConfiguration optional
              • ipAddressIds optional - array

                The number of IPs specified here limits the maximum size of the Pool - 100 dedicated nodes or 100 low-priority nodes can be allocated for each public IP. For example, a pool needing 250 dedicated VMs would need at least 3 public IPs specified. Each element of this collection is of the form: /subscriptions/{subscription}/resourceGroups/{group}/providers/Microsoft.Network/publicIPAddresses/{ip}.

              • provision optional - string

                The default value is BatchManaged.

          • subnetId optional - string

            The virtual network must be in the same region and subscription as the Azure Batch account. The specified subnet should have enough free IP addresses to accommodate the number of nodes in the pool. If the subnet doesn't have enough free IP addresses, the pool will partially allocate compute nodes and a resize error will occur. The 'MicrosoftAzureBatch' service principal must have the 'Classic Virtual Machine Contributor' Role-Based Access Control (RBAC) role for the specified VNet. The specified subnet must allow communication from the Azure Batch service to be able to schedule tasks on the compute nodes. This can be verified by checking if the specified VNet has any associated Network Security Groups (NSG). If communication to the compute nodes in the specified subnet is denied by an NSG, then the Batch service will set the state of the compute nodes to unusable. If the specified VNet has any associated Network Security Groups (NSG), then a few reserved system ports must be enabled for inbound communication. For pools created with a virtual machine configuration, enable ports 29876 and 29877, as well as port 22 for Linux and port 3389 for Windows. For pools created with a cloud service configuration, enable ports 10100, 20100, and 30100. Also enable outbound connections to Azure Storage on port 443. For cloudServiceConfiguration pools, only 'classic' VNETs are supported. For more details see: https://docs.microsoft.com/en-us/azure/batch/batch-api-basics#virtual-network-vnet-and-firewall-configuration

      • scaleSettings optional
          • autoScale optional
              • evaluationInterval optional - string

                If omitted, the default value is 15 minutes (PT15M).

              • formula required - string
          • fixedScale optional
              • nodeDeallocationOption optional - string

                If omitted, the default value is Requeue.

              • resizeTimeout optional - string

                The default value is 15 minutes. Timeout values use ISO 8601 format. For example, use PT10M for 10 minutes. The minimum value is 5 minutes. If you specify a value less than 5 minutes, the Batch service rejects the request with an error; if you are calling the REST API directly, the HTTP status code is 400 (Bad Request).

              • targetDedicatedNodes optional - integer

                At least one of targetDedicatedNodes, targetLowPriorityNodes must be set.

              • targetLowPriorityNodes optional - integer

                At least one of targetDedicatedNodes, targetLowPriorityNodes must be set.

      • startTask optional
          • commandLine optional - string

            The command line does not run under a shell, and therefore cannot take advantage of shell features such as environment variable expansion. If you want to take advantage of such features, you should invoke the shell in the command line, for example using "cmd /c MyCommand" in Windows or "/bin/sh -c MyCommand" in Linux. Required if any other properties of the startTask are specified.

          • containerSettings optional
              • containerRunOptions optional - string

                These additional options are supplied as arguments to the "docker create" command, in addition to those controlled by the Batch Service.

              • imageName required - string

                This is the full image reference, as would be specified to "docker pull". If no tag is provided as part of the image name, the tag ":latest" is used as a default.

              • registry optional
                  • identityReference optional
                      • resourceId optional - string

                        The ARM resource id of the user assigned identity.

                  • password optional - string
                  • registryServer optional - string

                    If omitted, the default is "docker.io".

                  • username optional - string
              • workingDirectory optional - string
          • environmentSettings optional array
              • name required - string
              • value optional - string
          • maxTaskRetryCount optional - integer

            The Batch service retries a task if its exit code is nonzero. Note that this value specifically controls the number of retries. The Batch service will try the task once, and may then retry up to this limit. For example, if the maximum retry count is 3, Batch tries the task up to 4 times (one initial try and 3 retries). If the maximum retry count is 0, the Batch service does not retry the task. If the maximum retry count is -1, the Batch service retries the task without limit.

          • resourceFiles optional array
              • autoStorageContainerName optional - string

                The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified.

              • blobPrefix optional - string

                The property is valid only when autoStorageContainerName or storageContainerUrl is used. This prefix can be a partial filename or a subdirectory. If a prefix is not specified, all the files in the container will be downloaded.

              • fileMode optional - string

                This property applies only to files being downloaded to Linux compute nodes. It will be ignored if it is specified for a resourceFile which will be downloaded to a Windows node. If this property is not specified for a Linux node, then a default value of 0770 is applied to the file.

              • filePath optional - string

                If the httpUrl property is specified, the filePath is required and describes the path which the file will be downloaded to, including the filename. Otherwise, if the autoStorageContainerName or storageContainerUrl property is specified, filePath is optional and is the directory to download the files to. In the case where filePath is used as a directory, any directory structure already associated with the input data will be retained in full and appended to the specified filePath directory. The specified relative path cannot break out of the task's working directory (for example by using '..').

              • httpUrl optional - string

                The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified. If the URL points to Azure Blob Storage, it must be readable from compute nodes. There are three ways to get such a URL for a blob in Azure storage: include a Shared Access Signature (SAS) granting read permissions on the blob, use a managed identity with read permission, or set the ACL for the blob or its container to allow public access.

              • identityReference optional
                  • resourceId optional - string

                    The ARM resource id of the user assigned identity.

              • storageContainerUrl optional - string

                The autoStorageContainerName, storageContainerUrl and httpUrl properties are mutually exclusive and one of them must be specified. This URL must be readable and listable from compute nodes. There are three ways to get such a URL for a container in Azure storage: include a Shared Access Signature (SAS) granting read and list permissions on the container, use a managed identity with read and list permissions, or set the ACL for the container to allow public access.

          • userIdentity optional
              • autoUser optional
                  • elevationLevel optional - string

                    The default value is nonAdmin.

                  • scope optional - string

                    The default value is Pool. If the pool is running Windows a value of Task should be specified if stricter isolation between tasks is required. For example, if the task mutates the registry in a way which could impact other tasks, or if certificates have been specified on the pool which should not be accessible by normal tasks but should be accessible by start tasks.

              • userName optional - string

                The userName and autoUser properties are mutually exclusive; you must specify one but not both.

          • waitForSuccess optional - boolean

            If true and the start task fails on a compute node, the Batch service retries the start task up to its maximum retry count (maxTaskRetryCount). If the task has still not completed successfully after all retries, then the Batch service marks the compute node unusable, and will not schedule tasks to it. This condition can be detected via the node state and scheduling error detail. If false, the Batch service will not wait for the start task to complete. In this case, other tasks can start executing on the compute node while the start task is still running; and even if the start task fails, new tasks will continue to be scheduled on the node. The default is true.

      • taskSchedulingPolicy optional
          • nodeFillType required - string
      • taskSlotsPerNode optional - integer

        The default value is 1. The maximum value is the smaller of 4 times the number of cores of the vmSize of the pool or 256.

      • userAccounts optional array
          • elevationLevel optional - string

            nonAdmin - The auto user is a standard user without elevated access. admin - The auto user is a user with elevated access and operates with full Administrator permissions. The default value is nonAdmin.

          • linuxUserConfiguration optional
              • gid optional - integer

                The uid and gid properties must be specified together or not at all. If not specified the underlying operating system picks the gid.

              • sshPrivateKey optional - string

                The private key must not be password protected. The private key is used to automatically configure asymmetric-key based authentication for SSH between nodes in a Linux pool when the pool's enableInterNodeCommunication property is true (it is ignored if enableInterNodeCommunication is false). It does this by placing the key pair into the user's .ssh directory. If not specified, password-less SSH is not configured between nodes (no modification of the user's .ssh directory is done).

              • uid optional - integer

                The uid and gid properties must be specified together or not at all. If not specified the underlying operating system picks the uid.

          • name required - string
          • password required - string
          • windowsUserConfiguration optional
              • loginMode optional - string

                Specifies login mode for the user. The default value for VirtualMachineConfiguration pools is interactive mode and for CloudServiceConfiguration pools is batch mode.

      • vmSize optional - string

        For information about available sizes of virtual machines for Cloud Services pools (pools created with cloudServiceConfiguration), see Sizes for Cloud Services (https://azure.microsoft.com/documentation/articles/cloud-services-sizes-specs/). Batch supports all Cloud Services VM sizes except ExtraSmall. For information about available VM sizes for pools using images from the Virtual Machines Marketplace (pools created with virtualMachineConfiguration) see Sizes for Virtual Machines (Linux) (https://azure.microsoft.com/documentation/articles/virtual-machines-linux-sizes/) or Sizes for Virtual Machines (Windows) (https://azure.microsoft.com/documentation/articles/virtual-machines-windows-sizes/). Batch supports all Azure VM sizes except STANDARD_A0 and those with premium storage (STANDARD_GS, STANDARD_DS, and STANDARD_DSV2 series).

  • type required - string

Frequently asked questions

What is Azure Batch Job?

Azure Batch Job is a resource for Batch of Microsoft Azure. Settings can be wrote in Terraform.