locals {
  acknowledge_lambda_name = "asset-transcoder-acknowledge"
}

module "acknowledge_owsrequest" {
  source = "git@github.com:theorchard/terraform-owsrequest.git//?ref=1.0.1"

  environment_name = var.environment
  service_name     = "lambda-${local.acknowledge_lambda_name}"
}

# Lambda function for the acknowledge step
module "acknowledge_lambda" {
  source = "git@github.com:theorchard/terraform-lambda.git//?ref=3.1.4"

  application_family  = var.application_family
  environment         = var.environment
  lambda_name         = local.acknowledge_lambda_name
  use_container_image = true
  lambda_description  = "Initiates the asset validation and encoding flow"

  lambda_function_environment_variables = merge({
    Environment                  = var.environment
    SNS_GENERAL_STATUS_TOPIC_ARN = module.sns_general_status.proxied_sns_arn
    LOGGER_DSN                   = "udp://${var.environment}-fluentd-applications-udp.theorchard.io:5160"
  }, var.lambda_additional_environment_variables)

  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
  iam_policy_file_enabled                        = false
  iam_managed_policy_attachments = [
    aws_iam_policy.common_lambda_policy.arn,
    "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/Dynamo-${var.environment}-lambda-${local.acknowledge_lambda_name}-owsrequest",
  ]
}
