variable "environment" {}
variable "github_user_token" {}
variable "user_name" {}
variable "certificate_arn" {}
variable "github_organization" {}
variable "github_repo_names" {type = "list"}
variable "atlantis_repo_whitelist" { type = "list"}
variable "route53_zone_name" {}

terraform {
  backend "s3" {
    bucket         = "dev-orcd-terraform-state"
    key            = "dev/terraform-atalantis-test/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = "true"
    dynamodb_table = "dev-terraform-atalantis-test"
  }
}

module "atlantis" {
  source = "terraform-aws-modules/atlantis/aws"

  name = "${var.environment}-atlantis"

  # VPC setting
  vpc_id             = "vpc-34dbfd51"
  private_subnet_ids = ["subnet-b649dfef", "subnet-44c19a21"]
  public_subnet_ids  = ["subnet-2ff85972", "subnet-9ee89ffa"]

  # DNS (without trailing dot)
  route53_zone_name = "${var.route53_zone_name}"

  # ACM (SSL certificate) - Specify ARN of an existing certificate or new one will be created and validated using Route53 DNS
  certificate_arn = "${var.certificate_arn}"

  allow_repo_config = true

  # Organization settings
  github_token = "${var.github_user_token}"
  github_organization = "${var.github_organization}"
  github_repo_names = "${var.github_repo_names}"

  # Atlantis user
  atlantis_github_user       = "${var.user_name}"
  atlantis_github_user_token = "${var.github_user_token}"
  atlantis_repo_whitelist    = "${var.atlantis_repo_whitelist}"
}
