variable "environment" {
  default = "dev"
}

variable "service_name" {
  default = "ows-test-with-custom-waf"
}

variable "aws_region" {
  default = "us-east-1"
}

variable "application_family" {
  default = "devops"
}

variable "team_name" {
  default = "devops"
}

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

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
  alias   = "dev"
  profile = "dev"

  default_tags {
    tags = module.default_tags.tags
  }
}

data "aws_caller_identity" "current" {}

data "aws_route53_zone" "route53_zone" {
  name = "${var.environment}.theorchard.io"
}

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

  environment = var.environment
}

module "custom_waf" {
  source            = "git@github.com:theorchard/terraform-aws-waf.git//?ref=1.5.0"
  environment       = var.environment
  service_name      = var.service_name
  aws_region        = var.aws_region
  count_waf_enabled = false
  block_waf_enabled = true
}

module "ows_service_environment" {
  source = "../../../"

  providers = {
    aws.dns = aws.dev
  }

  environment                      = var.environment
  service_name                     = var.service_name
  application_family               = "platform"
  aws_region                       = var.aws_region
  commit_sha                       = "latest"
  container_port                   = "8080"
  task_type                        = "web_service"
  desired_task_count               = 1
  task_cpu                         = 2048
  task_memory                      = 4096
  maximum_capacity                 = 4
  minimum_capacity                 = 1
  override_route53_zone_id         = data.aws_route53_zone.route53_zone.zone_id
  web_service_health_check_command = "curl -s -f -o /dev/null http://localhost:8080/hello/ || exit 1"
  custom_waf_arn                   = module.custom_waf.waf_blocking_arn_output
  fargate_service_subnets          = module.vpc_info.default_private_subnet_ids
  load_balancer_subnets            = module.vpc_info.default_private_subnet_ids
  # These are optional
  additional_tags = {
    "user_supplied_tag_1" = "some_project",
    "user_supplied_tag_2" = "orchard"
  }

  vpc_id = module.vpc_info.vpc_id

  environment_variables = [
    {
      Environment = "${var.environment}"
    },
  ]
}
