Skip to content
Open
6 changes: 3 additions & 3 deletions src/firebase_functions/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class RuntimeOptions:
to the value "gcf_gen1"
"""

vpc_connector: str | _util.Sentinel | None = None
vpc_connector: str | Expression[str] | _util.Sentinel | None = None
Comment thread
cabljac marked this conversation as resolved.
"""
Connect function to specified VPC connector.
A value of ``RESET_VALUE`` removes the VPC connector.
Expand Down Expand Up @@ -1232,8 +1232,8 @@ def set_global_options(
max_instances: int | Expression[int] | _util.Sentinel | None = None,
concurrency: int | Expression[int] | _util.Sentinel | None = None,
cpu: int | _typing.Literal["gcf_gen1"] | _util.Sentinel = "gcf_gen1",
vpc_connector: str | None = None,
vpc_connector_egress_settings: VpcEgressSetting | None = None,
vpc_connector: str | Expression[str] | _util.Sentinel | None = None,
vpc_connector_egress_settings: VpcEgressSetting | _util.Sentinel | None = None,
service_account: str | _util.Sentinel | None = None,
ingress: IngressSetting | _util.Sentinel | None = None,
labels: dict[str, str] | None = None,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,22 @@ def test_invoker_with_no_element_throws():
AssertionError, match="HttpsOptions: Invalid option for invoker - must be a non-empty list."
):
options.HttpsOptions(invoker=[])._endpoint(func_name="test")


def test_vpc_connector_accepts_string_param():
vpc_param = params.StringParam("VPC_CONNECTOR")

https_options = options.HttpsOptions(vpc_connector=vpc_param)
https_options_dict = https_options._asdict_with_global_options()

# The options dict should contain the CEL string representation for the param.
assert https_options_dict["vpc_connector"] == f"{vpc_param}", (
"vpc_connector param was not converted to CEL string"
)

# The generated endpoint should map the resolved vpc_connector into the vpc block.
endpoint = https_options._endpoint(func_name="test_vpc")
assert endpoint.vpc is not None, "vpc block was not set on endpoint"
assert endpoint.vpc["connector"] == f"{vpc_param}", (
"vpc connector was not set from vpc_connector Expression[str]"
)
Comment thread
HassanBahati marked this conversation as resolved.
Outdated
Loading