Skip to content

Commit

Permalink
provider/docker: Add support for a list of pull_triggers within the d…
Browse files Browse the repository at this point in the history
…ocker_image resource.
  • Loading branch information
hmcgonig committed Jan 3, 2017
1 parent adbf7c2 commit b5f4880
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
12 changes: 11 additions & 1 deletion builtin/providers/docker/resource_docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
10 changes: 3 additions & 7 deletions builtin/providers/docker/resource_docker_image_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/providers/docker/resource_docker_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ data "docker_registry_image" "foobarbaz" {
}
resource "docker_image" "foobarbaz" {
name = "${data.docker_registry_image.foobarbaz.name}"
pull_trigger = "${data.docker_registry_image.foobarbaz.sha256_digest}"
pull_triggers = ["${data.docker_registry_image.foobarbaz.sha256_digest}"]
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]
}
```

Expand Down
14 changes: 8 additions & 6 deletions website/source/docs/providers/docker/r/image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"]
}
```

Expand All @@ -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

Expand Down

0 comments on commit b5f4880

Please sign in to comment.