@@ -238,8 +238,10 @@ locals {
238238 }
239239 } : {}
240240
241- # HTTPRoute Resources (HTTPS traffic - port 443)
241+ # HTTPRoute Resources (HTTPS traffic - port 443, and HTTP - port 80 when force_ssl_redirection is disabled )
242242 # Note: GatewayClass, Gateway, and NginxProxy are created by the Helm chart
243+ force_ssl_redirection = lookup (var. instance . spec , " force_ssl_redirection" , false )
244+
243245 httproute_resources = {
244246 for k , v in local . rulesFiltered : " httproute-${ lower (var. instance_name )} -${ k } " => {
245247 apiVersion = " gateway.networking.k8s.io/v1"
@@ -252,21 +254,30 @@ locals {
252254 # Reference the correct listener(s) for this route's hostnames
253255 # If route has domain_prefix, reference the additional hostname listeners
254256 # If route has no domain_prefix, reference the base domain listeners
255- parentRefs = lookup (v, " domain_prefix" , null ) == null || lookup (v, " domain_prefix" , null ) == " " ? [
256- # No domain_prefix - use base domain listeners
257- for domain_key , domain in local . domains : {
258- name = local.name
259- namespace = var.environment.namespace
260- sectionName = " https-${ domain_key } "
261- }
262- ] : [
263- # Has domain_prefix - use additional hostname listeners
264- for domain_key , domain in local . domains : {
257+ # When force_ssl_redirection is disabled, also attach to HTTP listener so traffic is served on port 80
258+ parentRefs = concat (
259+ lookup (v, " domain_prefix" , null ) == null || lookup (v, " domain_prefix" , null ) == " " ? [
260+ # No domain_prefix - use base domain listeners
261+ for domain_key , domain in local . domains : {
262+ name = local . name
263+ namespace = var . environment . namespace
264+ sectionName = " https-${ domain_key } "
265+ }
266+ ] : [
267+ # Has domain_prefix - use additional hostname listeners
268+ for domain_key , domain in local . domains : {
269+ name = local . name
270+ namespace = var . environment . namespace
271+ sectionName = " https-${ replace (replace (" ${ lookup (v, " domain_prefix" , null )} .${ domain . domain } " , " ." , " -" ), " *" , " wildcard" )} "
272+ }
273+ ],
274+ # Also attach to HTTP listener when SSL redirection is disabled
275+ ! local. force_ssl_redirection ? [{
265276 name = local.name
266277 namespace = var.environment.namespace
267- sectionName = " https- ${ replace ( replace ( " ${ lookup (v, " domain_prefix " , null ) } . ${ domain . domain } " , " . " , " - " ), " * " , " wildcard " ) } "
268- }
269- ]
278+ sectionName = " http "
279+ }] : []
280+ )
270281
271282 # Include all domains in hostnames - Gateway API supports multiple hostnames per route
272283 hostnames = distinct ([
@@ -441,21 +452,30 @@ locals {
441452 # Reference the correct listener(s) for this route's hostnames
442453 # If route has domain_prefix, reference the additional hostname listeners
443454 # If route has no domain_prefix, reference the base domain listeners
444- parentRefs = lookup (v, " domain_prefix" , null ) == null || lookup (v, " domain_prefix" , null ) == " " ? [
445- # No domain_prefix - use base domain listeners
446- for domain_key , domain in local . domains : {
447- name = local.name
448- namespace = var.environment.namespace
449- sectionName = " https-${ domain_key } "
450- }
451- ] : [
452- # Has domain_prefix - use additional hostname listeners
453- for domain_key , domain in local . domains : {
455+ # When force_ssl_redirection is disabled, also attach to HTTP listener
456+ parentRefs = concat (
457+ lookup (v, " domain_prefix" , null ) == null || lookup (v, " domain_prefix" , null ) == " " ? [
458+ # No domain_prefix - use base domain listeners
459+ for domain_key , domain in local . domains : {
460+ name = local . name
461+ namespace = var . environment . namespace
462+ sectionName = " https-${ domain_key } "
463+ }
464+ ] : [
465+ # Has domain_prefix - use additional hostname listeners
466+ for domain_key , domain in local . domains : {
467+ name = local . name
468+ namespace = var . environment . namespace
469+ sectionName = " https-${ replace (replace (" ${ lookup (v, " domain_prefix" , null )} .${ domain . domain } " , " ." , " -" ), " *" , " wildcard" )} "
470+ }
471+ ],
472+ # Also attach to HTTP listener when SSL redirection is disabled
473+ ! local. force_ssl_redirection ? [{
454474 name = local.name
455475 namespace = var.environment.namespace
456- sectionName = " https- ${ replace ( replace ( " ${ lookup (v, " domain_prefix " , null ) } . ${ domain . domain } " , " . " , " - " ), " * " , " wildcard " ) } "
457- }
458- ]
476+ sectionName = " http "
477+ }] : []
478+ )
459479
460480 # Include all domains in hostnames - Gateway API supports multiple hostnames per route
461481 hostnames = distinct ([
0 commit comments