mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-30 03:29:39 -05:00
feat: adds support for init process injection for containers. (#300)
This commit is contained in:
parent
9c6ff18492
commit
cdc0b0a7e8
4 changed files with 73 additions and 0 deletions
|
|
@ -812,6 +812,11 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
Set: schema.HashString,
|
||||
},
|
||||
"init": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -322,6 +322,9 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
hostConfig.GroupAdd = stringSetToStringSlice(v.(*schema.Set))
|
||||
}
|
||||
|
||||
init := d.Get("init").(bool)
|
||||
hostConfig.Init = &init
|
||||
|
||||
var retContainer container.ContainerCreateCreatedBody
|
||||
|
||||
if retContainer, err = client.ContainerCreate(context.Background(), config, hostConfig, networkingConfig, d.Get("name").(string)); err != nil {
|
||||
|
|
@ -619,6 +622,15 @@ func resourceDockerContainerRead(d *schema.ResourceData, meta interface{}) error
|
|||
d.Set("publish_all_ports", container.HostConfig.PublishAllPorts)
|
||||
d.Set("restart", container.HostConfig.RestartPolicy.Name)
|
||||
d.Set("max_retry_count", container.HostConfig.RestartPolicy.MaximumRetryCount)
|
||||
// From what I can tell Init being nullable is only for container creation to allow
|
||||
// dockerd to default it to the daemons own default settings. So this != nil
|
||||
// check is most likely not ever going to fail. In the event that it does the
|
||||
// "init" value will be set to false as there isn't much else we can do about it.
|
||||
if container.HostConfig.Init != nil {
|
||||
d.Set("init", *container.HostConfig.Init)
|
||||
} else {
|
||||
d.Set("init", false)
|
||||
}
|
||||
d.Set("working_dir", container.Config.WorkingDir)
|
||||
if len(container.HostConfig.CapAdd) > 0 || len(container.HostConfig.CapDrop) > 0 {
|
||||
// TODO implement DiffSuppressFunc
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ func TestAccDockerContainer_basic(t *testing.T) {
|
|||
"destroy_grace_seconds",
|
||||
"upload",
|
||||
"remove_volumes",
|
||||
"init",
|
||||
|
||||
// TODO mavogel: Will be done in #219
|
||||
"volumes",
|
||||
|
|
@ -100,6 +101,48 @@ func TestAccDockerContainer_basic(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccDockerContainer_init(t *testing.T) {
|
||||
resourceName := "docker_container.fooinit"
|
||||
var c types.ContainerJSON
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccDockerContainerInitConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccContainerRunning(resourceName, &c),
|
||||
),
|
||||
},
|
||||
{
|
||||
ResourceName: "docker_container.fooinit",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
ImportStateVerifyIgnore: []string{
|
||||
"attach",
|
||||
"log_driver",
|
||||
"logs",
|
||||
"must_run",
|
||||
"restart",
|
||||
"rm",
|
||||
"start",
|
||||
"container_logs",
|
||||
"destroy_grace_seconds",
|
||||
"upload",
|
||||
"remove_volumes",
|
||||
|
||||
// TODO mavogel: Will be done in #219
|
||||
"volumes",
|
||||
"network_alias",
|
||||
"networks",
|
||||
"network_advanced",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccDockerContainer_basic_network(t *testing.T) {
|
||||
var c types.ContainerJSON
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
|
@ -1697,6 +1740,18 @@ resource "docker_container" "foo" {
|
|||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerInitConfig = `
|
||||
resource "docker_image" "fooinit" {
|
||||
name = "nginx:latest"
|
||||
}
|
||||
|
||||
resource "docker_container" "fooinit" {
|
||||
name = "tf-test"
|
||||
image = "${docker_image.fooinit.latest}"
|
||||
init = true
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerContainerUpdateConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "nginx:latest"
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ data is stored in them. See [the docker documentation](https://docs.docker.com/n
|
|||
* `sysctls` - (Optional, map) A map of kernel parameters (sysctls) to set in the container.
|
||||
* `ipc_mode` - (Optional, string) IPC sharing mode for the container. Possible values are: `none`, `private`, `shareable`, `container:<name|id>` or `host`.
|
||||
* `group_add` - (Optional, set of strings) Add additional groups to run as.
|
||||
* `init` - (Optional, bool) Configured whether an init process should be injected for this container. If unset this will default to the `dockerd` defaults.
|
||||
|
||||
<a id="labels-1"></a>
|
||||
#### Labels
|
||||
|
|
|
|||
Loading…
Reference in a new issue