-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
289 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
################################################### | ||
# Pull Through Cache Policy | ||
################################################### | ||
|
||
data "aws_iam_policy_document" "pull_through_cache" { | ||
count = length(var.pull_through_cache_policies) > 0 ? 1 : 0 | ||
|
||
dynamic "statement" { | ||
for_each = var.pull_through_cache_policies | ||
iterator = policy | ||
|
||
content { | ||
sid = "PullThroughCacheAccess-${policy.key}" | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = policy.value.iam_entities | ||
} | ||
actions = (policy.value.allow_create_repository | ||
? ["ecr:CreateRepository", "ecr:BatchImportUpstreamImage"] | ||
: ["ecr:BatchImportUpstreamImage"] | ||
) | ||
resources = [ | ||
for repository in policy.value.repositories : | ||
"arn:aws:ecr:${local.region}:${local.account_id}:repository/${repository}" | ||
] | ||
} | ||
} | ||
} | ||
|
||
|
||
################################################### | ||
# Pull Through Cache Rules | ||
################################################### | ||
|
||
locals { | ||
default_namespaces = { | ||
"ghcr.io" = "github" | ||
"myregistry.azurecr.io" = "azure" | ||
"public.ecr.aws" = "ecr-public" | ||
"quay.io" = "quay" | ||
"registry-1.docker.io" = "docker-hub" | ||
"registry.gitlab.com" = "gitlab" | ||
"registry.k8s.io" = "kubernetes" | ||
} | ||
} | ||
|
||
resource "aws_ecr_pull_through_cache_rule" "this" { | ||
for_each = { | ||
for rule in var.pull_through_cache_rules : | ||
coalesce(rule.namespace, local.default_namespaces[rule.upstream_url]) => rule | ||
} | ||
|
||
ecr_repository_prefix = each.key | ||
upstream_registry_url = each.value.upstream_url | ||
|
||
credential_arn = (each.value.credential != null | ||
? each.value.credential.secretsmanager_secret | ||
: null | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
################################################### | ||
# Replication Policy | ||
################################################### | ||
|
||
data "aws_iam_policy_document" "replication" { | ||
count = length(var.replication_policies) > 0 ? 1 : 0 | ||
|
||
dynamic "statement" { | ||
for_each = var.replication_policies | ||
iterator = policy | ||
|
||
content { | ||
sid = "ReplicationAccess${policy.value.account}" | ||
effect = "Allow" | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = [ | ||
"arn:aws:iam::${policy.value.account}:root" | ||
] | ||
} | ||
actions = (policy.value.allow_create_repository | ||
? ["ecr:CreateRepository", "ecr:ReplicateImage"] | ||
: ["ecr:ReplicateImage"] | ||
) | ||
resources = [ | ||
for repository in policy.value.repositories : | ||
"arn:aws:ecr:${local.region}:${local.account_id}:repository/${repository}" | ||
] | ||
} | ||
} | ||
} | ||
|
||
|
||
################################################### | ||
# Replication Rules | ||
################################################### | ||
|
||
resource "aws_ecr_replication_configuration" "this" { | ||
count = length(var.replication_rules) > 0 ? 1 : 0 | ||
|
||
replication_configuration { | ||
dynamic "rule" { | ||
for_each = var.replication_rules | ||
iterator = rule | ||
|
||
content { | ||
dynamic "destination" { | ||
for_each = rule.value.destinations | ||
|
||
content { | ||
registry_id = coalesce(destination.value.account, local.account_id) | ||
region = destination.value.region | ||
} | ||
} | ||
|
||
dynamic "repository_filter" { | ||
for_each = rule.value.filters | ||
iterator = filter | ||
|
||
content { | ||
filter_type = filter.value.type | ||
filter = filter.value.value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
################################################### | ||
# Scanning Configuration | ||
################################################### | ||
|
||
resource "aws_ecr_registry_scanning_configuration" "this" { | ||
scan_type = var.scanning_type | ||
|
||
dynamic "rule" { | ||
for_each = var.scanning_rules | ||
|
||
content { | ||
scan_frequency = rule.value.frequency | ||
|
||
dynamic "repository_filter" { | ||
for_each = rule.value.filters | ||
iterator = filter | ||
|
||
content { | ||
filter_type = filter.value.type | ||
filter = filter.value.value | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.