module "lambda-publishing-changelog-row-builder" {
  source                      = "git@github.com:theorchard/terraform-lambda.git?ref=3.1.9"
  environment                 = var.environment
  lambda_name                 = var.row_builder_lambda_name
  lambda_description          = "Generates and stores in S3 row for each composition. "
  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 = "2048"
  splitio_enabled             = true

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

  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_row_builder_lambda_name_sentry_project" {
  source                       = "git@github.com:theorchard/terraform-sentry.git//?ref=4.1.2"
  service_name                 = var.row_builder_lambda_name
  secrets_manager_service_name = var.row_builder_lambda_name
  environment                  = var.environment
  platform                     = "node"
  application_family           = var.application_family
}

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