@@ -58,6 +58,29 @@ def __str__(self) -> str:
5858 return self .value
5959
6060
61+ @_dataclasses .dataclass (frozen = True )
62+ class NetworkInterface :
63+ """
64+ Interface for a direct VPC network connection.
65+ At least one of ``network`` or ``subnetwork`` must be specified.
66+ """
67+
68+ network : str | Expression [str ] | _util .Sentinel | None = None
69+ """
70+ Network to use for Direct VPC Egress.
71+ """
72+
73+ subnetwork : str | Expression [str ] | _util .Sentinel | None = None
74+ """
75+ Subnetwork to use for Direct VPC Egress.
76+ """
77+
78+ tags : str | list [str ] | Expression [str ] | Expression [list ] | _util .Sentinel | None = None
79+ """
80+ Optional tags to apply to Direct VPC Egress traffic.
81+ """
82+
83+
6184@_dataclasses .dataclass (frozen = True )
6285class CorsOptions :
6386 """
@@ -257,6 +280,7 @@ class RuntimeOptions:
257280 vpc_connector : str | _util .Sentinel | None = None
258281 """
259282 Connect function to specified VPC connector.
283+ Mutually exclusive with ``network_interface``.
260284 A value of ``RESET_VALUE`` removes the VPC connector.
261285 """
262286
@@ -266,6 +290,18 @@ class RuntimeOptions:
266290 A value of ``RESET_VALUE`` turns off VPC connector egress settings.
267291 """
268292
293+ vpc_egress : VpcEgressSetting | _util .Sentinel | None = None
294+ """
295+ Alias for ``vpc_connector_egress_settings``.
296+ """
297+
298+ network_interface : NetworkInterface | _util .Sentinel | None = None
299+ """
300+ Direct VPC Egress network interface settings.
301+ Mutually exclusive with ``vpc_connector``.
302+ A value of ``RESET_VALUE`` removes Direct VPC Egress settings.
303+ """
304+
269305 service_account : str | _util .Sentinel | None = None
270306 """
271307 Specific service account for the function to run as.
@@ -339,6 +375,8 @@ def _asdict_with_global_options(self) -> dict:
339375 "service_account" ,
340376 "vpc_connector" ,
341377 "vpc_connector_egress_settings" ,
378+ "vpc_egress" ,
379+ "network_interface" ,
342380 ]
343381 if not preserve_external_changes :
344382 for option in resettable_options :
@@ -380,18 +418,76 @@ def convert_secret(secret) -> _manifest.SecretEnvironmentVariable:
380418 elif options .region is not None :
381419 region = [_typing .cast (str , options .region )]
382420
383- vpc : _manifest .VpcSettings | None = None
384- if isinstance (options .vpc_connector , str ):
385- vpc = (
386- {
387- "connector" : options .vpc_connector ,
388- "egressSettings" : options .vpc_connector_egress_settings .value
389- if isinstance (options .vpc_connector_egress_settings , VpcEgressSetting )
390- else options .vpc_connector_egress_settings ,
391- }
392- if options .vpc_connector_egress_settings is not None
393- else {"connector" : options .vpc_connector }
394- )
421+ vpc : _manifest .VpcSettings | _util .Sentinel | None = None
422+ vpc_egress = options .vpc_connector_egress_settings
423+ if options .vpc_egress is not None and (
424+ not isinstance (options .vpc_egress , _util .Sentinel ) or vpc_egress is None
425+ ):
426+ vpc_egress = options .vpc_egress
427+
428+ connector = options .vpc_connector
429+ has_connector = isinstance (connector , str )
430+ reset_connector = isinstance (connector , _util .Sentinel )
431+
432+ raw_network_interface = options_dict .get ("network_interface" )
433+ has_network_interface = isinstance (raw_network_interface , dict )
434+ reset_network_interface = isinstance (raw_network_interface , _util .Sentinel )
435+
436+ if has_network_interface :
437+ network_interface_dict = _typing .cast (dict [str , object ], raw_network_interface )
438+ if (
439+ network_interface_dict .get ("network" ) is None
440+ and network_interface_dict .get ("subnetwork" ) is None
441+ ):
442+ raise ValueError (
443+ "At least one of network or subnetwork must be specified in network_interface."
444+ )
445+
446+ if has_connector and has_network_interface :
447+ raise ValueError ("Cannot set both vpc_connector and network_interface" )
448+
449+ if (
450+ has_connector
451+ or vpc_egress is not None
452+ or has_network_interface
453+ or reset_connector
454+ or reset_network_interface
455+ ):
456+ if (reset_connector and not has_network_interface ) or (
457+ reset_network_interface and not has_connector
458+ ):
459+ vpc = RESET_VALUE
460+ else :
461+ vpc = {}
462+ if has_connector :
463+ vpc ["connector" ] = _typing .cast (str , connector )
464+ if vpc_egress is not None :
465+ vpc ["egressSettings" ] = (
466+ vpc_egress .value if isinstance (vpc_egress , VpcEgressSetting ) else vpc_egress
467+ )
468+ if has_network_interface :
469+ network_interface_dict = _typing .cast (dict [str , object ], raw_network_interface )
470+ network_interface_spec : _manifest .VpcNetworkInterface = {}
471+ if network_interface_dict .get ("network" ) is not None :
472+ network_interface_spec ["network" ] = _typing .cast (
473+ str | Expression [str ] | _util .Sentinel ,
474+ network_interface_dict ["network" ],
475+ )
476+ if network_interface_dict .get ("subnetwork" ) is not None :
477+ network_interface_spec ["subnetwork" ] = _typing .cast (
478+ str | Expression [str ] | _util .Sentinel ,
479+ network_interface_dict ["subnetwork" ],
480+ )
481+ if network_interface_dict .get ("tags" ) is not None :
482+ network_interface_spec ["tags" ] = _typing .cast (
483+ str
484+ | list [str ]
485+ | Expression [str ]
486+ | Expression [list ]
487+ | _util .Sentinel ,
488+ network_interface_dict ["tags" ],
489+ )
490+ vpc ["networkInterfaces" ] = [network_interface_spec ]
395491
396492 endpoint = _manifest .ManifestEndpoint (
397493 entryPoint = kwargs ["func_name" ],
@@ -1254,8 +1350,10 @@ def set_global_options(
12541350 max_instances : int | Expression [int ] | _util .Sentinel | None = None ,
12551351 concurrency : int | Expression [int ] | _util .Sentinel | None = None ,
12561352 cpu : int | _typing .Literal ["gcf_gen1" ] | _util .Sentinel = "gcf_gen1" ,
1257- vpc_connector : str | None = None ,
1258- vpc_connector_egress_settings : VpcEgressSetting | None = None ,
1353+ vpc_connector : str | _util .Sentinel | None = None ,
1354+ vpc_connector_egress_settings : VpcEgressSetting | _util .Sentinel | None = None ,
1355+ vpc_egress : VpcEgressSetting | _util .Sentinel | None = None ,
1356+ network_interface : NetworkInterface | _util .Sentinel | None = None ,
12591357 service_account : str | _util .Sentinel | None = None ,
12601358 ingress : IngressSetting | _util .Sentinel | None = None ,
12611359 labels : dict [str , str ] | None = None ,
@@ -1277,6 +1375,8 @@ def set_global_options(
12771375 cpu = cpu ,
12781376 vpc_connector = vpc_connector ,
12791377 vpc_connector_egress_settings = vpc_connector_egress_settings ,
1378+ vpc_egress = vpc_egress ,
1379+ network_interface = network_interface ,
12801380 service_account = service_account ,
12811381 ingress = ingress ,
12821382 labels = labels ,
0 commit comments