Skip to content

Commit 0d6a553

Browse files
committed
feat(ecr-registry): support aws v6
1 parent d856410 commit 0d6a553

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

modules/ecr-registry/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ This module creates following resources.
44

55
- `aws_ecr_account_setting`
66
- `aws_ecr_registry_policy` (optional)
7+
- `aws_ecr_registry_scanning_configuration`
78
- `aws_ecr_replication_configuration` (optional)
89
- `aws_ecr_pull_through_cache_rule` (optional)
9-
- `aws_ecr_registry_scanning_configuration`
1010

1111
<!-- BEGIN_TF_DOCS -->
1212
## Requirements
1313

1414
| Name | Version |
1515
|------|---------|
16-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.10 |
17-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.83 |
16+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12 |
17+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.12 |
1818

1919
## Providers
2020

2121
| Name | Version |
2222
|------|---------|
23-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.91.0 |
23+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.21.0 |
2424

2525
## Modules
2626

@@ -49,11 +49,12 @@ No modules.
4949
| <a name="input_policy"></a> [policy](#input\_policy) | (Optional) The policy document for ECR registry. This is a JSON formatted string. | `string` | `null` | no |
5050
| <a name="input_policy_version"></a> [policy\_version](#input\_policy\_version) | (Optional) The policy version of ECR registry. Valid values are `V1` or `V2`. Defaults to `V2`.<br/> `V1` - Only support three actions: `ReplicateImage`, `BatchImportUpstreamImage`, and `CreateRepository`<br/> `V2` - Support all ECR actions in the policy and enforce the registry policy in all ECR requests | `string` | `"V2"` | no |
5151
| <a name="input_pull_through_cache_policies"></a> [pull\_through\_cache\_policies](#input\_pull\_through\_cache\_policies) | (Optional) A list of ECR Registry Policies for Pull Through Cache. Each block of `pull_through_cache_policies` as defined below.<br/> (Required) `iam_entities` - One or more IAM principals to grant permission. Support the ARN of IAM entities, or AWS account ID.<br/> (Optional) `allow_create_repository` - Whether to auto-create the cached repositories with the same name within the current registry. Defaults to `false`.<br/> (Required) `repositories` - A list of target repositories. Support glob expressions for `repositories` like `*`. | <pre>list(object({<br/> iam_entities = list(string)<br/> allow_create_repository = optional(bool, false)<br/> repositories = list(string)<br/> }))</pre> | `[]` | no |
52-
| <a name="input_pull_through_cache_rules"></a> [pull\_through\_cache\_rules](#input\_pull\_through\_cache\_rules) | (Optional) A list of Pull Through Cache Rules for ECR registry. A `pull_through_cache_rules` block as defined below.<br/> (Required) `upstream_url` - The registry URL of the upstream public registry to use as the source.<br/> (Optional) `namespace` - The repository name prefix to use when caching images from the source registry. Default value is used if not provided.<br/> (Optional) `credential` - The configuration for credential to use to authenticate against the registry. A `credential` block as defined below.<br/> (Required) `secretsmanager_secret` - The ARN of the Secrets Manager secret to use for authentication. | <pre>list(object({<br/> upstream_url = string<br/> namespace = optional(string)<br/> credential = optional(object({<br/> secretsmanager_secret = string<br/> }))<br/> }))</pre> | `[]` | no |
52+
| <a name="input_pull_through_cache_rules"></a> [pull\_through\_cache\_rules](#input\_pull\_through\_cache\_rules) | (Optional) A list of Pull Through Cache Rules for ECR registry. A `pull_through_cache_rules` block as defined below.<br/> (Required) `upstream_url` - The registry URL of the upstream registry to use as the source.<br/> (Optional) `upstream_prefix` - The upstream repository prefix associated with the pull through cache rule. Used if the upstream registry is an ECR private registry. Defaults to `ROOT`.<br/> (Optional) `namespace` - The repository name prefix to use when caching images from the source registry. Default value is used if not provided.<br/> (Optional) `credential` - The configuration for credential to use to authenticate against the registry. A `credential` block as defined below.<br/> (Required) `secretsmanager_secret` - The ARN of the Secrets Manager secret to use for authentication.<br/> (Optional) `iam_role` - The ARN of the IAM role associated with the pull through cache rule. Must be specified if the upstream registry is a cross-account ECR private registry. | <pre>list(object({<br/> upstream_url = string<br/> upstream_prefix = optional(string, "ROOT")<br/> namespace = optional(string)<br/> credential = optional(object({<br/> secretsmanager_secret = string<br/> iam_role = optional(string)<br/> }))<br/> }))</pre> | `[]` | no |
53+
| <a name="input_region"></a> [region](#input\_region) | (Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region. | `string` | `null` | no |
5354
| <a name="input_replication_policies"></a> [replication\_policies](#input\_replication\_policies) | (Optional) A list of replication policies for ECR Registry. Each block of `replication_policies` as defined below.<br/> (Required) `account` - The AWS account ID of the source registry owner.<br/> (Optional) `allow_create_repository` - Whether to auto-create the replicated repositories with the same name within the current registry. Defaults to `false`.<br/> (Required) `repositories` - A list of target repositories. Support glob expressions like `*`. | <pre>list(object({<br/> account = string<br/> allow_create_repository = optional(bool, false)<br/> repositories = list(string)<br/> }))</pre> | `[]` | no |
5455
| <a name="input_replication_rules"></a> [replication\_rules](#input\_replication\_rules) | (Optional) A list of replication rules for ECR Registry. Each rule represents the replication destinations and repository filters for a replication configuration. Each block of `replication_rules` as defined below.<br/> (Required) `destinations` - A list of destinations for replication rule. Each block of `destinations` as defined below.<br/> (Optional) `account` - The AWS account ID of the ECR private registry to replicate to. Only required for cross-account replication.<br/> (Required) `region` - The Region to replicate to.<br/> (Optional) `filters` - The filter settings used with image replication. Specifying a repository filter to a replication rule provides a method for controlling which repositories in a private registry are replicated. If no filters are added, the contents of all repositories are replicated. Each block of `filters` as defined below.<br/> (Optional) `type` - The repository filter type. The only supported value is `PREFIX_MATCH`, which is a repository name prefix. Defaults to `PREFIX_MATCH`.<br/> (Required) `value` - The repository filter value. | <pre>list(object({<br/> destinations = list(object({<br/> account = optional(string)<br/> region = string<br/> }))<br/> filters = optional(list(object({<br/> type = optional(string, "PREFIX_MATCH")<br/> value = string<br/> })), [])<br/> }))</pre> | `[]` | no |
5556
| <a name="input_scanning_basic_version"></a> [scanning\_basic\_version](#input\_scanning\_basic\_version) | (Optional) The version of basic scanning for the registry. Valid values are `AWS_NATIVE` or `CLAIR`. Defaults to `AWS_NATIVE`. `CLAIR` was deprecated. | `string` | `"AWS_NATIVE"` | no |
56-
| <a name="input_scanning_rules"></a> [scanning\_rules](#input\_scanning\_rules) | (Optional) A list of scanning rules to determine which repository filters are used and at what frequency scanning will occur. Each block of `scanning_rules` as defined below.<br/> (Required) `frequency` - The frequency that scans are performed at for a private registry. Valid values are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN`.<br/> (Optional) `filters` - The configuration of repository filters for image scanning.<br/> (Optional) `type` - The repository filter type. The only supported value is `WILDCARD`. A filter with no wildcard will match all repository names that contain the filter. A filter with a wildcard (*) matches on any repository name where the wildcard replaces zero or more characters in the repository name. Defaults to `WILDCARD`.<br/> (Required) `value` - The repository filter value. | <pre>list(object({<br/> frequency = string<br/> filters = optional(list(object({<br/> type = optional(string, "WILDCARD")<br/> value = string<br/> })), [])<br/> }))</pre> | `[]` | no |
57+
| <a name="input_scanning_rules"></a> [scanning\_rules](#input\_scanning\_rules) | (Optional) A list of scanning rules to determine which repository filters are used and at what frequency scanning will occur. Each block of `scanning_rules` as defined below.<br/> (Required) `frequency` - The frequency that scans are performed at for a private registry. Valid values are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN` and `MANUAL`.<br/><br/> - When the `ENHANCED` scan type is specified, the supported scan frequencies are `CONTINUOUS_SCAN` and `SCAN_ON_PUSH`.<br/> - When the `BASIC` scan type is specified, the `SCAN_ON_PUSH` scan frequency is supported. If scan on push is not specified, then the `MANUAL` scan frequency is set by default.<br/> (Optional) `filters` - The configuration of repository filters for image scanning.<br/> (Optional) `type` - The repository filter type. The only supported value is `WILDCARD`. A filter with no wildcard will match all repository names that contain the filter. A filter with a wildcard (*) matches on any repository name where the wildcard replaces zero or more characters in the repository name. Defaults to `WILDCARD`.<br/> (Required) `value` - The repository filter value. | <pre>list(object({<br/> frequency = string<br/> filters = optional(list(object({<br/> type = optional(string, "WILDCARD")<br/> value = string<br/> })), [])<br/> }))</pre> | `[]` | no |
5758
| <a name="input_scanning_type"></a> [scanning\_type](#input\_scanning\_type) | (Optional) The scanning type to set for the registry. Valid values are `ENHANCED` or `BASIC`. Defaults to `BASIC`. | `string` | `"BASIC"` | no |
5859

5960
## Outputs
@@ -66,6 +67,7 @@ No modules.
6667
| <a name="output_policy_version"></a> [policy\_version](#output\_policy\_version) | The policy version of ECR registry. |
6768
| <a name="output_pull_through_cache_policies"></a> [pull\_through\_cache\_policies](#output\_pull\_through\_cache\_policies) | A list of Pull Through Cache policies for ECR Registry. |
6869
| <a name="output_pull_through_cache_rules"></a> [pull\_through\_cache\_rules](#output\_pull\_through\_cache\_rules) | A list of Pull Through Cache Rules for ECR registry. |
70+
| <a name="output_region"></a> [region](#output\_region) | The AWS region this module resources resides in. |
6971
| <a name="output_replication_policies"></a> [replication\_policies](#output\_replication\_policies) | A list of replication policies for ECR Registry. |
7072
| <a name="output_replication_rules"></a> [replication\_rules](#output\_replication\_rules) | A list of replication rules for ECR Registry. |
7173
| <a name="output_scanning_basic_version"></a> [scanning\_basic\_version](#output\_scanning\_basic\_version) | The version of basic scanning for the registry. |

modules/ecr-registry/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ locals {
1515
}
1616

1717
data "aws_caller_identity" "this" {}
18-
data "aws_region" "this" {}
18+
data "aws_region" "this" {
19+
region = var.region
20+
}
1921

2022
locals {
2123
account_id = data.aws_caller_identity.this.id
22-
region = data.aws_region.this.name
24+
region = data.aws_region.this.region
2325
}
2426

2527

@@ -28,6 +30,8 @@ locals {
2830
###################################################
2931

3032
resource "aws_ecr_account_setting" "registry_policy_scope" {
33+
region = var.region
34+
3135
name = "REGISTRY_POLICY_SCOPE"
3236
value = var.policy_version
3337
}
@@ -48,5 +52,7 @@ resource "aws_ecr_registry_policy" "this" {
4852
var.policy != null,
4953
]) ? 1 : 0
5054

55+
region = var.region
56+
5157
policy = data.aws_iam_policy_document.this.json
5258
}

modules/ecr-registry/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = aws_ecr_account_setting.registry_policy_scope.region
4+
}
5+
16
output "name" {
27
description = "The name of the registry."
38
value = local.metadata.name

modules/ecr-registry/pull-through-cache.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,21 @@ resource "aws_ecr_pull_through_cache_rule" "this" {
5252
coalesce(rule.namespace, local.default_namespaces[rule.upstream_url]) => rule
5353
}
5454

55+
region = var.region
56+
5557
ecr_repository_prefix = each.key
5658
upstream_registry_url = each.value.upstream_url
59+
upstream_repository_prefix = (endswith(each.value.upstream_url, "amazonaws.com")
60+
? each.value.upstream_prefix
61+
: null
62+
)
5763

5864
credential_arn = (each.value.credential != null
5965
? each.value.credential.secretsmanager_secret
6066
: null
6167
)
68+
custom_role_arn = (each.value.credential != null
69+
? each.value.credential.iam_role
70+
: null
71+
)
6272
}

modules/ecr-registry/replication.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ data "aws_iam_policy_document" "replication" {
3939
resource "aws_ecr_replication_configuration" "this" {
4040
count = length(var.replication_rules) > 0 ? 1 : 0
4141

42+
region = var.region
43+
4244
replication_configuration {
4345
dynamic "rule" {
4446
for_each = var.replication_rules

modules/ecr-registry/scanning.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
###################################################
44

55
resource "aws_ecr_account_setting" "basic_scan_type_version" {
6+
region = var.region
7+
68
name = "BASIC_SCAN_TYPE_VERSION"
79
value = var.scanning_basic_version
810
}
911

1012
resource "aws_ecr_registry_scanning_configuration" "this" {
13+
region = var.region
14+
1115
scan_type = var.scanning_type
1216

1317
dynamic "rule" {

modules/ecr-registry/variables.tf

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
variable "region" {
2+
description = "(Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region."
3+
type = string
4+
default = null
5+
nullable = true
6+
}
7+
18
variable "policy_version" {
29
description = <<EOF
310
(Optional) The policy version of ECR registry. Valid values are `V1` or `V2`. Defaults to `V2`.
@@ -91,16 +98,20 @@ variable "pull_through_cache_policies" {
9198
variable "pull_through_cache_rules" {
9299
description = <<EOF
93100
(Optional) A list of Pull Through Cache Rules for ECR registry. A `pull_through_cache_rules` block as defined below.
94-
(Required) `upstream_url` - The registry URL of the upstream public registry to use as the source.
101+
(Required) `upstream_url` - The registry URL of the upstream registry to use as the source.
102+
(Optional) `upstream_prefix` - The upstream repository prefix associated with the pull through cache rule. Used if the upstream registry is an ECR private registry. Defaults to `ROOT`.
95103
(Optional) `namespace` - The repository name prefix to use when caching images from the source registry. Default value is used if not provided.
96104
(Optional) `credential` - The configuration for credential to use to authenticate against the registry. A `credential` block as defined below.
97105
(Required) `secretsmanager_secret` - The ARN of the Secrets Manager secret to use for authentication.
106+
(Optional) `iam_role` - The ARN of the IAM role associated with the pull through cache rule. Must be specified if the upstream registry is a cross-account ECR private registry.
98107
EOF
99108
type = list(object({
100-
upstream_url = string
101-
namespace = optional(string)
109+
upstream_url = string
110+
upstream_prefix = optional(string, "ROOT")
111+
namespace = optional(string)
102112
credential = optional(object({
103113
secretsmanager_secret = string
114+
iam_role = optional(string)
104115
}))
105116
}))
106117
default = []
@@ -138,7 +149,10 @@ variable "scanning_basic_version" {
138149
variable "scanning_rules" {
139150
description = <<EOF
140151
(Optional) A list of scanning rules to determine which repository filters are used and at what frequency scanning will occur. Each block of `scanning_rules` as defined below.
141-
(Required) `frequency` - The frequency that scans are performed at for a private registry. Valid values are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN`.
152+
(Required) `frequency` - The frequency that scans are performed at for a private registry. Valid values are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN` and `MANUAL`.
153+
154+
- When the `ENHANCED` scan type is specified, the supported scan frequencies are `CONTINUOUS_SCAN` and `SCAN_ON_PUSH`.
155+
- When the `BASIC` scan type is specified, the `SCAN_ON_PUSH` scan frequency is supported. If scan on push is not specified, then the `MANUAL` scan frequency is set by default.
142156
(Optional) `filters` - The configuration of repository filters for image scanning.
143157
(Optional) `type` - The repository filter type. The only supported value is `WILDCARD`. A filter with no wildcard will match all repository names that contain the filter. A filter with a wildcard (*) matches on any repository name where the wildcard replaces zero or more characters in the repository name. Defaults to `WILDCARD`.
144158
(Required) `value` - The repository filter value.
@@ -156,9 +170,20 @@ variable "scanning_rules" {
156170
validation {
157171
condition = alltrue([
158172
for rule in var.scanning_rules :
159-
contains(["SCAN_ON_PUSH", "CONTINUOUS_SCAN"], rule.frequency)
173+
contains(["SCAN_ON_PUSH", "CONTINUOUS_SCAN", "MANUAL"], rule.frequency)
174+
])
175+
error_message = "Valid values for `frequency` are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN` and `MANUAL."
176+
}
177+
178+
validation {
179+
condition = alltrue([
180+
for rule in var.scanning_rules :
181+
(
182+
(var.scanning_type == "ENHANCED" && contains(["CONTINUOUS_SCAN", "SCAN_ON_PUSH"], rule.frequency)) ||
183+
(var.scanning_type == "BASIC" && contains(["SCAN_ON_PUSH", "MANUAL"], rule.frequency))
184+
)
160185
])
161-
error_message = "Valid values for `frequency` are `SCAN_ON_PUSH`, `CONTINUOUS_SCAN`."
186+
error_message = "For `ENHANCED` scanning_type, valid frequencies are `CONTINUOUS_SCAN` and `SCAN_ON_PUSH`. For `BASIC` scanning_type, valid frequencies are `SCAN_ON_PUSH` and `MANUAL`."
162187
}
163188

164189
validation {

modules/ecr-registry/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.10"
2+
required_version = ">= 1.12"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.83"
7+
version = ">= 6.12"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)