# Lambda function to elevate permissions.
module "home_page_lambda" {
  source = "git@github.com:theorchard/terraform-lambda.git//?ref=4.2.0"

  environment        = var.environment
  lambda_name        = local.home_page_lambda_name
  lambda_description = "Lambda function that generate HTML code of Break Glass Home Page."
  application_family = var.application_family

  lambda_runtime           = "python3.13"
  lambda_function_timeout  = var.lambda_function_timeout
  use_container_image      = true
  datadog_advanced_enabled = true

  lambda_function_environment_variables = {
    SENTRY_DSN  = module.home_page_lambda_sentry_project.sentry_key_dsn_public_output
    Environment = var.environment
  }

  vpc_enabled    = true
  vpc_id         = module.vpc_info.vpc_id
  vpc_subnet_ids = module.vpc_info.default_private_subnet_ids

  additional_tags = local.tags
}


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

  environment        = var.environment
  service_name       = local.home_page_lambda_name
  application_family = var.application_family
  teams              = [var.environment]
}

module "home_page_lambda_datadog_monitoring" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.13.6"

  environment  = var.environment
  service_name = local.home_page_lambda_name

  lambda_error_monitor_enabled      = true
  lambda_invocation_monitor_enabled = false

  lambda_error_ok_number                = 0
  lambda_error_warning_recovery_number  = null
  lambda_error_critical_recovery_number = null
  lambda_error_warning_number           = null
  lambda_error_critical_number          = 1

  notification_endpoints            = var.lambda_datadog_notification_endpoints
  escalation_notification_endpoints = var.lambda_datadog_notification_endpoints
}
