Skip to content

Commit be2edd1

Browse files
feat: Add new variable for allowing ECR image sharing to lambda service in external account (#16)
Co-authored-by: Bryant Biggs <[email protected]> Co-authored-by: Poh Peng <[email protected]>
1 parent a36e928 commit be2edd1

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ No modules.
234234
| <a name="input_repository_image_scan_on_push"></a> [repository\_image\_scan\_on\_push](#input\_repository\_image\_scan\_on\_push) | Indicates whether images are scanned after being pushed to the repository (`true`) or not scanned (`false`) | `bool` | `true` | no |
235235
| <a name="input_repository_image_tag_mutability"></a> [repository\_image\_tag\_mutability](#input\_repository\_image\_tag\_mutability) | The tag mutability setting for the repository. Must be one of: `MUTABLE` or `IMMUTABLE`. Defaults to `IMMUTABLE` | `string` | `"IMMUTABLE"` | no |
236236
| <a name="input_repository_kms_key"></a> [repository\_kms\_key](#input\_repository\_kms\_key) | The ARN of the KMS key to use when encryption\_type is `KMS`. If not specified, uses the default AWS managed key for ECR | `string` | `null` | no |
237+
| <a name="input_repository_lambda_read_access_arns"></a> [repository\_lambda\_read\_access\_arns](#input\_repository\_lambda\_read\_access\_arns) | The ARNs of the Lambda service roles that have read access to the repository | `list(string)` | `[]` | no |
237238
| <a name="input_repository_lifecycle_policy"></a> [repository\_lifecycle\_policy](#input\_repository\_lifecycle\_policy) | The policy document. This is a JSON formatted string. See more details about [Policy Parameters](http://docs.aws.amazon.com/AmazonECR/latest/userguide/LifecyclePolicies.html#lifecycle_policy_parameters) in the official AWS docs | `string` | `""` | no |
238239
| <a name="input_repository_name"></a> [repository\_name](#input\_repository\_name) | The name of the repository | `string` | `""` | no |
239240
| <a name="input_repository_policy"></a> [repository\_policy](#input\_repository\_policy) | The JSON policy to apply to the repository. If not specified, uses the default policy | `string` | `null` | no |

main.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,33 @@ data "aws_iam_policy_document" "repository" {
6262
}
6363
}
6464

65+
66+
dynamic "statement" {
67+
for_each = var.repository_type == "private" && length(var.repository_lambda_read_access_arns) > 0 ? [1] : []
68+
69+
content {
70+
sid = "PrivateLambdaReadOnly"
71+
72+
principals {
73+
type = "Service"
74+
identifiers = ["lambda.amazonaws.com"]
75+
}
76+
77+
actions = [
78+
"ecr:BatchGetImage",
79+
"ecr:GetDownloadUrlForLayer",
80+
]
81+
82+
condition {
83+
test = "StringLike"
84+
variable = "aws:sourceArn"
85+
86+
values = var.repository_lambda_read_access_arns
87+
}
88+
89+
}
90+
}
91+
6592
dynamic "statement" {
6693
for_each = length(var.repository_read_write_access_arns) > 0 && var.repository_type == "private" ? [var.repository_read_write_access_arns] : []
6794

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ variable "repository_read_access_arns" {
9090
default = []
9191
}
9292

93+
variable "repository_lambda_read_access_arns" {
94+
description = "The ARNs of the Lambda service roles that have read access to the repository"
95+
type = list(string)
96+
default = []
97+
}
98+
9399
variable "repository_read_write_access_arns" {
94100
description = "The ARNs of the IAM users/roles that have read/write access to the repository"
95101
type = list(string)

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module "wrapper" {
1717
attach_repository_policy = try(each.value.attach_repository_policy, var.defaults.attach_repository_policy, true)
1818
create_repository_policy = try(each.value.create_repository_policy, var.defaults.create_repository_policy, true)
1919
repository_read_access_arns = try(each.value.repository_read_access_arns, var.defaults.repository_read_access_arns, [])
20+
repository_lambda_read_access_arns = try(each.value.repository_lambda_read_access_arns, var.defaults.repository_lambda_read_access_arns, [])
2021
repository_read_write_access_arns = try(each.value.repository_read_write_access_arns, var.defaults.repository_read_write_access_arns, [])
2122
create_lifecycle_policy = try(each.value.create_lifecycle_policy, var.defaults.create_lifecycle_policy, true)
2223
repository_lifecycle_policy = try(each.value.repository_lifecycle_policy, var.defaults.repository_lifecycle_policy, "")

0 commit comments

Comments
 (0)