An open API service indexing awesome lists of open source software.

https://github.com/launchbynttdata/tf-aws-module_collection-ecr


https://github.com/launchbynttdata/tf-aws-module_collection-ecr

aws infrastructure-as-code platform-automation reference terraform

Last synced: 27 days ago
JSON representation

Awesome Lists containing this project

README

          

# tf-aws-module_collection-ecr

## Overview

Terraform collection module for AWS Elastic Container Registry (ECR). It creates and configures one or more private ECR repositories by composing the [`cloudposse/ecr/aws`](https://registry.terraform.io/modules/cloudposse/ecr/aws/latest) primitive module (pinned to `~> 1.0`).

**What this module manages:**

- **Repositories** — one private ECR repository per entry in `image_names`; the `name` / `namespace` / `stage` context controls the resulting repository name when `use_fullname = true`
- **Lifecycle policies** — enabled by default (`enable_lifecycle_policy = true`); `max_image_count` (default 500) controls how many image versions are retained, and `time_based_rotation` switches the count type to `sinceImagePushed`
- **Image scanning** — `scan_images_on_push = true` by default
- **Tag immutability** — defaults to `IMMUTABLE`; set `image_tag_mutability = "MUTABLE"` when tags must be overwritten. `image_tag_mutability_exclusion_filter` carves specific tag patterns out of the mutability setting (e.g. keep the registry `IMMUTABLE` but allow `latest` / `stable-*` to move)
- **Encryption** — AES-256 by default; pass `encryption_configuration = { encryption_type = "KMS", kms_key = "" }` for CMK encryption
- **Access control** — granular IAM repository policies via `principals_full_access`, `principals_push_access`, `principals_readonly_access`, `principals_lambda`, `principals_pull_through_access`, and the corresponding `organizations_*` lists for AWS Organizations-level grants
- **Pull-through cache** — `prefixes_pull_through_repositories` exposes upstream registry namespace prefixes
- **Cross-region / cross-account replication** — `replication_configurations` maps to the `aws_ecr_replication_configuration` resource arguments (up to 10 rules, 25 destinations each)
- **Protected tags** — `protected_tags` lists image-tag prefixes excluded from lifecycle eviction (e.g. `["prod", "staging"]`)

**Provider and Terraform versions:** AWS `>= 6.8.0, < 7.0`, Terraform `~> 1.10`.

> **AWS-imposed limits on `image_tag_mutability_exclusion_filter`.** AWS enforces a maximum of **5 filters per repository**, plus length and allowed-character constraints on each `filter` string. This wrapper deliberately does not duplicate those checks (see the comment on the variable in `variables.tf`); they are surfaced by the AWS provider at plan/apply time. Consult the [AWS ECR docs](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-tag-mutability.html) for the current authoritative limits.

**Example:** `examples/complete` — used by Terratest (`tests/post_deploy_functional`). The example injects a random suffix via `TF_VAR_suffix` to guarantee a unique repository name per test run.

## Pre-commit Hooks

This repository uses [pre-commit](https://pre-commit.com/) to enforce code quality. The hooks are configured in `.pre-commit-config.yaml` and include:

| Hook | Purpose |
|------|---------|
| `pre-commit-hooks` (v4.5.0) | Trailing whitespace, YAML/JSON validity, merge-conflict detection, line-ending normalization |
| `terraform_fmt` | Canonical Terraform formatting |
| `terraform_validate` | Module-level `terraform validate` |
| `terraform_docs` | Regenerates the `
## Requirements

| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | ~> 1.10 |
| [aws](#requirement\_aws) | >= 6.8.0, < 7.0 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| [ecr](#module\_ecr) | cloudposse/ecr/aws | ~> 1.0 |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`. This is for some rare cases where resources want additional configuration of tags and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
| [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`, in the order they appear in the list. New attributes are appended to the end of the list. The elements of the list are joined by the `delimiter` and treated as a single ID element. | `list(string)` | `[]` | no |
| [context](#input\_context) | Single object for setting entire context at once. See description of individual variables for details. Leave string and numeric variables as `null` to use default value. Individual variable settings (non-null) override settings in context object, except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |

{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no |
| [delimiter](#input\_delimiter) | Delimiter to be used between ID elements. Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map. Map of maps. Keys are names of descriptors. Values are maps of the form `{ format = string labels = list(string) }` (Type is `any` so the map values can later be enhanced to provide additional options.) `format` is a Terraform format string to be passed to the `format()` function. `labels` is a list of labels, in order, to pass to `format()` function. Label values will be normalized before being passed to `format()` so they will be identical to how they appear in `id`. Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| [enable\_lifecycle\_policy](#input\_enable\_lifecycle\_policy) | Set to false to prevent the module from adding any lifecycle policies to any repositories | `bool` | `true` | no |
| [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| [encryption\_configuration](#input\_encryption\_configuration) | ECR encryption configuration |
object({
encryption_type = string
kms_key = string
})
| `null` | no |
| [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| [force\_delete](#input\_force\_delete) | Whether to delete the repository even if it contains images | `bool` | `false` | no |
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6). Set to `0` for unlimited length. Set to `null` for keep the existing setting, which defaults to `0`. Does not affect `id_full`. | `number` | `null` | no |
| [image\_names](#input\_image\_names) | List of Docker local image names, used as repository names for AWS ECR | `list(string)` | `[]` | no |
| [image\_tag\_mutability](#input\_image\_tag\_mutability) | The tag mutability setting for the repository. Must be one of: `MUTABLE`, `IMMUTABLE`, `MUTABLE_WITH_EXCLUSION`, or `IMMUTABLE_WITH_EXCLUSION`. Use `*_WITH_EXCLUSION` variants when setting `image_tag_mutability_exclusion_filter`. | `string` | `"IMMUTABLE"` | no |
| [image\_tag\_mutability\_exclusion\_filter](#input\_image\_tag\_mutability\_exclusion\_filter) | List of exclusion filters for image tag mutability. Each filter object must contain 'filter' and 'filter\_type' attributes.
Requires AWS provider >= 6.8.0 (the minimum required by this module).
AWS-imposed limits (enforced by the provider, not by this wrapper): a maximum of 5 filters per repository, and per-filter length / allowed-character constraints. Refer to the AWS ECR docs for current limits. |
list(object({
filter = string
filter_type = optional(string, "WILDCARD")
}))
| `[]` | no |
| [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module. Does not affect keys of tags passed in via the `tags` input. Possible values: `lower`, `title`, `upper`. Default value: `title`. | `string` | `null` | no |
| [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to [\"namespace\", \"environment\", \"stage\", \"name\", \"attributes\"]. You can omit any of the
6 labels (\"tenant\" is the 6th), but at least one must be present.

This module is configured to work with the name of the repository provided as input | `list(string)` |
[
"name"
]
| no |
| [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`, set as tag values, and output by this module individually. Does not affect values of tags passed in via the `tags` input. Possible values: `lower`, `title`, `upper` and `none` (no transformation). Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs. Default value: `lower`. | `string` | `null` | no |
| [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output. Default is to include all labels. Tags with empty values will not be included in the `tags` output. Set to `[]` to suppress all generated tags. **Notes:** The value of the `name` tag, if included, will be the `id`, not the `name`. Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be changed in later chained modules. Attempts to change it will be silently ignored. | `list(string)` |
[
"default"
]
| no |
| [max\_image\_count](#input\_max\_image\_count) | How many Docker Image versions AWS ECR will store | `number` | `500` | no |
| [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. This is the only ID element not also included as a `tag`. The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
| [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
| [organizations\_full\_access](#input\_organizations\_full\_access) | Organization IDs to provide with full access to the ECR. | `list(string)` | `[]` | no |
| [organizations\_push\_access](#input\_organizations\_push\_access) | Organization IDs to provide with push access to the ECR | `list(string)` | `[]` | no |
| [organizations\_readonly\_access](#input\_organizations\_readonly\_access) | Organization IDs to provide with readonly access to the ECR. | `list(string)` | `[]` | no |
| [prefixes\_pull\_through\_repositories](#input\_prefixes\_pull\_through\_repositories) | Organization IDs to provide with push access to the ECR | `list(string)` | `[]` | no |
| [principals\_full\_access](#input\_principals\_full\_access) | Principal ARNs to provide with full access to the ECR | `list(string)` | `[]` | no |
| [principals\_lambda](#input\_principals\_lambda) | Principal account IDs of Lambdas allowed to consume ECR | `list(string)` | `[]` | no |
| [principals\_pull\_through\_access](#input\_principals\_pull\_through\_access) | Principal ARNs to provide with pull through access to the ECR | `list(string)` | `[]` | no |
| [principals\_push\_access](#input\_principals\_push\_access) | Principal ARNs to provide with push access to the ECR | `list(string)` | `[]` | no |
| [principals\_readonly\_access](#input\_principals\_readonly\_access) | Principal ARNs to provide with readonly access to the ECR | `list(string)` | `[]` | no |
| [protected\_tags](#input\_protected\_tags) | Name of image tags prefixes that should not be destroyed. Useful if you tag images with names like `dev`, `staging`, and `prod` | `list(string)` | `[]` | no |
| [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string. Characters matching the regex will be removed from the ID elements. If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
| [replication\_configurations](#input\_replication\_configurations) | Replication configuration for a registry. See [Replication Configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_replication_configuration#replication-configuration). |
list(object({
rules = list(object({ # Maximum 10
destinations = list(object({ # Maximum 25
region = string
registry_id = string
}))
repository_filters = list(object({
filter = string
filter_type = string
}))
}))
}))
| `[]` | no |
| [scan\_images\_on\_push](#input\_scan\_images\_on\_push) | Indicates whether images are scanned after being pushed to the repository (true) or not (false) | `bool` | `true` | no |
| [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
| [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`). Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
| [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
| [time\_based\_rotation](#input\_time\_based\_rotation) | Set to true to filter image based on the `sinceImagePushed` count type. | `bool` | `false` | no |
| [use\_fullname](#input\_use\_fullname) | Set 'true' to use `namespace-stage-name` for ecr repository name, else `name` | `bool` | `true` | no |

## Outputs

| Name | Description |
|------|-------------|
| [registry\_id](#output\_registry\_id) | Registry ID |
| [repository\_arn](#output\_repository\_arn) | ARN of first repository created |
| [repository\_arn\_map](#output\_repository\_arn\_map) | Map of repository names to repository ARNs |
| [repository\_name](#output\_repository\_name) | Name of first repository created |
| [repository\_url](#output\_repository\_url) | URL of first repository created |
| [repository\_url\_map](#output\_repository\_url\_map) | Map of repository names to repository URLs |