feat: Add image_id attribute to docker_image resource. (#450)

This commit is contained in:
Martin 2022-09-05 13:55:41 +02:00 committed by GitHub
parent b37b866b6d
commit ad65027896
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -94,7 +94,8 @@ resource "docker_image" "zoo" {
### Read-Only ### 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:<hash>` image digest. Do not confuse it with the default `latest` tag. - `latest` (String, Deprecated) The ID of the image in the form of `sha256:<hash>` image digest. Do not confuse it with the default `latest` tag.
- `output` (String, Deprecated) - `output` (String, Deprecated)
- `repo_digest` (String) The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`. - `repo_digest` (String) The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`.

View file

@ -14,6 +14,11 @@ func resourceDockerImage() *schema.Resource {
DeleteContext: resourceDockerImageDelete, DeleteContext: resourceDockerImageDelete,
Schema: map[string]*schema.Schema{ 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": { "name": {
Type: schema.TypeString, Type: schema.TypeString,
Description: "The name of the Docker image, including any tags or SHA256 repo digests.", 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", 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": { "repo_digest": {
Type: schema.TypeString, Type: schema.TypeString,
Description: "The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`.", Description: "The image sha256 digest in the form of `repo[:tag]@sha256:<hash>`.",

View file

@ -78,6 +78,7 @@ func resourceDockerImageRead(ctx context.Context, d *schema.ResourceData, meta i
// TODO mavogel: remove the appended name from the ID // TODO mavogel: remove the appended name from the ID
d.SetId(foundImage.ID + d.Get("name").(string)) d.SetId(foundImage.ID + d.Get("name").(string))
d.Set("image_id", foundImage.ID)
d.Set("latest", foundImage.ID) d.Set("latest", foundImage.ID)
d.Set("repo_digest", repoDigest) d.Set("repo_digest", repoDigest)
return nil return nil