diff --git a/README.md b/README.md index c30cb38..56879c6 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ Available targets: | attributes | Additional attributes (e.g. `policy` or `role`) | list(string) | `` | no | | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | | enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| image_names | List of Docker local image names, used as repository names for AWS ECR | list(string) | `` | no | | max_image_count | How many Docker Image versions AWS ECR will store | string | `500` | no | | name | The Name of the application or solution (e.g. `bastion` or `portal`) | string | - | yes | | namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | @@ -152,7 +153,10 @@ Available targets: | registry_id | Registry ID | | registry_url | Registry URL | | repository_arn | Repository ARN | +| repository_arn_map | Map of repository names to repository ARNs | +| repository_id_map | Map of repository names to repository IDs | | repository_name | Repository name | +| repository_url_map | Map of repository names to repository URLs | diff --git a/docs/terraform.md b/docs/terraform.md index 0f0c381..6251f0b 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -5,6 +5,7 @@ | attributes | Additional attributes (e.g. `policy` or `role`) | list(string) | `` | no | | delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no | | enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| image_names | List of Docker local image names, used as repository names for AWS ECR | list(string) | `` | no | | max_image_count | How many Docker Image versions AWS ECR will store | string | `500` | no | | name | The Name of the application or solution (e.g. `bastion` or `portal`) | string | - | yes | | namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | @@ -23,5 +24,8 @@ | registry_id | Registry ID | | registry_url | Registry URL | | repository_arn | Repository ARN | +| repository_arn_map | Map of repository names to repository ARNs | +| repository_id_map | Map of repository names to repository IDs | | repository_name | Repository name | +| repository_url_map | Map of repository names to repository URLs | diff --git a/examples/multiple-repo/main.tf b/examples/multiple-repo/main.tf new file mode 100644 index 0000000..85ea32b --- /dev/null +++ b/examples/multiple-repo/main.tf @@ -0,0 +1,12 @@ +provider "aws" { + region = "eu-west-1" +} + +module "ecr" { + source = "../../" + namespace = "eg" + stage = "dev" + name = "app" + use_fullname = false + list_image = ["redis", "nginx"] +} diff --git a/examples/multiple-repo/outputs.tf b/examples/multiple-repo/outputs.tf new file mode 100644 index 0000000..d04af63 --- /dev/null +++ b/examples/multiple-repo/outputs.tf @@ -0,0 +1,8 @@ +output "repository_id_map" { + value = module.ecr.repository_id_map + description = "Repository id map" +} +output "repository_url_map" { + value = module.ecr.repository_url_map + description = "Repository url map" +} \ No newline at end of file diff --git a/main.tf b/main.tf index d348165..10fb38a 100755 --- a/main.tf +++ b/main.tf @@ -16,9 +16,14 @@ module "label" { regex_replace_chars = var.regex_replace_chars } +locals { + _name = var.use_fullname ? module.label.id : module.label.name + image_names = length(var.image_names) > 0 ? var.image_names : [local._name] +} + resource "aws_ecr_repository" "default" { - count = var.enabled ? 1 : 0 - name = var.use_fullname ? module.label.id : module.label.name + count = var.enabled ? length(local.image_names) : 0 + name = local.image_names[count.index] image_scanning_configuration { scan_on_push = var.scan_images_on_push @@ -28,8 +33,8 @@ resource "aws_ecr_repository" "default" { } resource "aws_ecr_lifecycle_policy" "default" { - count = var.enabled ? 1 : 0 - repository = join("", aws_ecr_repository.default.*.name) + count = var.enabled ? length(local.image_names) : 0 + repository = aws_ecr_repository.default[count.index].name policy = <