terraform-provider-ibm
terraform-provider-ibm copied to clipboard
Add a way to submit Code Engine Job and waiting until job run ends
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
I'd like to create a Code Engine Job and then run it to complete some tasks. Before continuing with the rest of the script, it should wait for the job completition.
Code Engine API to use:
New or Affected Resource(s)
- ibm_code_engine_job_run
Potential Terraform Configuration
resource "ibm_code_engine_job_run" "code_engine_job_run_instance" {
project_id = ibm_code_engine_project.code_engine_project_instance.project_id
name = "my-job-run"
job_name = ibm_code_engine_job.code_engine_job_instance.name
}
References
A workaround was posted in #4774 using a restapi provider and time_sleep together to submit a build run, which can be easily modified to work for a job run.
Until this is implemented in the provider, the following works reasonably well.
data "ibm_iam_auth_token" "tokendata" {}
provider "restapi" {
uri = "https://api.${data.ibm_code_engine_project.code_engine_project_instance.region}.codeengine.cloud.ibm.com/"
write_returns_object = true
headers = {
Authorization = data.ibm_iam_auth_token.tokendata.iam_access_token
}
}
resource "random_pet" "ce_build_tag" {
length = 2 # Adjust the desired length random words
separator = "" # No separator between words
}
resource "restapi_object" "jobrun_worker" {
path = "/v2/projects/${data.ibm_code_engine_project.code_engine_project_instance.project_id}/job_runs"
data = jsonencode(
{
name = "worker-job-run-${random_pet.ce_build_tag.id}"
job_name = ibm_code_engine_job.ce_worker_job.name
}
)
id_attribute = "name"
depends_on = [ time_sleep.wait_for_build_worker ]
}