|
51 | 51 | }
|
52 | 52 | )
|
53 | 53 |
|
| 54 | +# https://cloud.google.com/functions/docs/reference/rest/v2/projects.locations.functions#vpconnectoregresssettings |
| 55 | +_VPC_EGRESS_SETTINGS_MAP = types.MappingProxyType( |
| 56 | + { |
| 57 | + "all": functions_v2.ServiceConfig.VpcConnectorEgressSettings.ALL_TRAFFIC, |
| 58 | + "private-ranges-only": functions_v2.ServiceConfig.VpcConnectorEgressSettings.PRIVATE_RANGES_ONLY, |
| 59 | + "unspecified": functions_v2.ServiceConfig.VpcConnectorEgressSettings.VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED, |
| 60 | + } |
| 61 | +) |
| 62 | + |
54 | 63 | # BQ managed functions (@udf) currently only support Python 3.11.
|
55 | 64 | _MANAGED_FUNC_PYTHON_VERSION = "python-3.11"
|
56 | 65 |
|
@@ -375,6 +384,7 @@ def create_cloud_function(
|
375 | 384 | max_instance_count=None,
|
376 | 385 | is_row_processor=False,
|
377 | 386 | vpc_connector=None,
|
| 387 | + vpc_connector_egress_settings="private-ranges-only", |
378 | 388 | memory_mib=1024,
|
379 | 389 | ingress_settings="internal-only",
|
380 | 390 | ):
|
@@ -472,6 +482,15 @@ def create_cloud_function(
|
472 | 482 | function.service_config.max_instance_count = max_instance_count
|
473 | 483 | if vpc_connector is not None:
|
474 | 484 | function.service_config.vpc_connector = vpc_connector
|
| 485 | + if vpc_connector_egress_settings not in _VPC_EGRESS_SETTINGS_MAP: |
| 486 | + raise bf_formatting.create_exception_with_feedback_link( |
| 487 | + ValueError, |
| 488 | + f"'{vpc_connector_egress_settings}' not one of the supported vpc egress settings values: {list(_VPC_EGRESS_SETTINGS_MAP)}", |
| 489 | + ) |
| 490 | + function.service_config.vpc_connector_egress_settings = cast( |
| 491 | + functions_v2.ServiceConfig.VpcConnectorEgressSettings, |
| 492 | + _VPC_EGRESS_SETTINGS_MAP[vpc_connector_egress_settings], |
| 493 | + ) |
475 | 494 | function.service_config.service_account_email = (
|
476 | 495 | self._cloud_function_service_account
|
477 | 496 | )
|
@@ -532,6 +551,7 @@ def provision_bq_remote_function(
|
532 | 551 | cloud_function_max_instance_count,
|
533 | 552 | is_row_processor,
|
534 | 553 | cloud_function_vpc_connector,
|
| 554 | + cloud_function_vpc_connector_egress_settings, |
535 | 555 | cloud_function_memory_mib,
|
536 | 556 | cloud_function_ingress_settings,
|
537 | 557 | bq_metadata,
|
@@ -580,6 +600,7 @@ def provision_bq_remote_function(
|
580 | 600 | max_instance_count=cloud_function_max_instance_count,
|
581 | 601 | is_row_processor=is_row_processor,
|
582 | 602 | vpc_connector=cloud_function_vpc_connector,
|
| 603 | + vpc_connector_egress_settings=cloud_function_vpc_connector_egress_settings, |
583 | 604 | memory_mib=cloud_function_memory_mib,
|
584 | 605 | ingress_settings=cloud_function_ingress_settings,
|
585 | 606 | )
|
|
0 commit comments