mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-18 23:06:10 -05:00
feat: Allow digest in image name (#744)
This commit is contained in:
parent
55e1f3f7d8
commit
6b1330a447
5 changed files with 25 additions and 4 deletions
|
|
@ -28,7 +28,7 @@ resource "docker_image" "ubuntu" {
|
|||
|
||||
### Required
|
||||
|
||||
- `name` (String) The name of the Docker image, including any tags. e.g. `alpine:latest`
|
||||
- `name` (String) The name of the Docker image, including any tags. e.g. `alpine:latest`. You can also specify a digest, e.g. `nginx:1.28.0@sha256:eaa7e36decc3421fc04478c586dfea0d931cebe47d5bc0b15d758a32ba51126f`.
|
||||
|
||||
### Optional
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func dataSourceDockerRegistryImage() *schema.Resource {
|
|||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Description: "The name of the Docker image, including any tags. e.g. `alpine:latest`",
|
||||
Description: "The name of the Docker image, including any tags. e.g. `alpine:latest`. You can also specify a digest, e.g. `nginx:1.28.0@sha256:eaa7e36decc3421fc04478c586dfea0d931cebe47d5bc0b15d758a32ba51126f`.",
|
||||
Required: true,
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func TestAccDockerRegistryImage_basic(t *testing.T) {
|
|||
ProviderFactories: providerFactories,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: loadTestConfiguration(t, DATA_SOURCE, "docker_registry_image", "testAccDockerImageDataSourceConfig"),
|
||||
Config: fmt.Sprintf(loadTestConfiguration(t, DATA_SOURCE, "docker_registry_image", "testAccDockerImageDataSourceConfig"), "alpine:latest"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestMatchResourceAttr("data.docker_registry_image.foo", "sha256_digest", registryDigestRegexp),
|
||||
),
|
||||
|
|
@ -30,6 +30,21 @@ func TestAccDockerRegistryImage_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDockerRegistryImage_basicWithDigest(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
ProviderFactories: providerFactories,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: fmt.Sprintf(loadTestConfiguration(t, DATA_SOURCE, "docker_registry_image", "testAccDockerImageDataSourceConfig"), "nginx:1.28.0@sha256:eaa7e36decc3421fc04478c586dfea0d931cebe47d5bc0b15d758a32ba51126f"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.docker_registry_image.foo", "sha256_digest", "sha256:eaa7e36decc3421fc04478c586dfea0d931cebe47d5bc0b15d758a32ba51126f"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccDockerRegistryImage_private(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
|
|
|||
|
|
@ -288,6 +288,12 @@ func parseImageOptions(image string) internalPullImageOptions {
|
|||
// we have the tag, strip it
|
||||
pullOpts.Repository = image[:prefixLength+tagIndex]
|
||||
pullOpts.Tag = image[prefixLength+tagIndex+1:]
|
||||
digestIndex := strings.Index(pullOpts.Tag, "@")
|
||||
if digestIndex != -1 {
|
||||
log.Printf("[INFO] Found digest in tag: %s, we are using the digest for pulling the image from the registry", pullOpts.Tag)
|
||||
// prefer pinned digest over tag name
|
||||
pullOpts.Tag = pullOpts.Tag[digestIndex+1:]
|
||||
}
|
||||
}
|
||||
|
||||
if pullOpts.Tag == "" {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
data "docker_registry_image" "foo" {
|
||||
name = "alpine:latest"
|
||||
name = "%s"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue