feat: support max replicas of Docker Service Task Spec (#112)

Closes #111
This commit is contained in:
Shunsuke Suzuki 2021-01-03 20:37:31 +09:00 committed by GitHub
parent 0042d2654a
commit 2101f471c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 0 deletions

View file

@ -651,6 +651,12 @@ func resourceDockerService() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"max_replicas": {
Type: schema.TypeInt,
Description: "Maximum number of replicas for per node (default value is 0, which is unlimited)",
Optional: true,
ValidateFunc: validateIntegerGeqThan(0),
},
"platforms": {
Type: schema.TypeSet,
Description: "Platforms stores all the platforms that the service's image can run on",

View file

@ -1102,6 +1102,9 @@ func createPlacement(v interface{}) (*swarm.Placement, error) {
if v, ok := rawPlacement["platforms"]; ok {
placement.Platforms = mapSetToPlacementPlatforms(v.(*schema.Set))
}
if v, ok := rawPlacement["max_replicas"]; ok {
placement.MaxReplicas = uint64(v.(int))
}
}
}
}

View file

@ -344,6 +344,7 @@ func TestAccDockerService_fullSpec(t *testing.T) {
os = "linux"
}
max_replicas = 2
}
force_update = 0
@ -451,6 +452,7 @@ func TestAccDockerService_fullSpec(t *testing.T) {
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.restart_policy.window", "10s"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.placement.0.constraints.4248571116", "node.role==manager"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.placement.0.prefs.1751004438", "spread=node.role.manager"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.placement.0.max_replicas", "2"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.force_update", "0"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.networks.#", "1"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.name", "json-file"),

View file

@ -444,6 +444,7 @@ func flattenTaskPlacement(in *swarm.Placement) []interface{} {
if len(in.Platforms) > 0 {
m["platforms"] = flattenPlacementPlatforms(in.Platforms)
}
m["max_replicas"] = in.MaxReplicas
out[0] = m
return out
}

View file

@ -215,6 +215,8 @@ resource "docker_service" "foo" {
prefs = [
"spread=node.role.manager",
]
max_replicas = 1
}
force_update = 0
@ -486,6 +488,7 @@ the extra mount mappings for the container. Each `configs` is a reference to a s
* `platforms` (Optional, set of) Platforms stores all the platforms that the service's image can run on
* `architecture` (Required, string) The architecture, e.g., `amd64`
* `os` (Required, string) The operation system, e.g., `linux`
* `max_replicas` (Optional, int) Maximum number of replicas for per node (default value is 0, which is unlimited)
<!-- end task-placement-spec -->
<!-- end log-driver-spec -->