terraform {
  required_version = ">= 1.6"
}

variable "subnets" {
  description = "Subnet declarations before normalization."
  type = list(object({
    name   = string
    cidr   = string
    az     = string
    public = optional(bool, false)
    tags   = optional(set(string), [])
  }))
  default = [
    { name = "App-A", cidr = "10.0.1.0/24", az = "az-a", tags = ["app", "shared"] },
    { name = "Web-B", cidr = "10.0.2.0/24", az = "az-b", public = true, tags = ["web"] },
  ]
}

locals {
  normalized_subnets = {
    for subnet in var.subnets : lower(subnet.name) => {
      cidr   = subnet.cidr
      az     = subnet.az
      public = subnet.public
      tags   = sort(tolist(subnet.tags))
    }
  }
}

output "normalized_subnets" {
  value = local.normalized_subnets
}
