/**
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
variable "cidr" {
  description = "vSphere/vSAN subnets CIDR range. To undersatnd the limits, please refer to [GCVE network requirements](https://cloud.google.com/vmware-engine/docs/quickstart-networking-requirements)."
  type        = string
}

variable "description" {
  description = "Private cloud description."
  type        = string
  default     = "Terraform-managed."
}

variable "management_cluster_config" {
  description = "Management cluster configuration."
  type = object({
    node_type_id      = string
    node_count        = number,
    custom_core_count = number
  })
  default = {
    node_type_id      = "standard-72",
    node_count        = 3,
    custom_core_count = null
  }
  nullable = false
}

variable "name" {
  description = "Private cloud name."
  type        = string
}

variable "private_connections" {
  description = "VMWare private connections configuration. It is used to create the gcloud command printed as output."
  type = map(object({
    name                = string
    network_self_link   = string
    peering_name        = optional(string)
    tenant_host_project = optional(string)
    description         = optional(string, "Terraform-managed.")
    type                = optional(string, "PRIVATE_SERVICE_ACCESS")
    routing_mode        = optional(string, "REGIONAL")
  }))
  default  = {}
  nullable = false
  validation {
    condition = alltrue([
      for k, v in var.private_connections :
      (v.peering_name != null) != (v.tenant_host_project != null)
      ]
    )
    error_message = "Both peering_name and tenant_host_project variables have been set. Only one variable is allowed."
  }
  validation {
    condition = alltrue([
      for r in var.private_connections :
      contains(["GLOBAL", "REGIONAL"], r.routing_mode)
    ])
    error_message = "Routing mode must be one of GLOBAL, REGIONAL."
  }
  validation {
    condition = alltrue([
      for r in var.private_connections :
      contains(["DELL_POWERSCALE", "NETAPP_CLOUD_VOLUMES", "PRIVATE_SERVICE_ACCESS", "THIRD_PARTY_SERVICE"], r.type)
    ])
    error_message = "Type must be one of DELL_POWERSCALE, NETAPP_CLOUD_VOLUMES, PRIVATE_SERVICE_ACCESS, THIRD_PARTY_SERVICE."
  }
}

variable "project_id" {
  description = "Project id."
  type        = string
}

variable "vmw_network_create" {
  description = "Create the VMware Engine network. When set to false, it uses a data source to reference an existing VMware Engine network."
  type        = bool
  default     = true
}

variable "vmw_network_description" {
  description = " VMware Engine network description."
  type        = string
  default     = "Terraform-managed."
}

variable "zone" {
  description = "Private cloud zone."
  type        = string
}




