From 6913754191e080a98741c176ad6004c07ee2c892 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Fri, 29 Apr 2016 18:42:24 -0500 Subject: [PATCH] provider/docker: don't crash with empty commands If any of the entries in `commands` on `docker_container` resources was empty, the assertion to string panic'd. Since we can't use ValidateFunc on list elements, we can only really check this at apply time. If any value is nil (resolves to empty string during conversion), we fail with an error prior to creating the container. Fixes #6409. --- .../providers/docker/resource_docker_container_funcs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/providers/docker/resource_docker_container_funcs.go b/builtin/providers/docker/resource_docker_container_funcs.go index 00090294c..b475884b6 100644 --- a/builtin/providers/docker/resource_docker_container_funcs.go +++ b/builtin/providers/docker/resource_docker_container_funcs.go @@ -51,6 +51,11 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err if v, ok := d.GetOk("command"); ok { createOpts.Config.Cmd = stringListToStringSlice(v.([]interface{})) + for _, v := range createOpts.Config.Cmd { + if v == "" { + return fmt.Errorf("values for command may not be empty") + } + } } if v, ok := d.GetOk("entrypoint"); ok { @@ -269,6 +274,10 @@ func resourceDockerContainerDelete(d *schema.ResourceData, meta interface{}) err func stringListToStringSlice(stringList []interface{}) []string { ret := []string{} for _, v := range stringList { + if v == nil { + ret = append(ret, "") + continue + } ret = append(ret, v.(string)) } return ret