diff --git a/moto/ec2/models/vpc_service_configuration.py b/moto/ec2/models/vpc_service_configuration.py index cccad8d4d..27350b8d6 100644 --- a/moto/ec2/models/vpc_service_configuration.py +++ b/moto/ec2/models/vpc_service_configuration.py @@ -41,6 +41,21 @@ class VPCServiceConfiguration(TaggedEC2Resource, CloudFormationModel): self.principals: List[str] = [] self.ec2_backend = ec2_backend + def to_dict(self) -> Dict[str, Any]: + return { + "AcceptanceRequired": self.acceptance_required, + "AvailabilityZones": self.availability_zones, + "BaseEndpointDnsNames": [self.endpoint_dns_name], + "ManagesVpcEndpoints": self.manages_vpc_endpoints, + "Owner": self.ec2_backend.account_id, + "PrivateDnsName": self.private_dns_name, + "PrivateDnsNames": [{"PrivateDnsName": self.private_dns_name}], + "ServiceId": self.id, + "ServiceName": self.service_name, + "ServiceType": [{"ServiceType": self.service_type}], + "VpcEndpointPolicySupported": True, + } + class VPCServiceConfigurationBackend: def __init__(self) -> None: diff --git a/moto/ec2/models/vpcs.py b/moto/ec2/models/vpcs.py index 43407744a..badb85b19 100644 --- a/moto/ec2/models/vpcs.py +++ b/moto/ec2/models/vpcs.py @@ -845,13 +845,16 @@ class VPCBackend: default_services = self._collect_default_endpoint_services( self.account_id, region # type: ignore[attr-defined] ) + custom_services = [x.to_dict() for x in self.configurations.values()] # type: ignore + all_services = default_services + custom_services + for service_name in service_names: - if service_name not in [x["ServiceName"] for x in default_services]: + if service_name not in [x["ServiceName"] for x in all_services]: raise InvalidServiceName(service_name) # Apply filters specified in the service_names and filters arguments. filtered_services = sorted( - self._filter_endpoint_services(service_names, filters, default_services), + self._filter_endpoint_services(service_names, filters, all_services), key=itemgetter("ServiceName"), ) diff --git a/tests/test_ec2/test_vpc_service_configuration.py b/tests/test_ec2/test_vpc_service_configuration.py index 2881ffff0..80dd07650 100644 --- a/tests/test_ec2/test_vpc_service_configuration.py +++ b/tests/test_ec2/test_vpc_service_configuration.py @@ -3,6 +3,7 @@ import pytest from botocore.exceptions import ClientError from moto import mock_ec2, mock_elbv2 +from moto.core import DEFAULT_ACCOUNT_ID from moto.moto_api._internal import mock_random # See our Development Tips on writing tests for hints on how to write good tests: @@ -101,13 +102,11 @@ def test_create_vpc_endpoint_service_configuration_with_options(): region_name="us-east-2", lb_type="gateway", zone="us-east-1c" ) - resp = client.create_vpc_endpoint_service_configuration( + config = client.create_vpc_endpoint_service_configuration( GatewayLoadBalancerArns=[lb_arn], AcceptanceRequired=False, PrivateDnsName="example.com", - ) - assert "ServiceConfiguration" in resp - config = resp["ServiceConfiguration"] + )["ServiceConfiguration"] assert config["AcceptanceRequired"] is False assert config["PrivateDnsName"] == "example.com" @@ -118,6 +117,13 @@ def test_create_vpc_endpoint_service_configuration_with_options(): "Value": "val", } + service_name = config["ServiceName"] + detail = client.describe_vpc_endpoint_services(ServiceNames=[service_name])[ + "ServiceDetails" + ][0] + assert detail["ServiceName"] == service_name + assert detail["Owner"] == DEFAULT_ACCOUNT_ID + @mock_ec2 @mock_elbv2