entrypoint support for docker_container resource
This commit is contained in:
parent
9e9d4b2c72
commit
0ded14f160
|
@ -71,6 +71,13 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
|
||||
"entrypoint": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
|
||||
"dns": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
|
|
|
@ -54,6 +54,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
createOpts.Config.Cmd = stringListToStringSlice(v.([]interface{}))
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("entrypoint"); ok {
|
||||
createOpts.Config.Entrypoint = stringListToStringSlice(v.([]interface{}))
|
||||
}
|
||||
|
||||
exposedPorts := map[dc.Port]struct{}{}
|
||||
portBindings := map[dc.Port][]dc.PortBinding{}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestAccDockerContainer_basic(t *testing.T) {
|
||||
var c dc.Container
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
|
@ -17,14 +18,42 @@ func TestAccDockerContainer_basic(t *testing.T) {
|
|||
resource.TestStep{
|
||||
Config: testAccDockerContainerConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccContainerRunning("docker_container.foo"),
|
||||
testAccContainerRunning("docker_container.foo", &c),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccContainerRunning(n string) resource.TestCheckFunc {
|
||||
func TestAccDockerContainer_entrypoint(t *testing.T) {
|
||||
var c dc.Container
|
||||
|
||||
testCheck := func(*terraform.State) error {
|
||||
if len(c.Config.Entrypoint) < 3 ||
|
||||
(c.Config.Entrypoint[0] != "/bin/bash" &&
|
||||
c.Config.Entrypoint[1] != "-c" &&
|
||||
c.Config.Entrypoint[2] != "ping localhost") {
|
||||
return fmt.Errorf("Container wrong entrypoint: %s", c.Config.Entrypoint)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccDockerContainerEntrypointConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccContainerRunning("docker_container.foo", &c),
|
||||
testCheck,
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccContainerRunning(n string, container *dc.Container) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
|
@ -43,6 +72,11 @@ func testAccContainerRunning(n string) resource.TestCheckFunc {
|
|||
|
||||
for _, c := range containers {
|
||||
if c.ID == rs.Primary.ID {
|
||||
inspected, err := client.InspectContainer(c.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Container could not be inspected: %s", err)
|
||||
}
|
||||
*container = *inspected
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -61,3 +95,14 @@ resource "docker_container" "foo" {
|
|||
image = "${docker_image.foo.latest}"
|
||||
}
|
||||
`
|
||||
const testAccDockerContainerEntrypointConfig = `
|
||||
resource "docker_image" "foo" {
|
||||
name = "nginx:latest"
|
||||
}
|
||||
|
||||
resource "docker_container" "foo" {
|
||||
name = "tf-test"
|
||||
image = "${docker_image.foo.latest}"
|
||||
entrypoint = ["/bin/bash", "-c", "ping localhost"]
|
||||
}
|
||||
`
|
||||
|
|
|
@ -37,6 +37,11 @@ The following arguments are supported:
|
|||
* `command` - (Optional, list of strings) The command to use to start the
|
||||
container. For example, to run `/usr/bin/myprogram -f baz.conf` set the
|
||||
command to be `["/usr/bin/myprogram", "-f", "baz.conf"]`.
|
||||
* `entrypoint` - (Optional, list of strings) The command to use as the
|
||||
Entrypoint for the container. The Entrypoint allows you to configure a
|
||||
container to run as an executable. For example, to run `/usr/bin/myprogram`
|
||||
when starting a container, set the entrypoint to be
|
||||
`["/usr/bin/myprogram"]`.
|
||||
* `dns` - (Optional, set of strings) Set of DNS servers.
|
||||
* `env` - (Optional, set of strings) Environmental variables to set.
|
||||
* `links` - (Optional, set of strings) Set of links for link based
|
||||
|
|
Loading…
Reference in New Issue