terraform-provider-ibm icon indicating copy to clipboard operation
terraform-provider-ibm copied to clipboard

Requires Terraform Resource "Submit build" for Code Engine Image Builds

Open marifse opened this issue 1 year ago • 2 comments

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

There is no terraform resource provided in terraform registry for submitting the Code Engine Image build after creating the Image build using terraform, this can only be done using the local provisioner right now, which i assume is not a good practice.

Code Engine Image Builds

  • ibm_code_engine_build

Potential Terraform Configuration

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

References

  • #0000

marifse avatar Aug 29 '23 21:08 marifse

Hello @marifse,

thank you for reaching out. I will bring that up internally and discuss, though I can't make any promises if and when we can provide a submit capability for build definitions. There are possibilities to work around that limitation with other means, perhaps that is a solution for you:

data "ibm_iam_auth_token" "tokendata" {}

provider "restapi" {
  uri                  = "https://api/.${var.region}.codeengine.cloud.ibm.com/"
  debug                = true
  write_returns_object = true
  headers = {
    Authorization = data.ibm_iam_auth_token.tokendata.iam_access_token
  }
}

resource "restapi_object" "buildrun" {
  path     = "/v2/projects/${ibm_code_engine_project.project.project_id}/build_runs"
  data = jsonencode(
    {
      name = "${var.basename}-build-run"
      output_image  = "${var.registry}/${ibm_cr_namespace.namespace.name}/mytodo:latest"
      output_secret = ibm_code_engine_secret.registry.name
      source_url    = "https://github.com/l2fprod/mytodo"
      strategy_type = "dockerfile"
      timeout = 3600
    }
  )
  id_attribute = "name"
}

resource "time_sleep" "wait_for_build" {
  create_duration = "2m"

  depends_on = [
    restapi_object.buildrun
  ]
}

michael-magrian avatar Oct 23 '23 08:10 michael-magrian

https://github.com/IBM/document-extraction-toolkit/tree/main/terraform

This might have some elements you are looking for. It can clone a repo, provision resources, create a container registry namespace, create code engine build definitions, use the workaround above to trigger build runs, then proceeds to deploy the code engine application after image builds finish.

bobfang avatar Jan 05 '24 23:01 bobfang