mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
provider/docker: Add support for a list of pull_triggers within the docker_image resource. (#10845)
This commit is contained in:
parent
c7f6b37826
commit
78e7d20bcb
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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" {
|
||||
@ -131,6 +147,16 @@ 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}"]
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerImageFromDataConfigWithPullTrigger = `
|
||||
data "docker_registry_image" "foobarbazoo" {
|
||||
name = "alpine:3.1"
|
||||
}
|
||||
resource "docker_image" "foobarbazoo" {
|
||||
name = "${data.docker_registry_image.foobarbazoo.name}"
|
||||
pull_trigger = "${data.docker_registry_image.foobarbazoo.sha256_digest}"
|
||||
}
|
||||
`
|
||||
|
@ -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}"]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user