Skip to content

Commit f82e330

Browse files
Update module sources and add ECR registry policy (#63)
* Update module sources and add ECR registry policy * Update src/main.tf Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Add account_map_enabled variable to Terraform file * Add 'account_map' variable for account ID mapping Added a new variable 'account_map' to define a structured mapping of account names to IDs with optional attributes. * Fix formatting in variables-account-map.tf * Update descriptions for account_map variables --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 8c2fbdb commit f82e330

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

src/main.tf

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@ locals {
33
}
44

55
module "full_access" {
6-
source = "../account-map/modules/roles-to-principals"
6+
source = "github.com/cloudposse-terraform-components/aws-account-map//src/modules/roles-to-principals?ref=v1.536.1"
77

88
role_map = var.read_write_account_role_map
99

10+
tenant = var.account_map_enabled ? module.iam_roles.global_tenant_name : null
11+
environment = var.account_map_enabled ? module.iam_roles.global_environment_name : null
12+
stage = var.account_map_enabled ? module.iam_roles.global_stage_name : null
13+
14+
account_map_bypass = !var.account_map_enabled
15+
account_map_defaults = var.account_map
16+
1017
context = module.this.context
1118
}
1219

1320
module "readonly_access" {
14-
source = "../account-map/modules/roles-to-principals"
21+
source = "github.com/cloudposse-terraform-components/aws-account-map//src/modules/roles-to-principals?ref=v1.536.1"
1522

1623
role_map = var.read_only_account_role_map
1724

25+
tenant = var.account_map_enabled ? module.iam_roles.global_tenant_name : null
26+
environment = var.account_map_enabled ? module.iam_roles.global_environment_name : null
27+
stage = var.account_map_enabled ? module.iam_roles.global_stage_name : null
28+
29+
account_map_bypass = !var.account_map_enabled
30+
account_map_defaults = var.account_map
31+
1832
context = module.this.context
1933
}
2034

@@ -63,3 +77,29 @@ resource "aws_ecr_pull_through_cache_rule" "this" {
6377
upstream_registry_url = each.value.registry
6478
credential_arn = length(each.value.secret) > 0 ? data.aws_secretsmanager_secret.cache_credentials[each.key].arn : null
6579
}
80+
81+
data "aws_caller_identity" "current" {
82+
count = local.enabled ? 1 : 0
83+
}
84+
85+
resource "aws_ecr_registry_policy" "this" {
86+
for_each = toset(local.enabled && length(var.pull_through_cache_rules) > 0 ? ["true"] : [])
87+
policy = jsonencode({
88+
Version = "2012-10-17"
89+
Statement = [
90+
{
91+
Effect = "Allow"
92+
Action = [
93+
"ecr:BatchGetImage",
94+
"ecr:GetDownloadUrlForLayer",
95+
"ecr:GetImageCopyStatus",
96+
"ecr:BatchImportUpstreamImage"
97+
]
98+
Principal = {
99+
AWS = distinct(compact(concat(module.full_access.principals, module.readonly_access.principals, [local.ecr_user_arn])))
100+
}
101+
Resource = format("arn:aws:ecr:%s:%s:repository/*", var.region, one(data.aws_caller_identity.current.*.account_id))
102+
}
103+
]
104+
})
105+
}

src/variables-account-map.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
variable "account_map_enabled" {
2+
type = bool
3+
description = "INFO: Temporary variable required for account-map deprication plan. Please do not change the value"
4+
default = true
5+
}
6+
7+
variable "account_map" {
8+
type = object({
9+
full_account_map = map(string)
10+
audit_account_account_name = optional(string, "")
11+
root_account_account_name = optional(string, "")
12+
identity_account_account_name = optional(string, "")
13+
aws_partition = optional(string, "aws")
14+
iam_role_arn_templates = optional(map(string), {})
15+
})
16+
description = "INFO: Temporary variable required for account-map deprication plan. Please do not change the value"
17+
default = {
18+
full_account_map = {}
19+
audit_account_account_name = ""
20+
root_account_account_name = ""
21+
identity_account_account_name = ""
22+
aws_partition = "aws"
23+
iam_role_arn_templates = {}
24+
}
25+
}

0 commit comments

Comments
 (0)