Skip to content

Commit 096af8c

Browse files
committed
feat(ecr-repository): support aws v6
1 parent 0d6a553 commit 096af8c

File tree

6 files changed

+67
-20
lines changed

6 files changed

+67
-20
lines changed

modules/ecr-repository/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ This module creates following resources.
1111

1212
| Name | Version |
1313
|------|---------|
14-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.10 |
15-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.44 |
14+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.12 |
15+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.12 |
1616

1717
## Providers
1818

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

2323
## Modules
2424

2525
| Name | Source | Version |
2626
|------|--------|---------|
27-
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.10.0 |
27+
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.12.0 |
2828

2929
## Resources
3030

@@ -38,17 +38,16 @@ This module creates following resources.
3838

3939
| Name | Description | Type | Default | Required |
4040
|------|-------------|------|---------|:--------:|
41+
| <a name="input_image_tag_mutability"></a> [image\_tag\_mutability](#input\_image\_tag\_mutability) | (Optional) The image tag mutability setting for the repository. `image_tag_mutability` as defined below.<br/> (Optional) `mode` - The tag mutability setting for the repository. Valid values are `MUTABLE`, `IMMUTABLE`, `MUTABLE_WITH_EXCLUSION` and `IMMUTABLE_WITH_EXCLUSION`. Defaults to `MUTABLE`.<br/> (Optional) `exclusion_filters` - A list of tag exclusion filters for the repository. Each block of `exclusion_filters` as defined below.<br/> (Optional) `type` - The type of filter to use. The only supported value is `WILDCARD`. Defaults to `WILDCARD`.<br/><br/> (Required) `value` - The filter pattern to use for excluding image tags from the mutability setting. | <pre>object({<br/> mode = optional(string, "MUTABLE")<br/> exclusion_filters = optional(list(object({<br/> type = optional(string, "WILDCARD")<br/> value = string<br/> })), [])<br/> })</pre> | n/a | yes |
4142
| <a name="input_name"></a> [name](#input\_name) | (Required) Desired name for the repository. | `string` | n/a | yes |
4243
| <a name="input_encryption"></a> [encryption](#input\_encryption) | (Optional) The encryption configuration of the repository. `encryption` as defined below.<br/> (Optional) `type` - The encryption type to use for the repository. Valid values are `AES256` or `KMS`. Defaults to `AES256`.<br/> (Optional) `kms_key` - The ARN of the KMS key to use for encryption of the repository when `type` is `KMS`. If not specified, uses the default AWS managed key for ECR. | <pre>object({<br/> type = optional(string, "AES256")<br/> kms_key = optional(string)<br/> })</pre> | `{}` | no |
4344
| <a name="input_force_delete"></a> [force\_delete](#input\_force\_delete) | (Optional) If `true`, will delete the repository even if it contains images. Defaults to `true`. | `bool` | `true` | no |
4445
| <a name="input_image_scan_on_push_enabled"></a> [image\_scan\_on\_push\_enabled](#input\_image\_scan\_on\_push\_enabled) | (Optional, Deprecated) Indicates whether images are scanned after being pushed to the repository or not scanned. This configuration is deprecated in favor of registry level scan filters. Defaults to `false`. | `bool` | `false` | no |
45-
| <a name="input_image_tag_immutable_enabled"></a> [image\_tag\_immutable\_enabled](#input\_image\_tag\_immutable\_enabled) | (Optional) Whether to enable the image tag immutability setting for the repository. Enable tag immutability to prevent image tags from being overwritten by subsequent image pushes using the same tag. Disable tag immutability to allow image tags to be overwritten. Defaults to `false`. | `bool` | `false` | no |
4646
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | (Optional) A list of Lifecycle rules for ECR repository. Each block of `lifecycle_rules` as defined below.<br/> (Required) `priority` - The order in which rules are applied, lowest to highest. A lifecycle policy rule with a priority of `1` will be applied first, a rule with priority of `2` will be next, and so on. Must be unique and do not need to be sequential across rules.<br/> (Optional) `descriptoin` - The description of the rule to describe the purpose of a rule within a lifecycle policy.<br/> (Required) `target` - The configuration of target images for the rule. `target` as defined below.<br/><br/> (Required) `status` - Valid values are `tagged`, `untagged`, or `any`. When you specify `tagged` status, either `tag_patterns` or `tag_prefixes` are required, but not both.<br/> (Optional) `tag_patterns` - A list of tag patterns to filter target images. If you specify multiple tags, only the images with all specified tags are selected. There is a maximum limit of four wildcards (*) per string.<br/> (Optional) `tag_prefixes` - A list of tag prefixes to filter target images. If you specify multiple prefixes, only the images with all specified prefixes are selected.<br/> (Required) `expiration` - The configuration of expiration condition for the rule. `expiration` as defined below.<br/><br/> (Optional) `count` - The maximum number of images to keep.<br/> (Optional) `days` - The maximum age of days to keep images. | <pre>list(object({<br/> priority = number<br/> description = optional(string, "Managed by Terraform.")<br/><br/> target = object({<br/> status = string<br/> tag_patterns = optional(list(string), [])<br/> tag_prefixes = optional(list(string), [])<br/> })<br/> expiration = object({<br/> count = optional(number)<br/> days = optional(number)<br/> })<br/> }))</pre> | `[]` | no |
4747
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
4848
| <a name="input_policy"></a> [policy](#input\_policy) | (Optional) The policy document for ECR Repository. This is a JSON formatted string. | `string` | `""` | no |
49-
| <a name="input_resource_group_description"></a> [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no |
50-
| <a name="input_resource_group_enabled"></a> [resource\_group\_enabled](#input\_resource\_group\_enabled) | (Optional) Whether to create Resource Group to find and group AWS resources which are created by this module. | `bool` | `true` | no |
51-
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | (Optional) The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | `""` | no |
49+
| <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 |
50+
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | (Optional) A configurations of Resource Group for this module. `resource_group` as defined below.<br/> (Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.<br/> (Optional) `name` - The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. If not provided, a name will be generated using the module name and instance name.<br/> (Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`. | <pre>object({<br/> enabled = optional(bool, true)<br/> name = optional(string, "")<br/> description = optional(string, "Managed by Terraform.")<br/> })</pre> | `{}` | no |
5251
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
5352

5453
## Outputs
@@ -61,6 +60,8 @@ This module creates following resources.
6160
| <a name="output_image_tag_immutable_enabled"></a> [image\_tag\_immutable\_enabled](#output\_image\_tag\_immutable\_enabled) | Whether to enable tag immutability to prevent image tags from being overwritten. |
6261
| <a name="output_lifecycle_rules"></a> [lifecycle\_rules](#output\_lifecycle\_rules) | The lifecycle rules for the repository. |
6362
| <a name="output_name"></a> [name](#output\_name) | The name of the repository. |
63+
| <a name="output_region"></a> [region](#output\_region) | The AWS region this module resources resides in. |
6464
| <a name="output_registry_id"></a> [registry\_id](#output\_registry\_id) | The registry ID where the repository was created. |
65+
| <a name="output_resource_group"></a> [resource\_group](#output\_resource\_group) | The resource group created to manage resources in this module. |
6566
| <a name="output_url"></a> [url](#output\_url) | The URL of the repository (in the form aws\_account\_id.dkr.ecr.region.amazonaws.com/repositoryName). |
6667
<!-- END_TF_DOCS -->

modules/ecr-repository/main.tf

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,33 @@ locals {
2020
###################################################
2121

2222
resource "aws_ecr_repository" "this" {
23+
region = var.region
24+
2325
name = local.metadata.name
2426

2527
force_delete = var.force_delete
26-
image_tag_mutability = var.image_tag_immutable_enabled ? "IMMUTABLE" : "MUTABLE"
28+
image_tag_mutability = var.image_tag_mutability.mode
29+
30+
dynamic "image_tag_mutability_exclusion_filter" {
31+
for_each = var.image_tag_mutability.exclusion_filters
32+
iterator = filter
33+
34+
content {
35+
filter_type = filter.value.type
36+
filter = filter.value.value
37+
}
38+
}
2739

2840
image_scanning_configuration {
2941
scan_on_push = var.image_scan_on_push_enabled
3042
}
3143

3244
encryption_configuration {
3345
encryption_type = var.encryption.type
34-
kms_key = var.encryption.kms_key
46+
kms_key = (var.encryption.type == "KMS"
47+
? var.encryption.kms_key
48+
: null
49+
)
3550
}
3651

3752
tags = merge(
@@ -51,6 +66,8 @@ resource "aws_ecr_repository" "this" {
5166
resource "aws_ecr_repository_policy" "this" {
5267
count = length(var.policy) > 0 ? 1 : 0
5368

69+
region = var.region
70+
5471
repository = aws_ecr_repository.this.name
5572
policy = var.policy
5673
}
@@ -106,6 +123,8 @@ locals {
106123
resource "aws_ecr_lifecycle_policy" "this" {
107124
count = length(local.lifecycle_policy) >= 100 ? 1 : 0
108125

126+
region = var.region
127+
109128
repository = aws_ecr_repository.this.name
110129
policy = local.lifecycle_policy
111130
}

modules/ecr-repository/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_repository.this.region
4+
}
5+
16
output "name" {
27
description = "The name of the repository."
38
value = var.name

modules/ecr-repository/resource-group.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module "resource_group" {
1616

1717
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

19+
region = var.region
20+
1921
name = local.resource_group_name
2022
description = var.resource_group.description
2123

modules/ecr-repository/variables.tf

Lines changed: 28 additions & 8 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 "name" {
29
description = "(Required) Desired name for the repository."
310
type = string
@@ -18,11 +25,27 @@ variable "policy" {
1825
nullable = false
1926
}
2027

21-
variable "image_tag_immutable_enabled" {
22-
description = "(Optional) Whether to enable the image tag immutability setting for the repository. Enable tag immutability to prevent image tags from being overwritten by subsequent image pushes using the same tag. Disable tag immutability to allow image tags to be overwritten. Defaults to `false`."
23-
type = bool
24-
default = false
25-
nullable = false
28+
variable "image_tag_mutability" {
29+
description = <<EOF
30+
(Optional) The image tag mutability setting for the repository. `image_tag_mutability` as defined below.
31+
(Optional) `mode` - The tag mutability setting for the repository. Valid values are `MUTABLE`, `IMMUTABLE`, `MUTABLE_WITH_EXCLUSION` and `IMMUTABLE_WITH_EXCLUSION`. Defaults to `MUTABLE`.
32+
(Optional) `exclusion_filters` - A list of tag exclusion filters for the repository. Each block of `exclusion_filters` as defined below.
33+
(Optional) `type` - The type of filter to use. The only supported value is `WILDCARD`. Defaults to `WILDCARD`.
34+
35+
(Required) `value` - The filter pattern to use for excluding image tags from the mutability setting.
36+
EOF
37+
type = object({
38+
mode = optional(string, "MUTABLE")
39+
exclusion_filters = optional(list(object({
40+
type = optional(string, "WILDCARD")
41+
value = string
42+
})), [])
43+
})
44+
45+
validation {
46+
condition = contains(["MUTABLE", "IMMUTABLE", "MUTABLE_WITH_EXCLUSION", "IMMUTABLE_WITH_EXCLUSION"], var.image_tag_mutability.mode)
47+
error_message = "Valid values for `mode` are `MUTABLE`, `IMMUTABLE`, `MUTABLE_WITH_EXCLUSION`, `IMMUTABLE_WITH_EXCLUSION`."
48+
}
2649
}
2750

2851
variable "image_scan_on_push_enabled" {
@@ -111,9 +134,6 @@ variable "module_tags_enabled" {
111134
# Resource Group
112135
###################################################
113136

114-
115-
116-
117137
variable "resource_group" {
118138
description = <<EOF
119139
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.

modules/ecr-repository/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.6"
2+
required_version = ">= 1.12"
33

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

0 commit comments

Comments
 (0)