locals {
  rw_accounts = [
    module.aws_accounts_list.accounts["gdb-delphi-dev"],
    module.aws_accounts_list.accounts["gdb-delphi-prod"],
  ]
  ro_accounts = [
    module.aws_accounts_list.accounts["gdb-artistapp-dev"],
    module.aws_accounts_list.accounts["gdb-artistapp-prod"],
    module.aws_accounts_list.accounts["gdb-apollo-dev"],
    module.aws_accounts_list.accounts["gdb-apollo-prod"],
    module.aws_accounts_list.accounts["gdb-core-dev"],
    module.aws_accounts_list.accounts["gdb-core-prod"],
    module.aws_accounts_list.accounts["gdb-delphi-dev"],
    module.aws_accounts_list.accounts["gdb-delphi-prod"],
    module.aws_accounts_list.accounts["gdb-whitelist-dev"],
    module.aws_accounts_list.accounts["gdb-whitelist-prod"],
  ]
  infra_ecr_tags = merge(
    local.common_tags,
    {
      service                  = "ECR",
      plat_env_project_service = "${local.aggregated_tag}_ECR"
    }
  )
}

module "secrets-rotator" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "infra/lambda/secrets-rotator"
  rw_accounts = local.rw_accounts
  common_tags = local.infra_ecr_tags
}

module "aws-users-key-watchdog" {
  source = "../../modules/ecr/repository_v4"

  repo_name   = "infra/lambda/aws-users-key-watchdog"
  lambda      = true
  rw_accounts = local.rw_accounts
  ro_accounts = values(module.aws_accounts_list.accounts)
  common_tags = local.infra_ecr_tags
}

module "jmeter-runner" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "infra/autotest/jmeter-runner"
  rw_accounts = local.rw_accounts
  common_tags = local.infra_ecr_tags
}

module "a0deploy" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "a0deploy"
  ro_accounts = [module.aws_accounts_list.accounts["gdb-infra-prod"]]
  common_tags = local.infra_ecr_tags
}

module "snowflake_schemachange_ecr" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "snowflake-schemachange"
  common_tags = local.infra_ecr_tags
}

module "python" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "python"
  ro_accounts = local.ro_accounts
  common_tags = local.infra_ecr_tags

  lifecycle_policy = jsonencode({
    rules = [
      {
        description  = "Expire images tagged with python version and older then 4 days."
        rulePriority = 1
        selection = {
          countNumber = 4
          countType   = "sinceImagePushed"
          countUnit   = "days"
          tagStatus   = "tagged"
          tagPrefixList = [
            "3.7", "3.8", "3.9", "3.10"
          ]
        },
        action = {
          type = "expire"
        }
      },
      {
        description  = "Expire untagged images older than 1 day"
        rulePriority = 2
        selection = {
          countNumber = 1
          countType   = "sinceImagePushed"
          countUnit   = "days"
          tagStatus   = "untagged"
        },
        action = {
          type = "expire"
        }
      },
    ]
  })
}

module "redis" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "redis"
  common_tags = local.infra_ecr_tags
}

module "mysql" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "mysql"
  common_tags = local.infra_ecr_tags
}

module "elasticsearch" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "elasticsearch"
  common_tags = local.infra_ecr_tags
}

module "postgres" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "postgres"
  common_tags = local.infra_ecr_tags
}

module "mongo" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "mongo"
  common_tags = local.infra_ecr_tags
}

module "node" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "node"
  common_tags = local.infra_ecr_tags
}

module "nginx" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "nginx"
  common_tags = local.infra_ecr_tags
}

module "sqitch" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "sqitch"
  common_tags = local.infra_ecr_tags
}

module "locust" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "locust"
  ro_accounts = [
    module.aws_accounts_list.accounts["the-orchard-prod"],
  ]
  common_tags = local.infra_ecr_tags
}

module "dotnet-sdk" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "dotnet/sdk"
  common_tags = local.infra_ecr_tags
}

module "dotnet-runtime" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "dotnet/runtime"
  common_tags = local.infra_ecr_tags
}

module "db-manager" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "infra/db-manager"
  ro_accounts = local.ro_accounts
  common_tags = local.infra_ecr_tags
}

module "locust_runner" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "infra/locust-runner"
  common_tags = local.infra_ecr_tags
}

module "split_synchronizer" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "split-synchronizer"
  ro_accounts = local.ro_accounts
  common_tags = local.infra_ecr_tags
}

module "eclipse_temurin" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "eclipse-temurin"
  ro_accounts = local.ro_accounts
  common_tags = local.infra_ecr_tags
}

module "ses_complaints_hard_bounces_notifications" {
  source = "../../modules/ecr/repository_v4"

  repo_name     = "infra/lambda/ses-complaints-hard-bounces-notifications"
  lambda        = true
  lambda_region = "us-east-1"
  ro_accounts = [
    module.aws_accounts_list.accounts["gdb-delphi-prod"],
    module.aws_accounts_list.accounts["gdb-core-dev"]
  ]
  common_tags = local.infra_ecr_tags
}

module "cross_product_documentation_notifications" {
  source = "../../modules/ecr/repository_v4"

  repo_name     = "infra/lambda/cross-product-documentation-notifications"
  lambda        = true
  lambda_region = "us-east-1"
  common_tags   = local.infra_ecr_tags
}

module "gdb_web_shared_components" {
  source = "../../modules/ecr/repository_v4"

  repo_name   = "gdb-web-shared-components"
  common_tags = local.infra_ecr_tags
}

module "billing_report" {
  source        = "../../modules/ecr/repository_v4"
  repo_name     = "infra/lambda/billing-report"
  lambda        = true
  lambda_region = "us-east-1"
  ro_accounts   = [module.aws_accounts_list.accounts["gdb-infra-prod"]]
  common_tags   = local.infra_ecr_tags
}

module "dd_agent_db_wrapper" {
  source      = "../../modules/ecr/repository_v1"
  repo_name   = "infra/dd-agent-db-wrapper"
  ro_accounts = local.ro_accounts
  common_tags = local.infra_ecr_tags
}
