Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to query ECR repository for most recently pushed image #12798

Closed
kvrhdn opened this issue Apr 13, 2020 · 3 comments · Fixed by #26857
Closed

Add ability to query ECR repository for most recently pushed image #12798

kvrhdn opened this issue Apr 13, 2020 · 3 comments · Fixed by #26857
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecr Issues and PRs that pertain to the ecr service.
Milestone

Comments

@kvrhdn
Copy link

kvrhdn commented Apr 13, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Use case: in my setup I often wish to deploy the most recently pushed ECR image to a test environment. But I found it isn't possible to query for this image directly using aws_ecr_image.

You can do fairly easy with the AWS cli:

$ aws ecr describe-images --repository-name <REPO> --query 'sort_by(imageDetails, &imagePushedAt)[-1]'

I would propose adding query functionality to aws_ecr_image, similar to aws_ami

data "aws_ecr_image" "most_recent" {
  repository_name = "my-repository"
  most_recent     = true
}

New or Affected Resource(s)

  • aws_ecr_image

Potential Terraform Configuration

Desired configuration:

data "aws_ecr_image" "most_recent" {
  repository_name = "my-repository"
  most_recent     = true
}

References

  • N/A
@kvrhdn kvrhdn added the enhancement Requests to existing resources that expand the functionality or scope. label Apr 13, 2020
@ghost ghost added the service/ecr Issues and PRs that pertain to the ecr service. label Apr 13, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 13, 2020
@kvrhdn
Copy link
Author

kvrhdn commented Apr 13, 2020

FWIW, I've been able to put a workaround together:

variable "repository_name" {
  description = "The ECR repository to query"
  type        = string
}

# Terraform's AWS provider does not provide a mechanism to query the ecr repository.
#
# We use an external data source, which can run any program that returns valid JSON, to run the AWS
# cli manually, which will produce a JSON in the following format:
#
#   {
#     "tags": "[\"1.0.0.1166\"]"
#   }
#
data "external" "tags_of_most_recently_pushed_image" {
  program = [
    "aws", "ecr", "describe-images",
    "--repository-name", var.repository_name,
    "--query", "{\"tags\": to_string(sort_by(imageDetails,& imagePushedAt)[-1].imageTags)}",
  ]
}

output "tags" {
  description = ""
  value       = jsondecode(data.external.tags_of_most_recently_pushed_image.result.tags)
}

@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 22, 2021
@ewbankkit ewbankkit self-assigned this Feb 22, 2023
@github-actions github-actions bot added this to the v4.56.0 milestone Feb 22, 2023
@github-actions
Copy link

This functionality has been released in v4.56.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ecr Issues and PRs that pertain to the ecr service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants