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

aws_ecr_repository: add newest_image_tag for improving experience with tag immutability #26658

Closed
francardoso93 opened this issue Sep 5, 2022 · 4 comments · Fixed by #26857
Closed
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@francardoso93
Copy link

francardoso93 commented Sep 5, 2022

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

data.aws_ecr_repository.service could have the tag of the newest pushed image as an attribute. That would grant a dynamic experience when working with immutable tags.

See this example that works fine when dealing with mutable tags:

resource "aws_lambda_function" "lambda_function" {
  package_type  = "Image"
  image_uri  = "${data.aws_ecr_repository.service.repository_url}:${var.image_version}"
  ...
}

Now, if I can't set image_version to latest, how to make sure terraform apply will keep up to date with newest image? To keep updating the image_version value manually seems like unnecessary work and poor experience.

Tag immutability should be used in production for hardening security, a better experience in doing so could drive that change in many systems.

New or Affected Resource(s)

aws_ecr_repository

Potential Terraform Configuration

resource "aws_lambda_function" "lambda_function" {
  package_type  = "Image"
  image_uri        = "${data.aws_ecr_repository.service.repository_url}:${data.aws_ecr_repository.service.newest_image_tag}"
  ...
}

or even better:

resource "aws_lambda_function" "lambda_function" {
  package_type  = "Image"
  image_uri        = "${data.aws_ecr_repository.service.newest_image_uri}"
  ...
}

References

https://sysdig.com/blog/toctou-tag-mutability/
https://aquasecurity.github.io/tfsec/v1.15.0/checks/aws/ecr/enforce-immutable-repository/

@francardoso93 francardoso93 added the enhancement Requests to existing resources that expand the functionality or scope. label Sep 5, 2022
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/lambda Issues and PRs that pertain to the lambda service. labels Sep 5, 2022
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Sep 6, 2022
@anitakrueger
Copy link

anitakrueger commented Oct 18, 2022

We are running into exactly this issue with a Fargate task definition. The definition is in terraform and originally creates the resource with the latest image tag. A github workflow then updates the task definition when a new image gets deployed. The workflow does move the latest tag as well, but it also creates a specific version on release, which is what I want to set my image in the task definition to. Now running terraform again, overwrites that and I have no way of querying what the latest image is.

@iRevive
Copy link

iRevive commented Oct 19, 2022

I have a similar issue. I use Terraform to provision the resources (ECS, EC2, etc). But deployments are managed by the GitLab pipeline: the script updates the task definition with a new tag.

To prevent Terraform from reverting the tag, I ignore changes in the task definition:

resource "aws_ecs_service" "service" {
  ...
  lifecycle {
    ignore_changes = [task_definition, desired_count]
  }
}

This approach works fine until something apart from the image tag needs to be changed in the task definition (e.g. add a new environment variable).

@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/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants