locals {
  lambda_ws_fetch_dsp_ids = "${var.service_name}-ws-fetch-dsp-ids"
}

terraform {
  backend "s3" {
    bucket  = "orcd-terraform-state"
    key     = "prod/timed-release/ws-fetch-dsp-ids/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

module "default_tags" {
  source             = "git@github.com:theorchard/terraform-default-tags.git//?ref=2.0.0"
  environment        = var.environment
  application_family = var.application_family
  service_name       = var.service_name
  team_name          = var.team_name
}

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

module "vpc_info" {
  source = "git@github.com:theorchard/terraform-vpc-info.git?ref=3.1.0"

  environment = var.environment
}

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

  environment               = var.environment
  application_family        = var.application_family
  lambda_name               = local.lambda_ws_fetch_dsp_ids

  lambda_description        = "Lambda to fetch dsp ids of unsupported timed release stores"
  lambda_function_timeout   = "300"
  use_container_image       = true
  vpc_enabled               = true
  vpc_id                    = module.vpc_info.vpc_id
  vpc_subnet_ids            = module.vpc_info.default_private_subnet_ids

  datadog_enabled           = true
  datadog_advanced_enabled  = true

  lambda_function_environment_variables = {
    ENVIRONMENT           = var.environment
    SENTRY_DSN            = module.lambda_ws_fetch_dsp_ids_sentry.sentry_key_dsn_public_output
    GRAPHQL_URL           = var.graphql_url
    OWS_TIMED_RELEASE_URL = var.ows_timed_release_url
    ORCHARD_PROFILE_ID    = var.orchard_profile_id
    ORCHARD_PROFILE_UUID  = var.orchard_profile_uuid
    ORCHARD_PROFILE_TYPE  = var.orchard_profile_type
    ORCHARD_IDENTITY_ID   = var.orchard_identity_id
  }
}

module "lambda_ws_fetch_dsp_ids_datadog" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.13.9"

  environment                       = var.environment
  service_name                      = local.lambda_ws_fetch_dsp_ids
  lambda_invocation_monitor_enabled = false
  notification_endpoints            = var.notification_endpoints
  escalation_notification_endpoints = var.escalation_notification_endpoints
}

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

  service_name       = local.lambda_ws_fetch_dsp_ids
  environment        = var.environment
  platform           = "node"
  application_family = var.application_family
}
