IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
338 stars 647 forks source link

Poor documentation of `ibm_code_engine_binding` #5138

Open saevarb opened 4 months ago

saevarb commented 4 months ago

Community Note

New or Affected Resource(s) or Datasource(s)

Description

I'm trying to use ibm_code_engine_binding to automate binding e.g. a postgres database to my code engine instances.

The documentation for component states:

Okay, so the database I want to bind to my code engine app, right?

So the name of my database.

Alright, and what are the valid values for this? I've tried databases-for-postgresql which does not work. In fact, this fails due to a regex validation error during apply(instead of during planning), and so does the same thing with underscores instead of dashes.

This also leaves one asking: where do I actually specify which code engine app this resource is supposed to be bound to? The documentation examples further confuses by providing the following example

resource "ibm_code_engine_binding" "code_engine_binding_instance" {
  component {
        name = "my-app-1"
        resource_type = "app_v2"
  }
  prefix = "MY_COS"
  project_id = "15314cc3-85b4-4338-903f-c28cdee6d005"
  secret_name = "my-service-access"
}

I can only assume app_v2 refers to a code engine application, but of course this is not documented anywhere on this page, but I can confirm this by looking at other documentation.. but clearly this is meant to be a binding to a COS resource, but then where is any reference to said COS resource?

As I've had to do before, I figured I'd try creating the binding manually, then import it and then look at the output from terraform. Unfortunately, the documentation for that states

You can import the ibm_code_engine_binding resource by using binding_id. The id property can be formed from project_id, and binding_id in the following format [..]

But nowhere is it described where you can get a binding id, and I've not been able to find it anywhere, not on the code engine service binding page(in urls or otherwise) or on the database side.

saevarb commented 4 months ago

I discovered that the ibm cloud cli can list bindings: ibmcloud ce binding list. There is an ID in there, but following the documentation and constructing and id <project_id>/<binding_id> using this ID returns an error during apply:

 "Result": {
β”‚         "errors": [
β”‚             {
β”‚                 "code": "parameter_invalid",
β”‚                 "message": "Bad request - The parameter 'id' is invalid. reason: TOOLONG",
β”‚                 "target": {
β”‚                     "name": "id",
β”‚                     "reason": "TOOLONG",
β”‚                     "type": "parameter"
β”‚                 }
β”‚             }
β”‚         ],
β”‚         "status_code": 400,
β”‚         "trace": "codeengine-api-61f504f2d86142afbf8c0bd2817c5502"
β”‚     },
jaksart1 commented 4 months ago

Hi @saevarb Thanks you for bringing the lack of clarity in the docs to our attentions, we are opening a ticket to improve them based on your feedback.

As for your issue, creating a service binding is actually a 3 step process.

  1. Create a code engine app/job

  2. Create a service-access secret that references your other ibm cloud service (in your case a postgres instance). This secret will contain all connection information related to your service instance.

  3. Create a binding with your Code Engine app/job (resource_type: app_v2 or job_v2) and the service access secret. This binding will connect your app/job to the service-access secret, giving your app/job access to the credentials stored within, thus allowing a connection between your app/job and postgres instance.

saevarb commented 4 months ago

@jaksart1 Thanks a lot for your quick response. That makes sense, but yes, would be super useful to have as part of the documentation.