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

  environment                                    = var.environment
  lambda_name                                    = "lambda-${var.service_name}-github-cli"
  application_family                             = var.application_family
  lambda_description                             = "Searches for text occurrences in Github org"
  use_container_image                            = true
  datadog_advanced_enabled                       = true
  vpc_enabled                                    = false
  lambda_function_timeout                        = 300
  lambda_function_reserved_concurrent_executions = 10
  splitio_enabled                                = false
  zappa_s3_policy_enabled                        = false

  lambda_function_environment_variables = {
    Environment  = var.environment
    SERVICE_NAME = "lambda-${var.service_name}-github-cli"
    SENTRY_DSN   = module.sentry_project_github_cli.sentry_key_dsn_public_output
    GITHUB_TOKEN = "${var.environment}/lambda-${var.service_name}-github-cli/GITHUB_TOKEN"
  }
}

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

  environment        = var.environment
  platform           = "python"
  service_name       = "lambda-${var.service_name}-github-cli"
  teams              = [var.environment]
  application_family = var.application_family
}

module "lambda_github_cli_secrets" {
  source   = "git@github.com:theorchard/terraform-secrets-manager.git//?ref=1.5.1"
  for_each = toset(var.github_cli_secrets)

  environment        = var.environment
  service_name       = "lambda-${var.service_name}-github-cli"
  secret_name        = each.value
  application_family = var.application_family
}
