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

feat: Add credentials_arn to support ECR pull through cache #30

Conversation

JoseAlvarezSonos
Copy link
Contributor

@JoseAlvarezSonos JoseAlvarezSonos commented Mar 12, 2024

Description

This feature PR adds the ability to pass a credentials_arn to the registry_pull_through_cache_rules variable, to allow to use this new field for pull through caches.

Motivation and Context

Since November 2023, ECR supports new upstream registries as pull through cache, including Dockerhub and GHCR. To use these new upstream registries, it's required to use credentials for the respective registries. AWS added a feature of providing a Secret Manager resource ARN to the ECR pull through cache rule to rely on this credentials. Along side this, the terraform-provider-aws added the same capabilities to the aws_ecr_pull_through_cache_rule resource.

Breaking Changes

This requires an update of the aws provider to >= 5.37 (previously >= 4.20). But there isn't any breaking change to update to this version.

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects

We are using our fork to make sure that it works and added all the required docs and examples to this repo as well.

@JoseAlvarezSonos JoseAlvarezSonos changed the title Feature - Adding credentials_arn for aws_ecr_pull_through_cache_rule feat: Adding credentials_arn for aws_ecr_pull_through_cache_rule Mar 12, 2024
@shivanand-deriv
Copy link

+1

Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but there are some minor improvements to be done.

@@ -112,6 +114,24 @@ data "aws_iam_policy_document" "registry" {
module.ecr.repository_arn,
]
}

dynamic "statement" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rewrite this as two simple statement blocks instead of using dynamic in the example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, refactored

ecr_repository_prefix = "dockerhub"
upstream_registry_url = "registry-1.docker.io"
# Make sure to read https://docs.aws.amazon.com/AmazonECR/latest/userguide/pull-through-cache-creating-secret.html
credential_arn = "arn:aws:secretsmanager:us-east-1:123456789:secret:ecr-pullthroughcache/dockerhub"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create the Secret Manager resource using this module and pass it as a reference here to show the completely working example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I created the resource and added the secret_string as variable, let me know if that's ok

"ecr:CreateRepository",
"ecr:BatchImportUpstreamImage"
]
resources = ["arn:aws:ecr:us-east-1:012345678901:repository/${statement.value}/*"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

012345678901 - should we replace this one with something else (more correct)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation, I replaced it with data.aws_caller_identity.current.account_id

@antonbabenko antonbabenko changed the title feat: Adding credentials_arn for aws_ecr_pull_through_cache_rule feat!: Adding credentials_arn to support ECR pull through cache. Bump AWS provider version. Mar 15, 2024
JoseAlvarezSonos and others added 2 commits March 17, 2024 23:40
- Refactor the a dynamic block into a more verbose format.
- Fixed all regions and accounts relying on data resources
- Creating the Secret manager resources with the proper format included.
@bryantbiggs bryantbiggs changed the title feat!: Adding credentials_arn to support ECR pull through cache. Bump AWS provider version. feat: Add credentials_arn to support ECR pull through cache Mar 17, 2024
Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

cc @antonbabenko

Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think AWS partition should still be fetched from data source to work for govcloud and China. The rest looks good.

@bryantbiggs
Copy link
Member

for the example? we don't usually enforce this for examples and just stick with the default commercial regions. the module source code we absolutely use the data sources to infer the correct partition, region, etc.

@antonbabenko
Copy link
Member

@bryantbiggs I looked in the wrong place :) Approved now

@antonbabenko antonbabenko merged commit 05e6fd0 into terraform-aws-modules:master Mar 25, 2024
6 checks passed
antonbabenko pushed a commit that referenced this pull request Mar 25, 2024
## [2.1.0](v2.0.0...v2.1.0) (2024-03-25)

### Features

* Add `credentials_arn` to support ECR pull through cache ([#30](#30)) ([05e6fd0](05e6fd0))
@antonbabenko
Copy link
Member

This PR is included in version 2.1.0 🎉

Copy link

I'm going to lock this pull request 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 related to this change, 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 Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants