module "lambda-publishing-changelog-report-compiler" {
  source                      = "git@github.com:theorchard/terraform-lambda.git//?ref=4.3.0"
  environment                 = var.environment
  lambda_name                 = var.report_compiler_lambda_name
  lambda_description          = "Responsible for compiling the individual rows of composition changes into one big xlsx file and saving that file in s3."
  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 = "5120"
  splitio_enabled             = true

  lambda_function_environment_variables = {
    Environment        = var.environment
    DD_LAMBDA_HANDLER  = "app.handler"
    SENTRY_DSN         = module.lambda_publishing_changelog_report_compiler_lambda_name_sentry_project.sentry_key_dsn_public_output
    BUCKET_NAME        = data.aws_s3_bucket.s3_bucket.bucket
    SPLIT_API_KEY_PATH = "${var.environment}/split/API_KEY"
  }

  lambda_function_reserved_concurrent_executions = 10

  iam_managed_policy_attachments = [
    aws_iam_policy.publishing_compositions_s3_list.arn,
    aws_iam_policy.publishing_compositions_s3_read.arn,
    aws_iam_policy.publishing_compositions_s3_write.arn
  ]
}

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

module "datadog_lambda_publishing_changelog_report_compiler_dashboards" {
  source                            = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.13.9"
  service_name                      = var.report_compiler_lambda_name
  environment                       = var.environment
  lambda_invocation_monitor_enabled = false
  lambda_error_monitor_enabled      = true
  notification_endpoints            = var.slack_alert_channel
}
