azurerm_batch_pool

Manages an Azure Batch pool.

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "testaccbatch"
  location = "West Europe"
}

resource "azurerm_storage_account" "example" {
  name                     = "testaccsa"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_batch_account" "example" {
  name                                = "testaccbatch"
  resource_group_name                 = azurerm_resource_group.example.name
  location                            = azurerm_resource_group.example.location
  pool_allocation_mode                = "BatchService"
  storage_account_id                  = azurerm_storage_account.example.id
  storage_account_authentication_mode = "StorageKeys"

  tags = {
    env = "test"
  }
}

resource "azurerm_batch_certificate" "example" {
  resource_group_name  = azurerm_resource_group.example.name
  account_name         = azurerm_batch_account.example.name
  certificate          = filebase64("certificate.cer")
  format               = "Cer"
  thumbprint           = "312d31a79fa0cef49c00f769afc2b73e9f4edf34"
  thumbprint_algorithm = "SHA1"
}

resource "azurerm_batch_pool" "example" {
  name                = "testaccpool"
  resource_group_name = azurerm_resource_group.example.name
  account_name        = azurerm_batch_account.example.name
  display_name        = "Test Acc Pool Auto"
  vm_size             = "Standard_A1"
  node_agent_sku_id   = "batch.node.ubuntu 20.04"

  auto_scale {
    evaluation_interval = "PT15M"

    formula = <<EOF
      startingNumberOfVMs = 1;
      maxNumberofVMs = 25;
      pendingTaskSamplePercent = $PendingTasks.GetSamplePercent(180 * TimeInterval_Second);
      pendingTaskSamples = pendingTaskSamplePercent < 70 ? startingNumberOfVMs : avg($PendingTasks.GetSample(180 *   TimeInterval_Second));
      $TargetDedicatedNodes=min(maxNumberofVMs, pendingTaskSamples);
EOF

  }

  storage_image_reference {
    publisher = "microsoft-azure-batch"
    offer     = "ubuntu-server-container"
    sku       = "20-04-lts"
    version   = "latest"
  }

  container_configuration {
    type = "DockerCompatible"
    container_registries {
      registry_server = "docker.io"
      user_name       = "login"
      password        = "apassword"
    }
  }

  start_task {
    command_line       = "echo 'Hello World from $env'"
    task_retry_maximum = 1
    wait_for_success   = true

    common_environment_properties = {
      env = "TEST"
    }

    user_identity {
      auto_user {
        elevation_level = "NonAdmin"
        scope           = "Task"
      }
    }
  }

  certificate {
    id             = azurerm_batch_certificate.example.id
    store_location = "CurrentUser"
    visibility     = ["StartTask"]
  }
}

Argument Reference

The following arguments are supported:


An identity block supports the following:


A data_disks block supports the following:


A disk_encryption block supports the following:

The disk encryption configuration applied on compute nodes in the pool. Disk encryption configuration is not supported on Linux pool created with Virtual Machine Image or Shared Image Gallery Image.


An extensions block supports the following:

The virtual machine extension for the pool. If specified, the extensions mentioned in this configuration will be installed on each node.


A node_placement block supports the following:

Node placement Policy type on Batch Pools. Allocation policy used by Batch Service to provision the nodes. If not specified, Batch will use the regional policy.


A storage_image_reference block supports the following:

This block provisions virtual machines in the Batch Pool from one of two sources: an Azure Platform Image (e.g. Ubuntu/Windows Server) or a Custom Image.

To provision from an Azure Platform Image, the following fields are applicable:

To provision a Custom Image, the following fields are applicable:


A fixed_scale block supports the following:


A auto_scale block supports the following:


A start_task block supports the following:


A container block supports the following:


A user_identity block supports the following:


A auto_user block supports the following:


A certificate block supports the following:


A container_configuration block supports the following:


A resource_file block supports the following:


A container_registries block supports the following:


An mount block supports the following:

Any property below is mutually exclusive with all other properties.


An azure_blob_file_system block supports the following:


An azure_file_share block supports the following:


A cifs_mount block supports the following:


A nfs_mount block supports the following:


A network_configuration block supports the following:


A endpoint_configuration block supports the following:


A network_security_group_rules block supports the following:


A task_scheduling_policy block supports the following:


A user_accounts block supports the following:


A linux_user_configuration block supports the following:


A windows_user_configuration block supports the following:


A windows block supports the following:

Windows operating system settings on the virtual machine. This property must not be specified if the imageReference specifies a Linux OS image.


Attributes Reference

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

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

Batch Pools can be imported using the resource id, e.g.

terraform import azurerm_batch_pool.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myGroup1/providers/Microsoft.Batch/batchAccounts/myBatchAccount1/pools/myBatchPool1