locals {
  encryption_config = var.kms_key_arn != null ? {
    encryption_type = "KMS"
    kms_key         = var.kms_key_arn
  } : null
}

resource "aws_ecr_repository" "this" {
  count = var.enabled ? 1 : 0
  name                 = var.name
  image_tag_mutability = "MUTABLE"
  image_scanning_configuration {
    scan_on_push = true
  }
  dynamic "encryption_configuration" {
    for_each = local.encryption_config != null ? [local.encryption_config] : []
    content {
      encryption_type = encryption_configuration.value.encryption_type
      kms_key         = encryption_configuration.value.kms_key
    }
  }
}