locals {
  lambda_add_product = "${var.service_name}-index-add-product"
}

module "lambda_content_index_add_product" {
  source = "git@github.com:theorchard/terraform-lambda.git//?ref=4.3.0"

  environment        = var.environment
  application_family = var.application_family
  lambda_name        = local.lambda_add_product

  use_container_image                            = true
  lambda_description                             = "Add products in the review queue ES index."
  lambda_function_timeout                        = "600"
  lambda_function_reserved_concurrent_executions = var.index_add_lambda_reserved_concurrency
  vpc_enabled                                    = true
  vpc_id                                         = module.vpc_info.vpc_id
  vpc_subnet_ids                                 = module.vpc_info.default_private_subnet_ids
  datadog_enabled                                = true
  datadog_advanced_enabled                       = true

  iam_managed_policy_attachments = [
    data.aws_iam_policy.opensearch_rw_policy.arn,
  ]

  lambda_function_environment_variables = {
    ENVIRONMENT              = var.environment
    SENTRY_DSN               = module.sentry_lambda_index_add_product.sentry_key_dsn_public_output
    SYSTEM_USER_IDENTITY_ID  = "ea0e755b-b799-4fa9-bce1-3177c49c0d46"
    SYSTEM_USER_PROFILE_ID   = "660987"
    SYSTEM_USER_PROFILE_TYPE = "ContentProfile"
    OPENSEARCH_ENDPOINT      = var.opensearch_endpoint
    OPENSEARCH_PORT          = var.opensearch_port
    OPENSEARCH_INDEX_ALIAS   = var.opensearch_index_alias
  }

  datadog_advanced_merge_xray_traces_enabled = false
}

# stage datadog creds and create dashboards.
module "datadog_lambda_content_index_add_product" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.13.9"

  environment                       = var.environment
  service_name                      = local.lambda_add_product
  notification_endpoints            = var.notification_endpoints
  escalation_notification_endpoints = var.notification_endpoints
}

module "sentry_lambda_index_add_product" {
  source = "git@github.com:theorchard/terraform-sentry.git//?ref=4.1.2"

  environment        = var.environment
  service_name       = local.lambda_add_product
  application_family = var.application_family
}
