Files
Suryansh Singhal f94033f098 improve configurability and resource references for internal ALB (#3654)
* refactor(net-lb-app-ext): improve configurability and resource references

- Allow overriding names for backend buckets and instance groups
- Add optional per-group description with default value
- Use self_link for instance group backend references
- Fix HTTP proxy name to use http_proxy_config

* reverted the instance group reference in backend service back to id instead of self link

* updated all the lb modules for unmanaged instance groups to have flexible names and proper refactorization of http_proxy_cofig in each module

* removed the description variable

* updated the readme.md for the net-lb-app-ext-regional module

* fixed the linting error for the change in versions.tf

---------

Co-authored-by: Julio Castillo <jccb@google.com>
Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>
2026-01-23 15:35:52 +00:00

205 lines
5.7 KiB
HCL

/**
* 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.
*/
variable "addresses" {
description = "Optional IP address used for the forwarding rule."
type = map(string)
default = null
}
variable "description" {
description = "Optional description used for resources."
type = string
default = "Terraform managed."
}
variable "group_configs" {
description = "Optional unmanaged groups to create. Can be referenced in backends via key or outputs."
type = map(object({
name = optional(string)
description = optional(string, "Terraform managed.")
zone = string
instances = optional(list(string))
named_ports = optional(map(number), {})
project_id = optional(string)
}))
default = {}
nullable = false
}
variable "http_proxy_config" {
description = "HTTP proxy configuration."
type = object({
name = optional(string)
description = optional(string, "Terraform managed.")
http_keepalive_timeout = optional(string)
})
default = {}
nullable = false
}
variable "https_proxy_config" {
description = "HTTPS proxy configuration."
type = object({
name = optional(string)
description = optional(string, "Terraform managed.")
certificate_manager_certificates = optional(list(string), [])
http_keepalive_timeout = optional(string)
quic_override = optional(string)
ssl_policy = optional(string)
})
default = {}
nullable = false
}
variable "labels" {
description = "Labels set on resources."
type = map(string)
default = {}
}
variable "name" {
description = "Load balancer name."
type = string
}
variable "neg_configs" {
description = "Optional network endpoint groups to create. Can be referenced in backends via key or outputs."
type = map(object({
project_id = optional(string)
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)
network = optional(string)
subnetwork = optional(string)
endpoints = optional(map(object({
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)
endpoints = optional(map(object({
ip_address = string
port = number
})))
}))
psc = optional(object({
region = string
target_service = string
network = optional(string)
subnetwork = optional(string)
}))
}))
default = {}
nullable = false
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) +
(try(v.psc, 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."
}
}
variable "ports" {
description = "Optional ports for HTTP load balancer."
type = list(string)
default = null
validation {
condition = length(coalesce(var.ports, [])) <= 1
error_message = "Application Load Balancer supports at most one port per forwarding rule."
}
}
variable "project_id" {
description = "Project id."
type = string
}
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"
}
}
variable "service_attachment" {
description = "PSC service attachments."
type = object({
automatic_connection = optional(bool, false)
consumer_accept_lists = optional(map(string), {})
consumer_reject_lists = optional(list(string))
description = optional(string)
domain_name = optional(map(string))
enable_proxy_protocol = optional(bool, false)
nat_subnets = map(list(string))
reconcile_connections = optional(bool)
})
default = null
}
variable "service_directory_registration" {
description = "Service directory namespace and service used to register this load balancer."
type = object({
namespace = string
service_directory_region = string
})
default = null
}
variable "vpc_config" {
description = "VPC-level configuration."
type = object({
network = string
subnetworks = map(string)
})
nullable = false
}