<@ULVA73B9P> what is the equivalent of this Terraf...
# ask-marvin
m
@Marvin what is the equivalent of this Terraform how-to https://www.prefect.io/blog/managing-prefect-deployments-with-terraform But for the case where I want to run Dockerized jobs, as in here? https://docs.prefect.io/v3/how-to-guides/deployment_infra/docker
m
thought for 99.4 seconds
Short version: the equivalent pattern in Prefect 3 for “Terraform + Dockerized jobs” is: 1. Terraform manages Prefect resources like the Docker work pool (and optionally deployments/schedules) 2. A Docker worker executes flow runs from that pool 3. Your deployment points at that Docker work pool and either: - uses an image containing your code, or - pulls code at runtime So the old blog post is only partially analogous now. It’s useful conceptually for IaC, but not as a literal how-to for Prefect 3 deployment creation. Best current references: - Run flows in Docker containers - Manage work pools - Deploy via Python - Infrastructure as Code - Prefect Terraform provider A practical mental model: - Terraform defines the pool: -
type = "docker"
- default job variables like image, env, networks, etc. - Deployment targets that pool - Worker listens to that pool and launches Docker containers Example shape in Terraform for the pool:
Copy code
hcl
resource "prefect_work_pool" "docker" {
  name = "docker-pool"
  type = "docker"

  job_variables = jsonencode({
    image = "my-registry/my-image:latest"
    image_pull_policy = "IfNotPresent"
    env = {
      PREFECT_LOGGING_LEVEL = "INFO"
    }
  })
}
Then your deployment can target that pool. In Prefect 3, I’d usually recommend one of these two patterns: Option A: Terraform for pool, Python for deployment - Create/manage the Docker work pool in Terraform - Define/update deployments in code with
flow.deploy(...)
Copy code
python
from prefect import flow

@flow
def my_flow():
    print("hello from docker")

if __name__ == "__main__":
    my_flow.deploy(
        name="my-flow-docker",
        work_pool_name="docker-pool",
        image="my-registry/my-image:latest",
        push=False,
    )
Option B: Terraform for both pool and deployment - Useful if you want the Prefect control-plane objects in Terraform state - More “pure IaC”, but less code-centric than
flow.deploy(...)
The important update is that for Prefect 3 you should not look for old 2.x patterns like: -
Deployment.build_from_flow()
-
prefect deployment build
Those are not the modern path in 3.x. Also, if you want the worker side, the CLI namespace is still
work-pool
/
worker
, but I wasn’t able to verify the exact CLI help output in time here, so I’d point you to the docs for the exact commands: - Manage work pools - Docker guide If you want, I can give you a concrete end-to-end example of: - Terraform for a Docker work pool - a
flow.deploy(...)
deployment - and the worker command to run it locally or in CI/CD.