Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deployment): add basic Deployment resource #202

Merged
merged 86 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4fb7752
added main scaffolding to support deployments
skyscrapr Mar 16, 2024
0b99d2f
add support for flows
skyscrapr Mar 17, 2024
770c634
fixup flows
skyscrapr Mar 28, 2024
5d479ec
fixup deployments
skyscrapr Mar 28, 2024
01b492e
add support for deployment access
skyscrapr Apr 14, 2024
9de2dc3
set required attributes
skyscrapr Apr 14, 2024
ca050bd
add support for deployment access
skyscrapr Apr 17, 2024
2a15607
fix flow import
skyscrapr Apr 18, 2024
6692f7b
fix imports for workspace resources
skyscrapr Apr 18, 2024
ee6a510
added main scaffolding to support deployments
skyscrapr Mar 16, 2024
8697512
add support for flows
skyscrapr Mar 17, 2024
67d33d9
fixup flows
skyscrapr Mar 28, 2024
688f5de
fixup deployments
skyscrapr Mar 28, 2024
bcb37cd
add support for deployment access
skyscrapr Apr 14, 2024
c7b0516
set required attributes
skyscrapr Apr 14, 2024
820d787
add support for deployment access
skyscrapr Apr 17, 2024
90e35d5
fix flow import
skyscrapr Apr 18, 2024
e18947f
fix imports for workspace resources
skyscrapr Apr 18, 2024
21dfe8f
Merge branch 'deployment_access' of https://github.com/skyscrapr/terr…
skyscrapr Apr 20, 2024
eac0e33
fixup tests to avoid hardcoding
skyscrapr Apr 22, 2024
fbbcbef
tidy up
skyscrapr Jun 7, 2024
5cea771
remove deployments
skyscrapr Jun 7, 2024
5268368
remove deployments
skyscrapr Jun 7, 2024
dc2581a
updates from PR review
skyscrapr Jun 12, 2024
2c2200a
revert change to test name prefix
skyscrapr Jun 13, 2024
8507fd7
updated flow resource to force recreation on change of tags
skyscrapr Jun 14, 2024
e6531e5
Update internal/client/flows.go
skyscrapr Jun 17, 2024
28c547d
Update internal/provider/resources/flow.go
skyscrapr Jun 17, 2024
01e74c5
Update internal/client/flows.go
skyscrapr Jun 17, 2024
5bc2b7b
Update internal/provider/resources/flow.go
skyscrapr Jun 17, 2024
fb41570
Update internal/provider/resources/flow_test.go
skyscrapr Jun 17, 2024
d1d084b
Update internal/provider/resources/flow.go
skyscrapr Jun 17, 2024
67c28f4
change model to state as per PR review
skyscrapr Jun 17, 2024
aff6f05
change model variable to plan as per PR review
skyscrapr Jun 17, 2024
26cc208
tidyup import logic
skyscrapr Jun 17, 2024
385ba6b
add prefect_flow examples
skyscrapr Jun 17, 2024
5a70f27
add prefect_flow examples
skyscrapr Jun 17, 2024
6915447
modify import logic as suggested in PR review
skyscrapr Jun 18, 2024
cb930ee
modify import logic as suggested in PR review
skyscrapr Jun 18, 2024
ec91f61
update docs for flow import
skyscrapr Jun 18, 2024
c11205d
Update internal/provider/resources/flow.go
skyscrapr Jun 21, 2024
7f75a54
Update internal/provider/resources/flow.go
skyscrapr Jun 21, 2024
133382a
add support for deployment resource
skyscrapr Jun 23, 2024
5c36cc0
tidy up some varible names and comments
skyscrapr Jun 23, 2024
4d2b088
regenerate docs
skyscrapr Jun 23, 2024
8f73df8
fixup import for deployments
skyscrapr Jun 23, 2024
658d023
add deployment resource examples
skyscrapr Jun 24, 2024
57b0f65
fixup typo in flow resrource example
skyscrapr Jun 24, 2024
69e8413
regenerate docs
skyscrapr Jun 24, 2024
3a8e114
tidy up some code
skyscrapr Jun 24, 2024
bb9f43e
Merge branch 'main' of github.com:PrefectHQ/terraform-provider-prefec…
mitchnielsen Jul 23, 2024
f009c69
Address pre-commit suggestions
mitchnielsen Jul 23, 2024
35962ab
Fix indentation on Deployment resource example
mitchnielsen Jul 23, 2024
8c47a6e
Apply some fixes to the Deployment schema
mitchnielsen Jul 26, 2024
4baaeb2
Remove 'status' field
mitchnielsen Jul 30, 2024
22b8e29
Remove comments for un-implemented fields
mitchnielsen Jul 30, 2024
8283331
Re-enable commented fields in copy to model
mitchnielsen Jul 30, 2024
5443ebe
Remove IsScheduleActive (deprecated)
mitchnielsen Jul 30, 2024
33c6f25
Remove document-id-related fields for now
mitchnielsen Jul 30, 2024
8a1fa4a
Consistent field formatting and implementation
mitchnielsen Jul 30, 2024
1babc2c
Fix Update method's comment and signature
mitchnielsen Jul 30, 2024
204926c
Apply fixes to schema attribute properties
mitchnielsen Jul 30, 2024
3ca6e2e
Finish implementing ManifestPath
mitchnielsen Jul 30, 2024
9c1fc11
Sort struct keys alphabetically
mitchnielsen Jul 30, 2024
2529e0a
Clean up import state functionality
mitchnielsen Jul 31, 2024
9058abf
Add more fields to Deployment example
mitchnielsen Jul 31, 2024
f6919e9
Clean up Deployment tests
mitchnielsen Jul 31, 2024
48270f8
Fix attributes on test deployment
mitchnielsen Jul 31, 2024
2345f70
Reference an existing work pool
mitchnielsen Aug 1, 2024
f91be37
Use ephemeral workspace for deployment test
mitchnielsen Aug 1, 2024
96c5203
Configure dependency on workspace and flow
mitchnielsen Aug 1, 2024
0e31c45
Disable Deployment Update test for now
mitchnielsen Aug 1, 2024
fa74d90
Fix arg to GetResourceWorkspaceImportStateID
mitchnielsen Aug 1, 2024
df8a873
Fix order of accountid, workspaceid args
mitchnielsen Aug 13, 2024
1425442
Remove unsupported 'name' from DeploymentUpdate
mitchnielsen Aug 13, 2024
9cb794b
Re-enable Deployment update tests
mitchnielsen Aug 13, 2024
88d17d8
Use template for TF manifest, test all fields
mitchnielsen Aug 14, 2024
89f3b22
Use evergreen workspace for now
mitchnielsen Aug 14, 2024
f2e0ea9
Test work pool and queue names
mitchnielsen Aug 14, 2024
c9b2c1b
Generate Terraform Docs
github-actions[bot] Aug 14, 2024
7cd1944
Rename example work pool name
mitchnielsen Aug 14, 2024
e7d84be
Generate Terraform Docs
github-actions[bot] Aug 14, 2024
265a7cf
Merge branch 'main' of github.com:PrefectHQ/terraform-provider-prefec…
mitchnielsen Aug 14, 2024
f744c5a
Merge branch 'main' into resource_deployment
parkedwards Aug 14, 2024
b2f7309
Fix Get method comment
mitchnielsen Aug 15, 2024
a3258a2
Fix deployment name in example
mitchnielsen Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions docs/resources/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "prefect_deployment Resource - prefect"
subcategory: ""
description: |-
Deployments are server-side representations of flows. They store the crucial metadata needed for remote orchestration including when, where, and how a workflow should run. Deployments elevate workflows from functions that you must call manually to API-managed entities that can be triggered remotely.
---

# prefect_deployment (Resource)

Deployments are server-side representations of flows. They store the crucial metadata needed for remote orchestration including when, where, and how a workflow should run. Deployments elevate workflows from functions that you must call manually to API-managed entities that can be triggered remotely.

## Example Usage

```terraform
resource "prefect_workspace" "workspace" {
handle = "my-workspace"
name = "my-workspace"
}

resource "prefect_flow" "flow" {
name = "my-flow"
workspace_id = prefect_workspace.workspace.id
tags = ["tf-test"]
}

resource "prefect_deployment" "deployment" {
name = "%s"
description = "string"
workspace_id = prefect_workspace.workspace.id
flow_id = prefect_flow.flow.id
entrypoint = "hello_world.py:hello_world"
tags = ["test"]
enforce_parameter_schema = false
manifest_path = "./bar/foo"
path = "./foo/bar"
paused = false
version = "v1.1.1"
work_pool_name = "mitch-testing-pool"
work_queue_name = "default"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `flow_id` (String) Flow ID (UUID) to associate deployment to
- `name` (String) Name of the workspace

### Optional

- `account_id` (String) Account ID (UUID), defaults to the account set in the provider
- `description` (String) A description for the deployment.
- `enforce_parameter_schema` (Boolean) Whether or not the deployment should enforce the parameter schema.
- `entrypoint` (String) The path to the entrypoint for the workflow, relative to the path.
- `manifest_path` (String) The path to the flow's manifest file, relative to the chosen storage.
- `path` (String) The path to the working directory for the workflow, relative to remote storage or an absolute path.
- `paused` (Boolean) Whether or not the deployment is paused.
- `tags` (List of String) Tags associated with the deployment
- `version` (String) An optional version for the deployment.
- `work_pool_name` (String) The name of the deployment's work pool.
- `work_queue_name` (String) The work queue for the deployment. If no work queue is set, work will not be scheduled.
- `workspace_id` (String) Workspace ID (UUID) to associate deployment to

### Read-Only

- `created` (String) Timestamp of when the resource was created (RFC3339)
- `id` (String) Workspace ID (UUID)
- `updated` (String) Timestamp of when the resource was updated (RFC3339)

## Import

Import is supported using the following syntax:

```shell
# Prefect Deployments can be imported via deployment_id
terraform import prefect_deployment.example 00000000-0000-0000-0000-000000000000

# or via deployment_id,workspace_id
terraform import prefect_deployment.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
```
2 changes: 1 addition & 1 deletion docs/resources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ Import is supported using the following syntax:

```shell
# Prefect Flows can be imported via flow_id,workspace_id
terraform import prefect_variable.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
terraform import prefect_flow.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
mitchnielsen marked this conversation as resolved.
Show resolved Hide resolved
```
5 changes: 5 additions & 0 deletions examples/resources/prefect_deployment/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Prefect Deployments can be imported via deployment_id
terraform import prefect_deployment.example 00000000-0000-0000-0000-000000000000

# or via deployment_id,workspace_id
terraform import prefect_deployment.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
27 changes: 27 additions & 0 deletions examples/resources/prefect_deployment/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "prefect_workspace" "workspace" {
handle = "my-workspace"
name = "my-workspace"
}

resource "prefect_flow" "flow" {
name = "my-flow"
workspace_id = prefect_workspace.workspace.id
tags = ["tf-test"]
}

resource "prefect_deployment" "deployment" {
name = "my-deployment"
description = "string"
workspace_id = prefect_workspace.workspace.id
flow_id = prefect_flow.flow.id
entrypoint = "hello_world.py:hello_world"
tags = ["test"]
enforce_parameter_schema = false
manifest_path = "./bar/foo"
path = "./foo/bar"
paused = false
version = "v1.1.1"
work_pool_name = "mitch-testing-pool"
work_queue_name = "default"
}

2 changes: 1 addition & 1 deletion examples/resources/prefect_flow/import.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Prefect Flows can be imported via flow_id,workspace_id
terraform import prefect_variable.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
terraform import prefect_flow.example 00000000-0000-0000-0000-000000000000,00000000-0000-0000-0000-000000000000
3 changes: 2 additions & 1 deletion examples/resources/prefect_flow/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ resource "prefect_flow" "flow" {
name = "my-flow"
workspace_id = prefect_workspace.workspace.id
tags = ["tf-test"]
}
}

1 change: 1 addition & 0 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PrefectClient interface {
BlockSchemas(accountID uuid.UUID, workspaceID uuid.UUID) (BlockSchemaClient, error)
BlockTypes(accountID uuid.UUID, workspaceID uuid.UUID) (BlockTypeClient, error)
Collections() (CollectionsClient, error)
Deployments(accountID uuid.UUID, workspaceID uuid.UUID) (DeploymentsClient, error)
Teams(accountID uuid.UUID) (TeamsClient, error)
Flows(accountID uuid.UUID, workspaceID uuid.UUID) (FlowsClient, error)
Workspaces(accountID uuid.UUID) (WorkspacesClient, error)
Expand Down
110 changes: 110 additions & 0 deletions internal/api/deployments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package api

import (
"context"

"github.com/google/uuid"
)

// DeploymentsClient is a client for working with deployemts.
type DeploymentsClient interface {
Create(ctx context.Context, data DeploymentCreate) (*Deployment, error)
Get(ctx context.Context, deploymentID uuid.UUID) (*Deployment, error)
List(ctx context.Context, handleNames []string) ([]*Deployment, error)
Update(ctx context.Context, deploymentID uuid.UUID, data DeploymentUpdate) error
Delete(ctx context.Context, deploymentID uuid.UUID) error
}

// Deployment is a representation of a deployment.
type Deployment struct {
BaseModel
AccountID uuid.UUID `json:"account_id"`
WorkspaceID uuid.UUID `json:"workspace_id"`

Description string `json:"description,omitempty"`
EnforceParameterSchema bool `json:"enforce_parameter_schema"`
Entrypoint string `json:"entrypoint"`
FlowID uuid.UUID `json:"flow_id"`
ManifestPath string `json:"manifest_path,omitempty"`
Name string `json:"name"`
Path string `json:"path"`
Paused bool `json:"paused"`
Tags []string `json:"tags"`
Version string `json:"version,omitempty"`
WorkPoolName string `json:"work_pool_name,omitempty"`
WorkQueueName string `json:"work_queue_name,omitempty"`
}

// DeploymentCreate is a subset of Deployment used when creating deployments.
type DeploymentCreate struct {
Description string `json:"description,omitempty"`
EnforceParameterSchema bool `json:"enforce_parameter_schema,omitempty"`
Entrypoint string `json:"entrypoint,omitempty"`
FlowID uuid.UUID `json:"flow_id"`
ManifestPath string `json:"manifest_path,omitempty"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
Paused bool `json:"paused,omitempty"`
Tags []string `json:"tags,omitempty"`
Version string `json:"version,omitempty"`
WorkPoolName string `json:"work_pool_name,omitempty"`
WorkQueueName string `json:"work_queue_name,omitempty"`
}

// DeploymentUpdate is a subset of Deployment used when updating deployments.
type DeploymentUpdate struct {
Description string `json:"description,omitempty"`
EnforceParameterSchema bool `json:"enforce_parameter_schema,omitempty"`
Entrypoint string `json:"entrypoint,omitempty"`
ManifestPath string `json:"manifest_path"`
Path string `json:"path,omitempty"`
Paused bool `json:"paused,omitempty"`
Tags []string `json:"tags,omitempty"`
Version string `json:"version,omitempty"`
WorkPoolName string `json:"work_pool_name,omitempty"`
WorkQueueName string `json:"work_queue_name,omitempty"`
}

// DeploymentFilter defines the search filter payload
// when searching for deployements by name.
// example request payload:
// {"deployments": {"handle": {"any_": ["test"]}}}.
type DeploymentFilter struct {
}
mitchnielsen marked this conversation as resolved.
Show resolved Hide resolved

type DeploymentAccess struct {
BaseModel
AccountID uuid.UUID `json:"account_id"`
WorkspaceID uuid.UUID `json:"workspace_id"`
DeploymentID uuid.UUID `json:"deployment_id"`
AccessControl DeploymentAccessControl `json:"access_control"`
}

// DeploymentAccessSet is a subset of DeploymentAccess used when Setting deployment access control.
type DeploymentAccessSet struct {
AccessControl DeploymentAccessControlSet `json:"access_control"`
}

// DeploymentAccessControlSet is a definition of deployment access control.
type DeploymentAccessControlSet struct {
ManageActorIDs []string `json:"manage_actor_ids"`
RunActorIDs []string `json:"run_actor_ids"`
ViewActorIDs []string `json:"view_actor_ids"`
ManageTeamIDs []string `json:"manage_team_ids"`
RunTeamIDs []string `json:"run_team_ids"`
ViewTeamIDs []string `json:"view_team_ids"`
}

// DeploymentAccessControl is a definition of deployment access control.
type DeploymentAccessControl struct {
ManageActors []Actor `json:"manage_actors"`
RunActors []Actor `json:"run_actors"`
ViewActors []Actor `json:"view_actors"`
}

type Actor struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Type string `json:"type"`
}
Loading
Loading