diff --git a/builtin/providers/docker/resource_docker_image.go b/builtin/providers/docker/resource_docker_image.go index 9c2f84d48932..eb84a2570553 100644 --- a/builtin/providers/docker/resource_docker_image.go +++ b/builtin/providers/docker/resource_docker_image.go @@ -28,9 +28,19 @@ func resourceDockerImage() *schema.Resource { }, "pull_trigger": &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"pull_triggers"}, + Deprecated: "Use field pull_triggers instead", + }, + + "pull_triggers": &schema.Schema{ + Type: schema.TypeSet, Optional: true, ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, }, }, } diff --git a/builtin/providers/docker/resource_docker_image_funcs.go b/builtin/providers/docker/resource_docker_image_funcs.go index 72cbc8ea2e2d..9c27b42597f5 100644 --- a/builtin/providers/docker/resource_docker_image_funcs.go +++ b/builtin/providers/docker/resource_docker_image_funcs.go @@ -188,15 +188,11 @@ func findImage(d *schema.ResourceData, client *dc.Client) (*dc.APIImages, error) return nil, fmt.Errorf("Empty image name is not allowed") } - foundImage := searchLocalImages(data, imageName) - - if foundImage == nil { - if err := pullImage(&data, client, imageName); err != nil { - return nil, fmt.Errorf("Unable to pull image %s: %s", imageName, err) - } + if err := pullImage(&data, client, imageName); err != nil { + return nil, fmt.Errorf("Unable to pull image %s: %s", imageName, err) } - foundImage = searchLocalImages(data, imageName) + foundImage := searchLocalImages(data, imageName) if foundImage != nil { return foundImage, nil } diff --git a/builtin/providers/docker/resource_docker_image_test.go b/builtin/providers/docker/resource_docker_image_test.go index 484c45e83ce0..750b39a1104a 100644 --- a/builtin/providers/docker/resource_docker_image_test.go +++ b/builtin/providers/docker/resource_docker_image_test.go @@ -89,6 +89,22 @@ func TestAccDockerImage_data(t *testing.T) { }) } +func TestAccDockerImage_data_pull_trigger(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + PreventPostDestroyRefresh: true, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDockerImageFromDataConfigWithPullTrigger, + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr("docker_image.foobarbazoo", "latest", contentDigestRegexp), + ), + }, + }, + }) +} + func testAccDockerImageDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "docker_image" { @@ -129,6 +145,16 @@ const testAccDockerImageFromDataConfig = ` data "docker_registry_image" "foobarbaz" { name = "alpine:3.1" } +resource "docker_image" "foobarbaz" { + name = "${data.docker_registry_image.foobarbaz.name}" + pull_triggers = ["${data.docker_registry_image.foobarbaz.sha256_digest}"] +} +` + +const testAccDockerImageFromDataConfigWithPullTrigger = ` +data "docker_registry_image" "foobarbaz" { + name = "alpine:3.1" +} resource "docker_image" "foobarbaz" { name = "${data.docker_registry_image.foobarbaz.name}" pull_trigger = "${data.docker_registry_image.foobarbaz.sha256_digest}" diff --git a/website/source/docs/providers/docker/d/registry_image.html.markdown b/website/source/docs/providers/docker/d/registry_image.html.markdown index 6f8213677200..ca364f4b8b2d 100644 --- a/website/source/docs/providers/docker/d/registry_image.html.markdown +++ b/website/source/docs/providers/docker/d/registry_image.html.markdown @@ -23,7 +23,7 @@ data "docker_registry_image" "ubuntu" { resource "docker_image" "ubuntu" { name = "${data.docker_registry_image.ubuntu.name}" - pull_trigger = "${data.docker_registry_image.ubuntu.sha256_digest}" + pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"] } ``` diff --git a/website/source/docs/providers/docker/r/image.html.markdown b/website/source/docs/providers/docker/r/image.html.markdown index a2005300a259..5dff59fbc75c 100644 --- a/website/source/docs/providers/docker/r/image.html.markdown +++ b/website/source/docs/providers/docker/r/image.html.markdown @@ -14,7 +14,7 @@ Pulls a Docker image to a given Docker host from a Docker Registry. This resource will *not* pull new layers of the image automatically unless used in conjunction with [`docker_registry_image`](/docs/providers/docker/d/registry_image.html) -data source to update the `pull_trigger` field. +data source to update the `pull_triggers` field. ## Example Usage @@ -36,7 +36,7 @@ data "docker_registry_image" "ubuntu" { resource "docker_image" "ubuntu" { name = "${data.docker_registry_image.ubuntu.name}" - pull_trigger = "${data.docker_registry_image.ubuntu.sha256_digest}" + pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"] } ``` @@ -48,10 +48,12 @@ The following arguments are supported: * `keep_locally` - (Optional, boolean) If true, then the Docker image won't be deleted on destroy operation. If this is false, it will delete the image from the docker local storage on destroy operation. -* `pull_trigger` - (Optional, string) Used to store the image digest from the - registry and will cause an image pull when changed. Needed when using - the `docker_registry_image` [data source](/docs/providers/docker/d/registry_image.html) - to trigger an update of the image. +* `pull_triggers` - (Optional, list of strings) List of values which cause an + image pull when changed. This is used to store the image digest from the + registry when using the `docker_registry_image` [data source](/docs/providers/docker/d/registry_image.html) + to trigger an image update. +* `pull_trigger` - **Deprecated**, use `pull_triggers` instead. + ## Attributes Reference