provider "aws" {
  region = "${var.region}"
}

# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket         = "dev-orcd-terraform-state"
    key            = "dev/ows-features/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = "true"
  }
}

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

  environment                       = "dev"
  service_name                      = "ows-features"

  environment_variables = [
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "Environment"
      value = "${var.Environment}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "SENTRY_DSN"
      value = "${var.SENTRY_DSN}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "LOGGER_DSN"
      value = "${var.LOGGER_DSN}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "LOGGER_LEVEL"
      value = "${var.LOGGER_LEVEL}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "REDIS_URL"
      value = "${var.REDIS_URL}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "REDIS_CACHE_TTL"
      value = "${var.REDIS_CACHE_TTL}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "DATADOG_ENV"
      value = "${var.DATADOG_ENV}"
    },
    {
      namespace = "aws:elasticbeanstalk:application:environment"
      name = "DD_APM_ANALYZED_SPANS"
      value = "${var.DD_APM_ANALYZED_SPANS}"
    }
  ]
}

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

  environment              = "dev"
  service_name             = "ows-features"
  cache_engine             = "redis"
}
