provider "aws" {
  region = "us-east-1"
  default_tags {
    tags = {
      account_group = var.account_group
      environment   = var.environment
      terraformed   = true
    }
  }
}

terraform {
  backend "s3" {
    bucket  = "qa-ecommerce-terraform-state"
    key     = "qa/us_east_1_vpc/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

data "aws_ec2_transit_gateway" "transit_gateway" {
  filter {
    name   = "options.amazon-side-asn"
    values = ["64513"]
  }
}

data "aws_ec2_managed_prefix_lists" "required_routes" {
  filter {
    name   = "prefix-list-name"
    values = var.vpc_routing_destination_prefix_lists
  }
}

data "aws_route53_resolver_firewall_rule_group" "dns_firewall_rule_group" {
  firewall_rule_group_id = "rslvr-frg-1764658298884585" # sony_ioc_rule_group
}

module "vpc" {
  source = "git@github.com:theorchard/terraform-vpc.git//modules/vpc?ref=4.2.0"

  account_group              = var.account_group
  env                        = var.environment
  vpc_cidr                   = "10.219.32.0/21"
  dns_firewall_rule_group_id = data.aws_route53_resolver_firewall_rule_group.dns_firewall_rule_group.id


  vpc_public_subnets = [
    { availability_zone = "us-east-1a", cidr_block = "10.219.32.0/26", name = "${var.environment}_public_subnet_0" },
    { availability_zone = "us-east-1b", cidr_block = "10.219.32.64/26", name = "${var.environment}_public_subnet_1" },
    { availability_zone = "us-east-1c", cidr_block = "10.219.32.128/26", name = "${var.environment}_public_subnet_2" },
  ]

  vpc_private_subnets = [
    { availability_zone = "us-east-1a", cidr_block = "10.219.34.0/23", name = "${var.environment}_private_subnet_0" },
    { availability_zone = "us-east-1b", cidr_block = "10.219.36.0/23", name = "${var.environment}_private_subnet_1" },
    { availability_zone = "us-east-1c", cidr_block = "10.219.38.0/23", name = "${var.environment}_private_subnet_2" },
  ]

  vpc_flow_logs = {
    gsirt = {
      log_destination      = "arn:aws:s3:::${var.vpc_flow_logs_bucket}"
      log_destination_type = "s3"
      traffic_type         = "REJECT"
    }
  }
}
