# ------------------------------------------------------------------------------------------------------------
# COMMON TERRAGRUNT CONFIGURATION
# This is the common component configuration for lambda. The common variables for each environment to
# deploy lambda are defined here. This configuration will be merged into the environment configuration
# via an include block.
# ------------------------------------------------------------------------------------------------------------

inputs = {
  runtime             = "nodejs20.x"
  timeout             = 10 
  handler             = "/opt/nodejs/node_modules/datadog-lambda-js/handler.handler"
  architectures       = ["x86_64"]
  layers = [
    "arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node20-x:115",
    "arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:65"
  ]
  ignore_source_code_hash = true
  create_default_role     = false
  datadog_config = {
    DD_ENABLED                         = false
    DD_API_KEY_SECRET_ARN              = ""
    DD_SITE                            = "datadoghq.com"
    DD_LAMBDA_HANDLER                  = "index.handler"
    DD_TRACE_ENABLED                   = true
    DD_LOGS_INJECTION                  = true
    DD_APM_OBFUSCATION_MONGODB_ENABLED = false
    NODE_ENV                           = "production"
  }

  ### Attach existing policies
  existing_policies = [
    "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess",
    "arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
  ]
  
  policy_statements = {
    account = {
      effect  = "Allow"
      actions = ["sts:AssumeRole"]
      principals = [{
        type        = "Service"
        identifiers = ["lambda.amazonaws.com"]
      }]
    }
  }
}
