diff --git a/docs/resources/image.md b/docs/resources/image.md index 92791816..3c559b30 100644 --- a/docs/resources/image.md +++ b/docs/resources/image.md @@ -94,7 +94,8 @@ resource "docker_image" "zoo" { ### Read-Only -- `id` (String) The ID of this resource. +- `id` (String) Unique identifier for this resource. This is not the image ID, but the ID of the resource in the Terraform state. This is used to identify the resource in the Terraform state. To reference the correct image ID, use the `image_id` attribute. +- `image_id` (String) The ID of the image (as seen when executing `docker inspect` on the image). Can be used to reference the image via its ID in other resources. - `latest` (String, Deprecated) The ID of the image in the form of `sha256:` image digest. Do not confuse it with the default `latest` tag. - `output` (String, Deprecated) - `repo_digest` (String) The image sha256 digest in the form of `repo[:tag]@sha256:`. diff --git a/internal/provider/resource_docker_image.go b/internal/provider/resource_docker_image.go index 0e229231..02478b5f 100644 --- a/internal/provider/resource_docker_image.go +++ b/internal/provider/resource_docker_image.go @@ -14,6 +14,11 @@ func resourceDockerImage() *schema.Resource { DeleteContext: resourceDockerImageDelete, Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + Description: "Unique identifier for this resource. This is not the image ID, but the ID of the resource in the Terraform state. This is used to identify the resource in the Terraform state. To reference the correct image ID, use the `image_id` attribute.", + }, "name": { Type: schema.TypeString, Description: "The name of the Docker image, including any tags or SHA256 repo digests.", @@ -28,6 +33,12 @@ func resourceDockerImage() *schema.Resource { Deprecated: "Use repo_digest instead", }, + "image_id": { + Type: schema.TypeString, + Description: "The ID of the image (as seen when executing `docker inspect` on the image). Can be used to reference the image via its ID in other resources.", + Computed: true, + }, + "repo_digest": { Type: schema.TypeString, Description: "The image sha256 digest in the form of `repo[:tag]@sha256:`.", diff --git a/internal/provider/resource_docker_image_funcs.go b/internal/provider/resource_docker_image_funcs.go index 48c7f729..cccd39f0 100644 --- a/internal/provider/resource_docker_image_funcs.go +++ b/internal/provider/resource_docker_image_funcs.go @@ -78,6 +78,7 @@ func resourceDockerImageRead(ctx context.Context, d *schema.ResourceData, meta i // TODO mavogel: remove the appended name from the ID d.SetId(foundImage.ID + d.Get("name").(string)) + d.Set("image_id", foundImage.ID) d.Set("latest", foundImage.ID) d.Set("repo_digest", repoDigest) return nil