module "lambda-nr-ownership-ingest-product-writer" {
  source                      = "git@github.com:theorchard/terraform-lambda.git//?ref=4.0.1"
  environment                 = var.environment
  lambda_name                 = var.product_writer_lambda_name
  lambda_description          = "Lambda that writes products in ownership ingestion csv."
  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
  application_family          = var.application_family
  lambda_function_memory_size = var.lambda_memory_size
  splitio_enabled             = true

  lambda_function_environment_variables = {
    Environment           = var.environment
    DD_LAMBDA_HANDLER     = "app.handler"
    SENTRY_DSN            = module.lambda_nr_ownership_ingest_product_writer_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     = var.kafkajs_log_level
  }

  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_writer_sentry_project" {
  source                       = "git@github.com:theorchard/terraform-sentry//?ref=4.1.2"
  service_name                 = "lambda-nr-ownership-product-writer"
  secrets_manager_service_name = var.product_writer_lambda_name
  environment                  = var.environment
  platform                     = "node"
  application_family           = var.application_family
}

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