2022-04-04 23:58:55 -07:00
|
|
|
/**
|
|
|
|
* Copyright 2022 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.
|
|
|
|
*/
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "address" {
|
|
|
|
description = "Optional IP address used for the forwarding rule."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = string
|
2022-11-14 05:39:00 -08:00
|
|
|
default = null
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "description" {
|
|
|
|
description = "Optional description used for resources."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = string
|
2022-11-14 05:39:00 -08:00
|
|
|
default = "Terraform managed."
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-18 00:48:41 -08:00
|
|
|
# during the preview phase you cannot change this attribute on an existing rule
|
|
|
|
variable "global_access" {
|
|
|
|
description = "Allow client access from all regions."
|
|
|
|
type = bool
|
|
|
|
default = null
|
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "group_configs" {
|
|
|
|
description = "Optional unmanaged groups to create. Can be referenced in backends via key or outputs."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = map(object({
|
2022-11-14 05:39:00 -08:00
|
|
|
zone = string
|
|
|
|
instances = optional(list(string), [])
|
|
|
|
named_ports = optional(map(number), {})
|
2022-11-18 00:48:41 -08:00
|
|
|
project_id = optional(string)
|
2022-04-04 23:58:55 -07:00
|
|
|
}))
|
2022-11-14 05:39:00 -08:00
|
|
|
default = {}
|
|
|
|
nullable = false
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "labels" {
|
|
|
|
description = "Labels set on resources."
|
|
|
|
type = map(string)
|
|
|
|
default = {}
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "name" {
|
|
|
|
description = "Load balancer name."
|
|
|
|
type = string
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "neg_configs" {
|
|
|
|
description = "Optional network endpoint groups to create. Can be referenced in backends via key or outputs."
|
|
|
|
type = map(object({
|
2022-11-18 00:48:41 -08:00
|
|
|
project_id = optional(string)
|
2022-11-16 05:14:05 -08:00
|
|
|
cloudrun = optional(object({
|
|
|
|
region = string
|
|
|
|
target_service = optional(object({
|
|
|
|
name = string
|
|
|
|
tag = optional(string)
|
|
|
|
}))
|
|
|
|
target_urlmask = optional(string)
|
|
|
|
}))
|
|
|
|
gce = optional(object({
|
|
|
|
zone = string
|
|
|
|
# default_port = optional(number)
|
2022-11-14 05:39:00 -08:00
|
|
|
network = optional(string)
|
|
|
|
subnetwork = optional(string)
|
2022-12-21 08:04:56 -08:00
|
|
|
endpoints = optional(map(object({
|
2022-11-16 05:14:05 -08:00
|
|
|
instance = string
|
|
|
|
ip_address = string
|
|
|
|
port = number
|
|
|
|
})))
|
|
|
|
|
|
|
|
}))
|
|
|
|
hybrid = optional(object({
|
|
|
|
zone = string
|
|
|
|
network = optional(string)
|
|
|
|
# re-enable once provider properly support this
|
|
|
|
# default_port = optional(number)
|
2022-12-21 08:04:56 -08:00
|
|
|
endpoints = optional(map(object({
|
2022-11-16 05:14:05 -08:00
|
|
|
ip_address = string
|
|
|
|
port = number
|
|
|
|
})))
|
2022-11-14 05:39:00 -08:00
|
|
|
}))
|
2022-11-16 05:14:05 -08:00
|
|
|
# psc = optional(object({}))
|
2022-11-14 05:39:00 -08:00
|
|
|
}))
|
|
|
|
default = {}
|
|
|
|
nullable = false
|
2022-11-16 05:14:05 -08:00
|
|
|
validation {
|
|
|
|
condition = alltrue([
|
|
|
|
for k, v in var.neg_configs : (
|
|
|
|
(try(v.cloudrun, null) == null ? 0 : 1) +
|
|
|
|
(try(v.gce, null) == null ? 0 : 1) +
|
|
|
|
(try(v.hybrid, null) == null ? 0 : 1) == 1
|
|
|
|
)
|
|
|
|
])
|
|
|
|
error_message = "Only one type of neg can be configured at a time."
|
|
|
|
}
|
|
|
|
validation {
|
|
|
|
condition = alltrue([
|
|
|
|
for k, v in var.neg_configs : (
|
|
|
|
v.cloudrun == null
|
|
|
|
? true
|
|
|
|
: v.cloudrun.target_urlmask != null || v.cloudrun.target_service != null
|
|
|
|
)
|
|
|
|
])
|
|
|
|
error_message = "Cloud Run negs need either target type or target urlmask defined."
|
|
|
|
}
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "network_tier_premium" {
|
|
|
|
description = "Use premium network tier. Defaults to true."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = bool
|
2022-11-14 05:39:00 -08:00
|
|
|
default = true
|
|
|
|
nullable = false
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "ports" {
|
|
|
|
description = "Optional ports for HTTP load balancer, valid ports are 80 and 8080."
|
|
|
|
type = list(string)
|
|
|
|
default = null
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-19 03:38:37 -08:00
|
|
|
variable "project_id" {
|
|
|
|
description = "Project id."
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "protocol" {
|
|
|
|
description = "Protocol supported by this load balancer."
|
|
|
|
type = string
|
|
|
|
default = "HTTP"
|
|
|
|
nullable = false
|
|
|
|
validation {
|
|
|
|
condition = (
|
|
|
|
var.protocol == null || var.protocol == "HTTP" || var.protocol == "HTTPS"
|
|
|
|
)
|
|
|
|
error_message = "Protocol must be HTTP or HTTPS"
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "region" {
|
|
|
|
description = "The region where to allocate the ILB resources."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
2022-11-18 00:48:41 -08:00
|
|
|
variable "service_directory_registration" {
|
|
|
|
description = "Service directory namespace and service used to register this load balancer."
|
|
|
|
type = object({
|
|
|
|
namespace = string
|
|
|
|
service = string
|
|
|
|
})
|
|
|
|
default = null
|
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "ssl_certificates" {
|
|
|
|
description = "SSL target proxy certificates (only if protocol is HTTPS)."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = object({
|
2022-11-14 05:39:00 -08:00
|
|
|
certificate_ids = optional(list(string), [])
|
|
|
|
create_configs = optional(map(object({
|
|
|
|
certificate = string
|
|
|
|
private_key = string
|
|
|
|
})), {})
|
2022-04-04 23:58:55 -07:00
|
|
|
})
|
2022-11-14 05:39:00 -08:00
|
|
|
default = {}
|
|
|
|
nullable = false
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|
|
|
|
|
2022-11-14 05:39:00 -08:00
|
|
|
variable "vpc_config" {
|
|
|
|
description = "VPC-level configuration."
|
2022-04-04 23:58:55 -07:00
|
|
|
type = object({
|
2022-11-14 05:39:00 -08:00
|
|
|
network = string
|
|
|
|
subnetwork = string
|
2022-04-04 23:58:55 -07:00
|
|
|
})
|
2022-11-14 05:39:00 -08:00
|
|
|
nullable = false
|
2022-04-04 23:58:55 -07:00
|
|
|
}
|