From cd0b52d19fe56a70554d9cd694a4ea74d162b186 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 24 Jan 2018 23:03:01 +0200 Subject: [PATCH] cpuset added --- docker/resource_docker_container.go | 15 +++++++++++++++ docker/resource_docker_container_funcs.go | 4 ++++ website/docs/r/container.html.markdown | 1 + 3 files changed, 20 insertions(+) diff --git a/docker/resource_docker_container.go b/docker/resource_docker_container.go index aa47c951..561aba5f 100644 --- a/docker/resource_docker_container.go +++ b/docker/resource_docker_container.go @@ -355,6 +355,21 @@ func resourceDockerContainer() *schema.Resource { }, }, + "cpuset": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + + ValidateFunc: func(v interface{}, k string) (ws []string, es []error) { + value := v.(string) + if !regexp.MustCompile(`^\d+([,-]\d+)*$`).MatchString(value) { + es = append(es, fmt.Errorf("%q must be comma or hyphen separated string of cpus to use", k)) + } + return + }, + + }, + "log_driver": &schema.Schema{ Type: schema.TypeString, Optional: true, diff --git a/docker/resource_docker_container_funcs.go b/docker/resource_docker_container_funcs.go index 4c9aaf49..b6aa8dd6 100644 --- a/docker/resource_docker_container_funcs.go +++ b/docker/resource_docker_container_funcs.go @@ -167,6 +167,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err hostConfig.CPUShares = int64(v.(int)) } + if v, ok := d.GetOk("cpuset"); ok { + hostConfig.CPUSetCPUs = v.(string) + } + if v, ok := d.GetOk("log_opts"); ok { hostConfig.LogConfig.Config = mapTypeMapValsToString(v.(map[string]interface{})) } diff --git a/website/docs/r/container.html.markdown b/website/docs/r/container.html.markdown index a267cb24..dca753bd 100644 --- a/website/docs/r/container.html.markdown +++ b/website/docs/r/container.html.markdown @@ -73,6 +73,7 @@ The following arguments are supported: * `memory_swap` - (Optional, int) The total memory limit (memory + swap) for the container in MBs. This setting may compute to `-1` after `terraform apply` if the target host doesn't support memory swap, when that is the case docker will use a soft limitation. * `cpu_shares` - (Optional, int) CPU shares (relative weight) for the container. +* `cpuset` - (Optional, string) A comma-separated list or hyphen-separated range of CPUs a container can use. * `log_driver` - (Optional, string) The logging driver to use for the container. Defaults to "json-file". * `log_opts` - (Optional, map of strings) Key/value pairs to use as options for