From 42031f27fb14ae8a57a6fc3fb66f2e8939b51e73 Mon Sep 17 00:00:00 2001 From: Manuel Vogel Date: Mon, 23 Sep 2019 19:41:20 +0200 Subject: [PATCH] feat: adds container working dir (#181) Closes #146 --- docker/resource_docker_container.go | 6 +++++- docker/resource_docker_container_funcs.go | 4 +++- docker/resource_docker_container_test.go | 4 ++++ website/docs/r/container.html.markdown | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docker/resource_docker_container.go b/docker/resource_docker_container.go index cb1433ea..4a73495f 100644 --- a/docker/resource_docker_container.go +++ b/docker/resource_docker_container.go @@ -163,7 +163,11 @@ func resourceDockerContainer() *schema.Resource { Optional: true, ForceNew: true, }, - + "working_dir": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "capabilities": { Type: schema.TypeSet, Optional: true, diff --git a/docker/resource_docker_container_funcs.go b/docker/resource_docker_container_funcs.go index 61b9423c..b914b216 100644 --- a/docker/resource_docker_container_funcs.go +++ b/docker/resource_docker_container_funcs.go @@ -76,7 +76,9 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err if len(exposedPorts) != 0 { config.ExposedPorts = exposedPorts } - + if v, ok := d.GetOk("working_dir"); ok { + config.WorkingDir = v.(string) + } extraHosts := []string{} if v, ok := d.GetOk("host"); ok { extraHosts = extraHostsSetToDockerExtraHosts(v.(*schema.Set)) diff --git a/docker/resource_docker_container_test.go b/docker/resource_docker_container_test.go index bf8c28df..cbade28a 100644 --- a/docker/resource_docker_container_test.go +++ b/docker/resource_docker_container_test.go @@ -451,6 +451,9 @@ func TestAccDockerContainer_customized(t *testing.T) { if c.HostConfig.UsernsMode != "testuser:231072:65536" { return fmt.Errorf("Container doesn't have a correct userns mode") } + if c.Config.WorkingDir != "/tmp" { + return fmt.Errorf("Container doesn't have a correct working dir") + } return nil } @@ -1432,6 +1435,7 @@ resource "docker_container" "foo" { pid_mode = "host" userns_mode = "testuser:231072:65536" + working_dir = "/tmp" } resource "docker_network" "test_network" { diff --git a/website/docs/r/container.html.markdown b/website/docs/r/container.html.markdown index 22695f5a..95a62abd 100644 --- a/website/docs/r/container.html.markdown +++ b/website/docs/r/container.html.markdown @@ -65,6 +65,7 @@ data is stored in them. See [the docker documentation][linkdoc] for more details one of "no", "on-failure", "always", "unless-stopped". * `max_retry_count` - (Optional, int) The maximum amount of times to an attempt a restart when `restart` is set to "on-failure" +* `working_dir`- (Optional, string) The working directory for commands to run in * `rm` - (Optional, bool) If true, then the container will be automatically removed after his execution. Terraform won't check this container after creation. * `start` - (Optional, bool) If true, then the Docker container will be