variable "team_name" {
  type    = string
  default = "devops"
}

variable "environment" {
  default = "networking"
}

variable "aws_region" {
  default = "us-east-1"
}

variable "application_family" {
  description = "The application family this resource belongs to"
  type        = string
  default     = "devops"
}

variable "peer_account_id" {
  type        = string
  description = "The AWS account ID of the SME Cloudops-managed peer account"
  default     = "358364484590"
}

variable "peer_region" {
  type        = string
  description = "The AWS region of the peer account"
  default     = "us-east-1"
}

variable "peer_transit_gateway_id" {
  type        = string
  description = "The ID of the peer transit gateway"
  default     = "tgw-0c05530bb9c4c4a11"
}

variable "managed_prefix_lists" {
  type = list(object({
    name           = string
    address_family = string
    cidr_blocks    = list(string)
  }))
  default = [
    {
      name           = "sme-internal-reportingdb"
      address_family = "IPv4"
      cidr_blocks    = [
        "10.12.192.0/24", # ReportingDB
      ]
    },
    {
      name           = "sme-internal-tadas"
      address_family = "IPv4"
      cidr_blocks    = [
        "10.250.208.0/24", # Tadas private subnets
        "10.250.209.0/24",
        "10.250.210.0/24",
      ]
    },
    {
      name           = "sme-infosec-vm-network"
      address_family = "IPv4"
      cidr_blocks    = [
        "10.12.222.0/24", # sme-infosec-vm-network
      ]
    },
  ]
}

variable "managed_prefix_list_share_principals" {
  description = "List of principals to share the managed prefix list resource with via RAM"
  default     = [
    "arn:aws:organizations::970903126758:ou/o-bqioddgr91/ou-ax9e-vu43qt3i", # The Orchard OU
    "arn:aws:organizations::970903126758:ou/o-bqioddgr91/ou-ax9e-ouayejxi", # Data Strategy aka GDB OU
  ]
}

variable "managed_prefix_list_vpc_references" {
  type        = map(string)
  description = "A map of prefix list names to VPC names to create routes for in the attachment's route table"
  default = {
    prod-orcd-private-subnet-prefix-list   = "prod"
    qa-orcd-private-subnet-prefix-list     = "prod"
  }
}

locals {
  flattened_resource_share_and_principals_list = [
    for obj in setproduct(values(aws_ram_resource_share.managed_prefix_list_resource_share), var.managed_prefix_list_share_principals) : {
      resource_share_arn = obj[0].arn
      principal          = obj[1]
    }
  ]

  flattened_resource_share_and_principals_list_us_west_2 = [
    for pair in setproduct(keys(aws_ram_resource_share.managed_prefix_list_resource_share_us_west_2), var.managed_prefix_list_share_principals) : {
      key                = "${pair[0]}_${pair[1]}"
      resource_share_arn = aws_ram_resource_share.managed_prefix_list_resource_share_us_west_2[pair[0]].arn
      principal          = pair[1]
    }
  ]
}
