variable environment {}
variable lambda_function_name {}
variable api_gateway_instance_name {}

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

# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket         = "terraform-state-bucket"
    key            = "env/appname/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = "true"
    dynamodb_table = "terraform-env-appname"
  }
}

# Use the owsrequest module
module "iam_owsrequest" {
  source = "git@github.com:theorchard/terraform-owsrequest.git"

  environment_name = "${var.environment}"
  service_name = "lambda-${var.lambda_function_name}"
}

module "lambda_function" {
  source = "../modules/lambda"

  s3_bucket                             = "${var.environment}-orcdbucket"
  s3_path                               = "path_inside_bucket"
  lambda_name                           = "${var.environment}-${var.lambda_function_name}"
  lambda_description                    = "This function does important things"
  lambda_function_environment_variables = {
    Environment = "dev",
    DEBUG_MODE  = "true"
                                          }
  lambda_function_handler               = "file_name.handler_name"
  # This is a dummy zip used for function creation only.
  lambda_function_package_path          = "${path.module}/lambda.zip"
  lambda_function_timeout               = 300
  owsrequest_iam_policy                 = "${module.iam_owsrequest.policy_arn_output}"
  vpc_security_group_ids                = ["sg-12345678"]
  vpc_subnet_ids                        = ["subnet-12345678", "subnet-01234567"]
}
