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

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

provider "aws" {
  region  = var.aws_region
  alias   = "dev"
  profile = "dev"

  default_tags {
    tags = module.default_tags.tags
  }
}

terraform {
  backend "s3" {
    bucket  = "dev-orcd-terraform-state"
    key     = "dev/ows-dev-fargate-logging/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

data "aws_caller_identity" "current" {}

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

  environment = var.environment
}

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

module "ows_dev_fargate_logging_fargate_environment" {
  source = "git@github.com:theorchard/terraform-fargate.git//?ref=5.0.1"

  providers = {
    aws.dns = aws.dev
  }

  environment             = var.environment
  service_name            = var.service_name
  aws_region              = var.aws_region
  application_family      = var.application_family
  desired_task_count      = 2
  minimum_capacity        = 2
  maximum_capacity        = 4
  task_cpu                = 512
  task_memory             = 1024
  route53_zone_id         = data.aws_route53_zone.route53_zone.zone_id
  vpc_id                  = module.vpc_info.vpc_id
  fargate_service_subnets = module.vpc_info.default_private_subnet_ids
  load_balancer_subnets   = module.vpc_info.default_private_subnet_ids
  blocking_waf_enabled    = true

  environment_variables = [
    {
      Environment = var.environment
    },
    {
      LOGGER_DSN = "https://${var.environment}-fluentd-applications.theorchard.io:8888/application"
    },
    {
      DATADOG_ENV = "${var.environment}-${var.service_name}"
    },
    {
      DD_LOGS_INJECTION = "true"
    },
  ]
}

module "ows_dev_fargate_logging_fargate_service_dashboard" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/service?ref=6.10.0"

  environment                       = var.environment
  environment_type                  = "fargate"
  service_name                      = var.service_name
  application_family                = var.application_family
  service_4xx_monitor_enabled       = false
  service_5xx_monitor_enabled       = false
  notification_endpoints            = ""
  escalation_notification_endpoints = ""
}
