:wave: - curious if there's alternative support (...
# ask-community
d
👋 - curious if there's alternative support (I can't seem to find it) for adding deployment triggers for non-sdk related deployments. i didn't explore if prefect.yaml supports them or not, but my current deployment flow is through terraform. example in thread.
Copy code
variable "stg_deployment_tag" {
  description = "Deployment tag used for staging (e.g., 'latest')."
  type        = string
  default     = "latest"
}

module "stg_aws_prefect_backend" {
  count = var.stg_deployment_tag != "" ? 1 : 0

  source = "../../../../../devops/infra/terraform/modules/aws_prefect_backend"

  pipeline                               = local.pipeline
  short_env                              = "stg"
  prefect_task_deployment_repository_url = aws_ecr_repository.pipeline_repo.repository_url
  prefect_task_deployment_tag            = var.stg_deployment_tag

  aws_ecs_cluster      = "${local.prefix}-pipelines-stg"
  aws_ecs_service_name = local.pipeline

  prefect_api_url = local.prefect_api_url
  prefect_api_key = local.prefect_api_key

  prefect_work_pools = [
    {
      name            = "stg--${local.pipeline}:2048-4096"
      kind            = "ecs"
      task_definition = {
        cpu    = 2048
        memory = 4096
        worker_resources = {
          cpu    = 2048
          memory = 4096
        }        
      }
    }
  ]

  prefect_deployments = [
    {
      prefect_flow_name       = "stg--${local.pipeline}:root"
      prefect_deployment_name = "stg--${local.pipeline}"
      pipeline                = tostring(local.pipeline)
      work_pool = {
        name          = "stg--${local.pipeline}:2048-4096"
        job_variables = {}
        queue         = "default"
      }
    }
  ]
}
This is how I'm managing my work pool/flow deployments now. the
prefect_deployment
param utilizes the
prefect_deployment
resource within the module (below)
Copy code
resource "prefect_flow" "pipeline_flow" {
  for_each = { for dep in var.prefect_deployments : dep.prefect_deployment_name => dep }
  name     = each.value.prefect_flow_name
  tags     = []
}

resource "prefect_deployment" "pipeline_deployment" {
  for_each = { for dep in var.prefect_deployments : dep.prefect_deployment_name => dep }

  name       = each.value.prefect_deployment_name
  flow_id    = prefect_flow.pipeline_flow[each.key].id
  entrypoint = "src/${replace(each.value.pipeline, "-", "_")}/main.py:root"

  paused     = false
  pull_steps = [
    {
      type      = "set_working_directory",
      directory = "/opt/"
    }
  ]

  job_variables = jsonencode(
    merge(
      lookup(each.value.work_pool, "job_variables", {}),
      {
        "image" : "${var.prefect_task_deployment_repository_url}:${var.prefect_task_deployment_tag}"
      }
    )
  )

  work_pool_name  = each.value.work_pool.name
  work_queue_name = lookup(each.value.work_pool, "queue", "default")
}
my ideal scenario is the TF module would support adding the deployment events https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs/resources/deployment
b
Hey David! You can add deployment triggers to a prefect.yaml (docs for that here).
d
i guess my question is will terraform ever be expected to support that since deployments can be managed through the module
i'd ideally not use prefect.yaml
b
Gotcha, I'm not seeing mentions of deployment triggers in the TF docs. 🤔
Mind opening a GitHub issue for this?
d
Added here @Bianca Hoch https://github.com/PrefectHQ/terraform-provider-prefect/issues/391 cc - @Jamie Zieziula @Mitch Nielsen
gratitude thank you 1
m
if I'm understanding your need correctly, you can manage triggers in the
prefect_automation
resource: https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs/resources/automation
prefect spin 1
🙌 1
d
yeah that's it. but i want to associate those with the deployment as i would in the prefect.yaml. Wouldn't it make sense for the
prefect_deployment
resource in terraform to have a
triggers
param to accept a list of those ids for continuity?
m
the way it's currently wired is to set
deployment_id
on the
prefect_automation
to tell it which deployment to apply the action
d
oh i see, rtfm - my bad
will close the ticket
m
no problem at all, the automations resource is pretty complicated and still fairly new so it's good feedback. we should probably include usage of the
deployment_id
in the example
👍 2
d
just reverse dependencies so my assumption was to go down the one rabbit hole. appreciate the clarification. trying to avoid the prefect.yml so i can manage my workpools with deployments together through terraform
b
Thank you Mitch! Sorry for the extra work David 🙇
🤝 1
d
no worries! thanks everyone.
m