Skip to content

Commit

Permalink
Adds infra recipe for prefect-cloud workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilRex committed Dec 16, 2024
1 parent 4d6ac44 commit 8b5b876
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
52 changes: 52 additions & 0 deletions infra/prefect-cloud/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Declare that we need the Prefect provider
// NOTE: Fails when both PREFECT_CLOUD_ACCOUNT_ID and PREFECT_API_URL are set
terraform {
required_providers {
prefect = {
source = "PrefectHQ/prefect"
}
}
}

// Create a workspace
locals {
workspace_handle = replace(replace(lower(var.prefect_workspace_name), " ", "-"), "_", "-")
}

resource "prefect_workspace" "workspace" {
name = var.prefect_workspace_name
handle = local.workspace_handle
}

// Create a service account and add it to the workspace
resource "prefect_service_account" "service_account" {
name = "prefect-worker"
account_role_name = "Member"
depends_on = [prefect_workspace.workspace]
}

data "prefect_workspace_role" "worker" {
name = "Worker"
depends_on = [prefect_workspace.workspace]
}

resource "prefect_workspace_access" "workspace_access" {
accessor_type = "SERVICE_ACCOUNT"
accessor_id = prefect_service_account.service_account.id
workspace_id = prefect_workspace.workspace.id
workspace_role_id = data.prefect_workspace_role.worker.id
}

// Create basic process and docker work pools
resource "prefect_work_pool" "process_work_pool" {
name = "process"
type = "process"
workspace_id = prefect_workspace.workspace.id
}

resource "prefect_work_pool" "docker_work_pool" {
name = "docker"
type = "docker"
workspace_id = prefect_workspace.workspace.id
}

8 changes: 8 additions & 0 deletions infra/prefect-cloud/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output "prefect_workspace_id" {
value = prefect_workspace.workspace.id
}

output "prefect_service_account_api_key" {
value = prefect_service_account.service_account.api_key
sensitive = true
}
3 changes: 3 additions & 0 deletions infra/prefect-cloud/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "prefect_workspace_name" {
description = "The name of the workspace"
}

0 comments on commit 8b5b876

Please sign in to comment.