terraform-provider-kubernetes
terraform-provider-kubernetes copied to clipboard
kubernetes_job_v1 does not support suspend field
I am creating this new issue because the original one has been closed without resolving it (#1739).
Terraform Version, Provider Version and Kubernetes Version
Terraform version: v1.9.6
Kubernetes provider version: v2.32.0
Kubernetes version: v1.30.6-eks-7f9249a
Affected Resource(s)
- kubernetes_job_v1
Terraform Configuration Files
resource "kubernetes_job_v1" "restore_db" {
metadata {
name = "restore-db"
namespace = data.kubernetes_namespace_v1.database_management.id
}
spec {
suspend = true # <--- this field does not exist
backoff_limit = 1
template {
metadata {
labels = local.restore_common_labels
}
spec {
restart_policy = "Never"
container {
name = "database-restorer"
image = "mcr.microsoft.com/mssql-tools"
command = [
"/bin/bash",
"-c"
]
args = [
"/opt/mssql-tools/bin/sqlcmd -V16 -b -S $DATABASE_INSTANCE -U $MASTER_USERNAME -i /data/restore_db.sql"
]
env {
name = "DATABASE_INSTANCE"
value = "${data.aws_db_instance.target.address},${data.aws_db_instance.target.db_instance_port}"
}
env {
name = "MASTER_USERNAME"
value = local.rds_master_username
}
env_from {
secret_ref {
name = kubernetes_secret_v1.restore_db.metadata.0.name
}
}
volume_mount {
name = "script-volume"
mount_path = "/data"
}
}
volume {
name = "script-volume"
config_map {
name = kubernetes_config_map_v1.restore_db.metadata.0.name
}
}
}
}
}
}
Output
│ Error: Unsupported argument
│
│ on db_restore.tf line 53, in resource "kubernetes_job_v1" "restore_db":
│ 53: suspend = true
│
│ An argument named "suspend" is not expected here.
Steps to Reproduce
- terraform validate
Expected Behavior
What should have happened?
Kubernetes job spec support the suspend field since v1.21, I should be able to specify the suspend field in the kubernetes_job_v1 resource too.
Actual Behavior
What actually happened? I cannot specify the suspend field, terraform rejects it. It is strange because kubernetes_cronjob_v1 supports it.
I'd like to take a look at the issue.
So. I think the main reason suspend was not implemented for a Job resource is existence of wait_for_completion which tells Terraform to wait until the Job either succeeds or fails. If suspend is set to true, wait_for_completion cannot be set to true, because it is unclear when (and whether at all) the user sets suspend to false and resumes the job.
A proposal:
- do not allow setting both
suspendandwait_for_completionto true at the same time suspendis allowed to change, and changingsuspendleads to resource update in-place
"suspend": {
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
Description: "Tells the controller to suspend subsequent executions, and terminate all active executions. suspend and wait_for_completion cannot be both set to true. Defaults to false. More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/#suspending-a-job",
},
What do you think?
Hi @marsskop,
for me your proposal is sound.