diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9f9efc..ebdef26d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ IMPROVEMENTS * Adds `rm` and `attach` options to execute short-lived containers [GH-43] and [[#106](https://github.com/terraform-providers/terraform-provider-docker/pull/106)] * Adds container healthcheck[[#93](https://github.com/terraform-providers/terraform-provider-docker/pull/93)] * Adds the docker container start flag [GH-62] and [[#94](https://github.com/terraform-providers/terraform-provider-docker/pull/94)] +* Adds `cpu_set` to docker container [[#41](https://github.com/terraform-providers/terraform-provider-docker/pull/41)] BUG FIXES * Fixes that new network were appended to the default bridge [GH-10] diff --git a/docker/resource_docker_container.go b/docker/resource_docker_container.go index 81e0ab39..f69ac100 100644 --- a/docker/resource_docker_container.go +++ b/docker/resource_docker_container.go @@ -426,6 +426,13 @@ func resourceDockerContainer() *schema.Resource { ValidateFunc: validateIntegerGeqThan(0), }, + "cpu_set": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validateStringMatchesPattern(`^\d+([,-]\d+)*$`), + }, + "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 36698f77..fbdb934f 100644 --- a/docker/resource_docker_container_funcs.go +++ b/docker/resource_docker_container_funcs.go @@ -210,6 +210,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err hostConfig.CPUShares = int64(v.(int)) } + if v, ok := d.GetOk("cpu_set"); ok { + hostConfig.CpusetCpus = v.(string) + } + if v, ok := d.GetOk("log_opts"); ok { hostConfig.LogConfig.Config = mapTypeMapValsToString(v.(map[string]interface{})) } diff --git a/docker/resource_docker_container_test.go b/docker/resource_docker_container_test.go index f0cd410d..c6021f39 100644 --- a/docker/resource_docker_container_test.go +++ b/docker/resource_docker_container_test.go @@ -212,6 +212,10 @@ func TestAccDockerContainer_customized(t *testing.T) { return fmt.Errorf("Container has wrong cpu shares setting: %d", c.HostConfig.CPUShares) } + if c.HostConfig.CpusetCpus != "0-1" { + return fmt.Errorf("Container has wrong cpu set setting: %s", c.HostConfig.CpusetCpus) + } + if len(c.HostConfig.DNS) != 1 { return fmt.Errorf("Container does not have the correct number of dns entries: %d", len(c.HostConfig.DNS)) } @@ -1048,6 +1052,7 @@ resource "docker_container" "foo" { memory = 512 memory_swap = 2048 cpu_shares = 32 + cpu_set = "0-1" capabilities { add= ["ALL"] diff --git a/website/docs/r/container.html.markdown b/website/docs/r/container.html.markdown index e9306a92..d5e8c730 100644 --- a/website/docs/r/container.html.markdown +++ b/website/docs/r/container.html.markdown @@ -84,6 +84,7 @@ data is stored in them. See [the docker documentation][linkdoc] for more details * `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. +* `cpu_set` - (Optional, string) A comma-separated list or hyphen-separated range of CPUs a container can use, e.g. `0-1`. * `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