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

  application_family = var.application_family
  environment        = var.environment
  platform           = "python"
  service_name       = var.acr_function_name
  teams              = [var.environment]
}

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

  environment_name = var.environment
  service_name     = var.acr_function_name
}

module "acrcloud_secret" {
  source = "git@github.com:theorchard/terraform-secrets-manager.git//?ref=1.5.1"

  environment                    = var.environment
  service_name                   = var.acr_function_name
  secret_name                    = "ACR_CLOUD_ACCESS_TOKEN"
  application_family             = var.application_family
  secret_recovery_window_in_days = 7
}

data "aws_iam_policy" "s3_mezz_ro_fingerprinting" {
  name = "S3-${var.environment}-orcd-mezzanine-assets-RO"
}

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

  application_family       = var.application_family
  datadog_advanced_enabled = true
  environment              = var.environment
  lambda_name              = var.acr_function_name
  lambda_description       = "Generate fingerprints from ACRCloud given an asset"
  lambda_function_timeout  = var.lambda_default_timeout
  use_container_image      = true
  vpc_id                   = var.vpc_id
  vpc_subnet_ids           = var.vpc_subnet_ids

  lambda_function_memory_size = 10240

  iam_managed_policy_attachments = [
    data.aws_iam_policy.s3_mezz_ro_fingerprinting.arn,
    module.lambda_acr_fingerprinter_owsrequest.policy_arn_output
  ]

  lambda_function_environment_variables = {
    ENVIRONMENT         = var.environment
    ACR_CLOUD_BUCKET_ID = var.acr_cloud_bucket_id
  }

  lambda_function_reserved_concurrent_executions = "20"
}

module "datadog_lambda_acr_fingerprinter_dashboards" {
  source                            = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.18.1"
  service_name                      = var.acr_function_name
  environment                       = var.environment
  lambda_invocation_monitor_enabled = false
  lambda_error_monitor_enabled      = true
  notification_endpoints            = var.notification_endpoints
  teams                             = var.teams
}
