
// The product-deduplicator creation Lambda
module "lambda_nr_ownership_ingest_product_deduplicator" {
  source                   = "git@github.com:theorchard/terraform-lambda.git//?ref=3.1.9"
  environment              = var.environment
  lambda_name              = var.product_deduplicator_lambda_name
  lambda_description       = "Dedupe products in the input file."
  lambda_function_timeout  = "900"
  use_container_image      = true
  vpc_subnet_ids           = module.vpc_info.default_private_subnet_ids
  vpc_enabled              = true
  vpc_id                   = module.vpc_info.vpc_id
  datadog_advanced_enabled = true
  splitio_enabled          = true
  application_family       = var.application_family

  lambda_function_environment_variables = {
    Environment           = var.environment
    DD_LAMBDA_HANDLER     = "app.handler"
    SENTRY_DSN            = module.lambda_nr_ownership_ingest_product_deduplicator_sentry_project.sentry_key_dsn_public_output
    SPLIT_API_KEY_PATH    = "${var.environment}/split/API_KEY"
    BUCKET_NAME           = data.aws_s3_bucket.s3_bucket.bucket
    REPORTING_KAFKA_TOPIC = var.ownership_ingest_reporting_topic
    KAFKA_BROKERS         = var.kafka_brokers
    SCHEMA_REGISTRY_URL   = var.schema_registry_url
    KAFKAJS_LOG_LEVEL     = "nothing"
  }

  lambda_function_reserved_concurrent_executions = 30

  iam_managed_policy_attachments = [
    data.aws_iam_policy.ownership_ingestion_bucket_rw_policy.arn
  ]
}

module "lambda_nr_ownership_ingest_product_deduplicator_sentry_project" {
  source             = "git@github.com:theorchard/terraform-sentry.git//?ref=4.1.2"
  service_name       = var.product_deduplicator_lambda_name
  environment        = var.environment
  platform           = "node"
  application_family = var.application_family
}

module "datadog_lambda_nr_ownership_ingest_product_deduplicator_dashboards" {
  source                 = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.12.0"
  service_name           = var.product_deduplicator_lambda_name
  environment            = var.environment
  notification_endpoints = var.slack_alert_channel
  teams                  = [var.team_name]
}
