Repository: PrefectHQ/prefect

Issue:
Include triggers in output of `deployment inspect`
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

If I have a deployment specification that has a set of triggers those triggers aren't reflected in the output of `prefect deployment inspect`.

### Describe the proposed behavior

`prefect deployment inspect` should include any automations that are owned by the deployment as triggers.

### Example Use

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/cli/deployment.py b/src/prefect/cli/deployment.py
--- a/src/prefect/cli/deployment.py
+++ b/src/prefect/cli/deployment.py
@@ -286,6 +286,14 @@ async def inspect(name: str):
                 exclude={"_block_document_id", "_block_document_name", "_is_anonymous"}
             )
 
+        if client.server_type == ServerType.CLOUD:
+            deployment_json["automations"] = [
+                a.dict()
+                for a in await client.read_resource_related_automations(
+                    f"prefect.deployment.{deployment.id}"
+                )
+            ]
+
     app.console.print(Pretty(deployment_json))
 
 
diff --git a/src/prefect/client/orchestration.py b/src/prefect/client/orchestration.py
--- a/src/prefect/client/orchestration.py
+++ b/src/prefect/client/orchestration.py
@@ -1,3 +1,4 @@
+import asyncio
 import datetime
 import warnings
 from contextlib import AsyncExitStack
@@ -5,7 +6,6 @@
 from uuid import UUID
 
 import httpcore
-import asyncio
 import httpx
 import pendulum
 import pydantic
@@ -18,8 +18,6 @@
 import prefect.states
 from prefect._internal.compatibility.deprecated import deprecated_callable
 from prefect.client.schemas import FlowRun, OrchestrationResult, TaskRun
-from prefect.deprecated.data_documents import DataDocument
-from prefect.logging import get_logger
 from prefect.client.schemas.actions import (
     ArtifactCreate,
     BlockDocumentCreate,
@@ -76,8 +74,8 @@
     TaskRunResult,
     Variable,
     Worker,
-    WorkQueue,
     WorkPool,
+    WorkQueue,
 )
 from prefect.client.schemas.responses import DeploymentResponse, WorkerFlowRunResponse
 from prefect.client.schemas.schedules import SCHEDULE_TYPES
@@ -90,7 +88,9 @@
     LogSort,
     TaskRunSort,
 )
-from prefect.events.schemas import Automation
+from prefect.deprecated.data_documents import DataDocument
+from prefect.events.schemas import Automation, ExistingAutomation
+from prefect.logging import get_logger
 from prefect.settings import (
     PREFECT_API_DATABASE_CONNECTION_URL,
     PREFECT_API_ENABLE_HTTP2,
@@ -2507,6 +2507,16 @@ async def create_automation(self, automation: Automation) -> UUID:
 
         return UUID(response.json()["id"])
 
+    async def read_resource_related_automations(
+        self, resource_id: str
+    ) -> List[ExistingAutomation]:
+        if self.server_type != ServerType.CLOUD:
+            raise RuntimeError("Automations are only supported for Prefect Cloud.")
+
+        response = await self._client.get(f"/automations/related-to/{resource_id}")
+        response.raise_for_status()
+        return pydantic.parse_obj_as(List[ExistingAutomation], response.json())
+
     async def delete_resource_owned_automations(self, resource_id: str):
         if self.server_type != ServerType.CLOUD:
             raise RuntimeError("Automations are only supported for Prefect Cloud.")
diff --git a/src/prefect/events/schemas.py b/src/prefect/events/schemas.py
--- a/src/prefect/events/schemas.py
+++ b/src/prefect/events/schemas.py
@@ -1,6 +1,6 @@
+from datetime import timedelta
 from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Union, cast
 from uuid import UUID, uuid4
-from datetime import timedelta
 
 import pendulum
 from pydantic import Extra, Field, PrivateAttr, root_validator, validator
@@ -12,7 +12,6 @@
 from prefect.events.actions import ActionTypes, RunDeployment
 from prefect.utilities.collections import AutoEnum
 
-
 # These are defined by Prefect Cloud
 MAXIMUM_LABELS_PER_RESOURCE = 500
 MAXIMUM_RELATED_RESOURCES = 500
@@ -276,6 +275,10 @@ class Config:
     )
 
 
+class ExistingAutomation(Automation):
+    id: UUID = Field(..., description="The ID of this automation")
+
+
 @copy_model_fields
 class ResourceTrigger(PrefectBaseModel):
     name: Optional[str] = Field(


Test patch: