provider "aws" {
  region = var.aws_region
}

provider "aws" {
  region  = var.aws_region
  alias   = "networking"
  profile = "networking"
}

terraform {
  backend "s3" {
    bucket  = "orcd-terraform-state"
    key     = "prod/daemon-switchboard-consumer/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

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

  environment = var.environment
}

data "aws_acm_certificate" "theorchard_io" {
  domain   = "*.theorchard.io"
  statuses = ["ISSUED"]
}

data "aws_route53_zone" "route53_zone" {
  name = "theorchard.io"
}

data "aws_vpc" "vpc" {
  tags = {
    Name = "${var.environment}-graphql-switchboard-vpc"
  }
}

data "aws_subnets" "private" {
  filter {
    name   = "vpc-id"
    values = [data.aws_vpc.vpc.id]
  }
  tags = {
    Name = "${var.environment}-${var.graphql_service_name}-private-subnet*"
  }
}

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

  environment        = var.environment
  service_name       = "switchboard-consumer"
  application_family = var.application_family
  shard_count        = 2
  retention_period   = 168
}

module "lambda_switchboard_producer_dashboard" {
  source                                = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.18.1"
  environment                           = var.environment
  service_name                          = "switchboard-producer"
  notification_endpoints                = "@rvstiphout@theorchard.com @evlastos@theorchard.com @owright@theorchard.com @aprice@theorchard.com @amclarty@theorchard.com"
  escalation_notification_endpoints     = "@rvstiphout@theorchard.com @evlastos@theorchard.com @owright@theorchard.com @aprice@theorchard.com @amclarty@theorchard.com"
  lambda_invocation_monitor_enabled     = false
  lambda_error_monitor_enabled          = true
  lambda_error_critical_number          = 2
  lambda_error_warning_number           = 1
  lambda_error_critical_recovery_number = 0
  lambda_error_warning_recovery_number  = 0
}

module "graphql_switchboard_secrets" {
  source             = "git@github.com:theorchard/terraform-secrets-manager.git//?ref=1.5.1"
  for_each           = var.secret_names
  application_family = var.application_family
  environment        = var.environment
  service_name       = "graphql-switchboard"
  secret_name        = each.value
}
