feat: Add sysctl implementation to container of docker_service. (#499)

This commit is contained in:
Martin 2022-12-23 15:29:17 +01:00 committed by GitHub
parent b30ba0c07c
commit 19191883d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -378,6 +378,7 @@ Optional:
- `secrets` (Block Set) References to zero or more secrets that will be exposed to the service (see [below for nested schema](#nestedblock--task_spec--container_spec--secrets))
- `stop_grace_period` (String) Amount of time to wait for the container to terminate before forcefully removing it (ms|s|m|h). If not specified or '0s' the destroy will not check if all tasks/containers of the service terminate.
- `stop_signal` (String) Signal to stop the container
- `sysctl` (Map of String) Sysctls config (Linux only)
- `user` (String) The user inside the container
<a id="nestedblock--task_spec--container_spec--configs"></a>

View file

@ -499,6 +499,12 @@ func resourceDockerService() *schema.Resource {
Optional: true,
ValidateDiagFunc: validateStringMatchesPattern(`^(default|process|hyperv)$`),
},
"sysctl": {
Type: schema.TypeMap,
Description: "Sysctls config (Linux only)",
Optional: true,
ForceNew: true,
},
},
},
},

View file

@ -174,6 +174,9 @@ func flattenContainerSpec(in *swarm.ContainerSpec) []interface{} {
if len(in.Isolation) > 0 {
m["isolation"] = string(in.Isolation)
}
if len(in.Sysctls) > 0 {
m["sysctl"] = in.Sysctls
}
out = append(out, m)
return out
}
@ -925,6 +928,9 @@ func createContainerSpec(v interface{}) (*swarm.ContainerSpec, error) {
if value, ok := rawContainerSpec["isolation"]; ok {
containerSpec.Isolation = container.Isolation(value.(string))
}
if value, ok := rawContainerSpec["sysctl"]; ok {
containerSpec.Sysctls = mapTypeMapValsToString(value.(map[string]interface{}))
}
}
}