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 4 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
58 changes: 58 additions & 0 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
ValidateFunc: validate.IntInSlice([]int{
1,
2,
4,
}),
},

"sku": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved
ValidateFunc: validation.StringInSlice([]string{
"K80",
"P100",
"V100",
}, false),
},
},
},
},

"port": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
}

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.

* `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.
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:

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