Terraform
Workload Policies Configure workload rightsizing policies and attach them to clusters with Terraform.
devzero_workload_policy defines how workloads should be rightsized -- CPU and memory vertical scaling, horizontal scaling, and the triggers that activate them. devzero_workload_policy_target attaches a policy to one or more clusters with optional namespace, kind, and workload filters.
resource "devzero_workload_policy" "cost_saving" {
name = "cost-saving-policy"
description = "Aggressively rightsize non-critical workloads"
action_triggers = [ "on_detection" ]
detection_triggers = [ "pod_creation" , "pod_update" ]
cpu_vertical_scaling {
enabled = true
target_percentile = 0.95
min_request = 50
max_request = 4000
overhead_multiplier = 1.1
limits_adjustment_enabled = true
}
memory_vertical_scaling {
enabled = true
target_percentile = 0.95
min_request = 64
max_request = 8192
overhead_multiplier = 1.15
limits_adjustment_enabled = true
}
}
Parameter Type Required Description namestring Yes Unique name for the policy descriptionstring No Human-readable description action_triggerslist(string) No When to act: "on_detection", "on_schedule" cron_schedulestring No 5-field cron expression (used with "on_schedule" trigger) detection_triggerslist(string) No What triggers detection: "pod_creation", "pod_update" loopback_period_secondsnumber No Historical data window in seconds startup_period_secondsnumber No Grace period after pod starts before scaling cooldown_minutesnumber No Minimum wait time between scaling applications live_migration_enabledbool No Enable live migration of workloads scheduler_pluginslist(string) No Scheduler plugins to use (e.g. ["dz-scheduler"]) defragmentation_schedulestring No Cron expression for background optimization min_change_percentnumber No Minimum resource change to trigger scaling drift_delta_percentnumber No Allowed drift before re-evaluation stability_cv_maxnumber No Maximum coefficient of variation for stability cpu_vertical_scalingblock No CPU vertical scaling configuration (see below) memory_vertical_scalingblock No Memory vertical scaling configuration (see below) gpu_vertical_scalingblock No GPU vertical scaling configuration (see below) gpu_vram_vertical_scalingblock No GPU VRAM vertical scaling configuration (see below) horizontal_scalingblock No Horizontal scaling configuration (see below)
Used by cpu_vertical_scaling, memory_vertical_scaling, gpu_vertical_scaling, and gpu_vram_vertical_scaling.
Parameter Type Required Description enabledbool Yes Whether vertical scaling is active target_percentilefloat No Usage percentile to target (e.g. 0.95) min_requestnumber No Minimum request value (millicores for CPU, MiB for memory) max_requestnumber No Maximum request value overhead_multiplierfloat No Safety margin multiplier applied to recommendations limits_adjustment_enabledbool No Whether to adjust limits alongside requests
Parameter Type Required Description enabledbool Yes Whether horizontal scaling is active min_replicasnumber No Minimum number of replicas max_replicasnumber No Maximum number of replicas overhead_multiplierfloat No Safety margin multiplier applied to recommendations limits_adjustment_enabledbool No Whether to adjust limits alongside requests
devzero_workload_policy_target attaches a devzero_workload_policy to one or more clusters. You can optionally filter by workload kind, namespace, and name patterns.
resource "devzero_workload_policy_target" "production" {
name = "production-target"
policy_id = devzero_workload_policy . cost_saving . id
cluster_ids = [devzero_cluster . production . id]
kind_filter = [ "Deployment" , "StatefulSet" ]
enabled = true
}
Parameter Type Required Description namestring Yes Unique name for the target policy_idstring Yes ID of the devzero_workload_policy to attach cluster_idslist(string) Yes List of cluster IDs to apply the policy to descriptionstring No Human-readable description enabledbool No Whether the target is active (default: true) prioritynumber No Priority when multiple targets match a workload workload_nameslist(string) No Specific workload names to match node_group_nameslist(string) No Node groups to scope the policy to kind_filterlist(string) No Workload kinds to include (see below) name_patternblock No Regex-based name matching (pattern, flags) namespace_selectorblock No Label selector for namespaces (match_labels, match_expressions) workload_selectorblock No Label selector for workloads (match_labels, match_expressions)
Supported kind filter values: Pod, Deployment, StatefulSet, DaemonSet, Job, CronJob, ReplicaSet, ReplicationController, Rollout
Parameter Type Description patternstring Regular expression to match workload names flagsstring Regex flags: "i" (case-insensitive), "m" (multiline)
Parameter Type Description match_labelsmap(string) Key-value pairs that must all match match_expressionslist(block) Label selector expressions (key, operator, values)