# Lambda defintion for send_failure step (temporary it will be a healthcheck endpoint)

# allow making owsrequests from lambda
module "lambda_send_failure_owsrequest" {
  source = "git@github.com:theorchard/terraform-owsrequest.git//?ref=1.1.0"

  environment_name = var.environment
  service_name     = "lambda-send-failure"
}

# lambda defination
module "lambda_send_failure" {
  source = "git@github.com:theorchard/terraform-lambda.git//?ref=5.2.1"

  environment         = var.environment
  use_container_image = true
  lambda_name         = "lambda-send-failure"
  lambda_description  = "For send_failure step in step function."
  application_family  = var.application_family

  lambda_function_environment_variables = {
    Environment   = var.environment
    LOGGER_DSN    = var.logger_dsn
    SENTRY_DSN    = module.sentry_gda_account_creation.sentry_key_dsn_public_output
    KAFKA_BROKERS = var.kafka_brokers
    KAFKA_TOPIC   = var.kafka_topic
  }

  lambda_function_timeout                        = var.lambda_default_timeout
  vpc_id                                         = var.vpc_id
  vpc_subnet_ids                                 = var.vpc_subnet_ids
  lambda_function_reserved_concurrent_executions = var.lambda_concurrent_executions
  datadog_enabled                                = var.datadog_enabled
  datadog_advanced_enabled                       = false

  iam_managed_policy_attachments = [
    module.lambda_send_failure_owsrequest.policy_arn_output
  ]
}


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

  environment                       = var.environment
  service_name                      = "lambda-send-failure"
  lambda_invocation_monitor_enabled = false
}
