diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 35bcae9cbaa9..da4dcde03d19 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -145,6 +145,38 @@ func resourceArmContainerGroup() *schema.Resource { ForceNew: true, }, + "gpu": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "count": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validate.IntInSlice([]int{ + 1, + 2, + 4, + }), + }, + + "sku": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "K80", + "P100", + "V100", + }, false), + }, + }, + }, + }, + "port": { Type: schema.TypeInt, Optional: true, @@ -529,6 +561,21 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc }, } + if v, ok := data["gpu"]; ok { + gpus := v.([]interface{}) + for _, gpuRaw := range gpus { + v := gpuRaw.(map[string]interface{}) + gpuCount := int32(v["count"].(int)) + gpuSku := containerinstance.GpuSku(v["sku"].(string)) + + gpus := containerinstance.GpuResource{ + Count: &gpuCount, + Sku: gpuSku, + } + container.Resources.Requests.Gpu = &gpus + } + } + if v, ok := data["ports"].(*schema.Set); ok && len(v.List()) > 0 { var ports []containerinstance.ContainerPort for _, v := range v.List() { @@ -779,6 +826,17 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta if v := resourceRequests.MemoryInGB; v != nil { containerConfig["memory"] = *v } + + gpus := make([]interface{}, 0) + if v := resourceRequests.Gpu; v != nil { + gpu := make(map[string]interface{}) + if v.Count != nil { + gpu["count"] = *v.Count + } + gpu["sku"] = string(v.Sku) + gpus = append(gpus, gpu) + } + containerConfig["gpu"] = gpus } } diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 66e76c35d454..3e189e649e60 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -211,6 +211,9 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.%", "2"), resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo", "secureBar"), resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo1", "secureBar1"), + resource.TestCheckResourceAttr(resourceName, "container.0.gpu.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.gpu.0.count", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.gpu.0.sku", "K80"), resource.TestCheckResourceAttr(resourceName, "container.0.volume.#", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.mount_path", "/aci/logs"), resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.name", "logs"), @@ -592,7 +595,7 @@ resource "azurerm_container_group" "test" { ports { port = 80 protocol = "TCP" - } + } environment_variables = { "foo" = "bar" @@ -689,6 +692,11 @@ resource "azurerm_container_group" "test" { protocol = "TCP" } + gpu = { + count = 1 + sku = "K80" + } + volume { name = "logs" mount_path = "/aci/logs" diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index e8dbeba9fc67..47af628745d9 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -55,7 +55,7 @@ resource "azurerm_container_group" "aci-helloworld" { } ports { port = 443 - protocol = "TCP" + protocol = "TCP" } environment_variables = { @@ -134,6 +134,10 @@ A `container` block supports: * `memory` - (Required) The required memory of the containers in GB. Changing this forces a new resource to be created. +* `gpu` - (Optional) A `gpu` block as defined below. + +~> **Note:** Gpu resources are currently only supported in Linux containers. + * `ports` - (Optional) A set of public ports for the container. Changing this forces a new resource to be created. Set as documented in the `ports` block below. * `environment_variables` - (Optional) A list of environment variables to be set on the container. Specified as a map of name/value pairs. Changing this forces a new resource to be created. @@ -184,6 +188,14 @@ A `ports` block supports: * `protocol` - (Required) The network protocol associated with port. Possible values are `TCP` & `UDP`. +-- + +A `gpu` block supports: + +* `count` - (Required) The number of GPUs which should be assigned to this container. Allowed values are `1`, `2`, or `4`. + +* `sku` - (Required) The Sku which should be used for the GPU. Possible values are `K80`, `P100`, or `V100`. + --- A `volume` block supports: