Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPU support for Linux Azure Container Instances #3053

Merged
merged 6 commits into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ func resourceArmContainerGroup() *schema.Resource {
ForceNew: true,
},

"gpu": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"gpu_count": {
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
},

"gpu_sku": {
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
ForceNew: true,
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
},

"port": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -529,6 +551,20 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc
},
}

if v, ok := data["gpu"]; ok {
gpu := v.([]interface{})
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
for _, v := range gpu {
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
gpuCount := v.(map[string]interface{})["gpu_count"]
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
gpuSku := v.(map[string]interface{})["gpu_sku"]
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

gpus := containerinstance.GpuResource{
Count: utils.Int32(int32(gpuCount.(int))),
Sku: containerinstance.GpuSku(gpuSku.(string)),
}
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() {
Expand Down Expand Up @@ -779,6 +815,16 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta
if v := resourceRequests.MemoryInGB; v != nil {
containerConfig["memory"] = *v
}
if v := resourceRequests.Gpu; v != nil {
gpus := make([]interface{}, 0)
gpu := make(map[string]interface{})

gpu["gpu_count"] = *v.Count
gpu["gpu_sku"] = v.Sku
gpus = append(gpus, gpu)

containerConfig["gpu"] = gpus
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.gpu_count", "1"),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
resource.TestCheckResourceAttr(resourceName, "container.0.gpu.0.gpu_sku", "K80"),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
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"),
Expand Down Expand Up @@ -592,7 +595,7 @@ resource "azurerm_container_group" "test" {
ports {
port = 80
protocol = "TCP"
}
}

environment_variables = {
"foo" = "bar"
Expand Down Expand Up @@ -687,7 +690,12 @@ resource "azurerm_container_group" "test" {
ports {
port = 80
protocol = "TCP"
}
}

gpu = {
gpu_count = 1
gpu_sku = "K80"
}

volume {
name = "logs"
Expand Down
14 changes: 13 additions & 1 deletion website/docs/r/container_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ resource "azurerm_container_group" "aci-helloworld" {
}
ports {
port = 443
protocol = "TCP"
protocol = "TCP"
}

environment_variables = {
Expand Down Expand Up @@ -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.

~> **Note:** Gpu resources are currently only supported in Linux containers.
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

* `gpu` - (Optional) Specify to deploy the container with a GPU resource.
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

* `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.
Expand Down Expand Up @@ -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:

* `gpu_count` - (Required) The number of GPUs. Allowed values are 1, 2, or 4.
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

* `gpu_sku` - (Required) The GPU SKU. Allowed values are K80, P100, or V100.
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

---

A `volume` block supports:
Expand Down