mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-02-17 09:38:33 -05:00
feat: Implement triggers attribute for docker_image. (#425)
* feat: Implement triggers attribute for docker_image. * fix: Update repo_digest value in test.
This commit is contained in:
parent
6db80ccbb0
commit
59fcfcc269
5 changed files with 35 additions and 1 deletions
|
|
@ -62,6 +62,20 @@ resource "docker_image" "zoo" {
|
|||
}
|
||||
```
|
||||
|
||||
You can use the `triggers` argument to specify when the image should be rebuild. This is for example helpful when you want to rebuild the docker image whenever the source code changes.
|
||||
|
||||
```terraform
|
||||
resource "docker_image" "zoo" {
|
||||
name = "zoo"
|
||||
build {
|
||||
path = "."
|
||||
}
|
||||
triggers = {
|
||||
dir_sha1 = sha1(join("", [for f in fileset(path.module, "src/*") : filesha1(f)]))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<!-- schema generated by tfplugindocs -->
|
||||
## Schema
|
||||
|
||||
|
|
@ -76,6 +90,7 @@ resource "docker_image" "zoo" {
|
|||
- `keep_locally` (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` (String, Deprecated) A value which cause an image pull when changed
|
||||
- `pull_triggers` (Set of String) 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-sources/registry_image.md).
|
||||
- `triggers` (Map of String) A map of arbitrary strings that, when changed, will force the `docker_image` resource to be replaced. This can be used to rebuild an image when contents of source code folders change
|
||||
|
||||
### Read-Only
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
resource "docker_image" "zoo" {
|
||||
name = "zoo"
|
||||
build {
|
||||
path = "."
|
||||
}
|
||||
triggers = {
|
||||
dir_sha1 = sha1(join("", [for f in fileset(path.module, "src/*") : filesha1(f)]))
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ func TestAccDockerImageDataSource_withSpecificTag(t *testing.T) {
|
|||
Config: loadTestConfiguration(t, DATA_SOURCE, "docker_image", "testAccDockerImageDataSourceWithSpecificTag"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.docker_image.foo", "name", imageName),
|
||||
resource.TestCheckResourceAttr("data.docker_image.foo", "repo_digest", "busybox@sha256:a3170d3672568b2c6626710db3573f3d92ee31eed933c24f3d7ea978178e21b8"),
|
||||
resource.TestCheckResourceAttr("data.docker_image.foo", "repo_digest", "busybox@sha256:09439c073bd3eb029a91c72eff2c0d9f12ab9c84f66bdef360fcf3f91a81bf7c"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -144,6 +144,12 @@ func resourceDockerImage() *schema.Resource {
|
|||
},
|
||||
},
|
||||
},
|
||||
"triggers": {
|
||||
Description: "A map of arbitrary strings that, when changed, will force the `docker_image` resource to be replaced. This can be used to rebuild an image when contents of source code folders change",
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,8 @@ In this case the image "zoo" and "zoo:develop" are built.
|
|||
|
||||
{{tffile "examples/resources/docker_image/resource-build.tf"}}
|
||||
|
||||
You can use the `triggers` argument to specify when the image should be rebuild. This is for example helpful when you want to rebuild the docker image whenever the source code changes.
|
||||
|
||||
{{tffile "examples/resources/docker_image/resource-build-triggers.tf"}}
|
||||
|
||||
{{ .SchemaMarkdown | trimspace }}
|
||||
|
|
|
|||
Loading…
Reference in a new issue