variable env {}

# Elastic Beanstalk environment variables
variable LOGGER_DSN {}
variable SENTRY_DSN {}
variable SECRET_TOKEN {}
variable SECRET_TOKEN_KEY {}

provider "aws" {
  region = "us-east-1"
}

# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket         = "orcd-terraform-state"
    key            = "qa/bff-feature-fm/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = "true"
    dynamodb_table = "terraform-qa-bff-feature-fm"
  }
}

module "bff_feature_fm_owsrequest" {
  source = "git@github.com:theorchard/terraform-owsrequest.git//"

  environment_name = "${var.env}"
  service_name     = "bff-feature-fm"
}

module "bff_feature_fm_environment" {
  source = "git@github.com:theorchard/terraform-elasticbeanstalk.git//"

  environment                               = "${var.env}"
  service_name                              = "bff-feature-fm"
  update_max_batch                          = "1"
  vpc_elb_subnets                           = "subnet-0f4dba24,subnet-30e29047"
  vpc_subnets                               = "subnet-cb4dbae0,subnet-5366ef24"
  vpc_id                                    = "vpc-7f0e841a"
  aws_route53_zone_id                       = "Z2RSKZ9M7TJ9Z"
  elb_v2_access_logs_s3_bucket              = "aws-logs-437795906767-us-east-1"
  iam_managed_policy_attachments            = [
    "${module.bff_feature_fm_owsrequest.policy_arn_output}"
  ]
  load_balancer_listener_port               = "443"
  load_balancer_listener_protocol           = "HTTPS"
  load_balancer_ssl_certificate_arn         = "arn:aws:acm:us-east-1:437795906767:certificate/a76e4883-28aa-4062-a4cc-c06b8012ae28"
  process_port                              = "80"
  process_protocol                          = "HTTP"
  load_balancer_inbound_allowed_cidr_blocks = [
    "34.201.121.156/32",
    "52.201.57.50/32",
    "31.168.227.138/32",
    "100.25.173.143/32",
    "54.91.2.157/32",
    "3.82.169.30/32",
    "18.232.37.235/32",
    "3.217.233.184/32",
    "3.219.37.224/32",
  ]
  vpc_elb_scheme                            = ""

  environment_variables = [
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "Environment"
      value = "${var.env}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "LOGGER_DSN"
      value = "${var.LOGGER_DSN}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "SENTRY_DSN"
      value = "${var.SENTRY_DSN}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "SECRET_TOKEN"
      value = "${var.SECRET_TOKEN}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "SECRET_TOKEN_KEY"
      value = "${var.SECRET_TOKEN_KEY}"
    }
  ]

}