Using Terraform to Generate QuickBooks Connector

Summary

The user wants to use Terraform to automatically generate a connector for QuickBooks, which is a community-supported source in Airbyte. They have provided a sample source configuration and want guidance on how to write this automatically using Terraform.


Question

Hi there, I had an issue related to a source which is supported by community. I wanted to connect quick books which is available as an community only supported source. Now I want to use terraform to generate that connector. I create the source using the UI of my OSS build and retrieve it using api for demonstration purposes: (Quickbook is only supported in OSS and hence a connector has not been generated )

Do help me understand how I can use terraform to write this automatically…

            "sourceId": "2b953b45-341f-445d-8e15-28d115a8500c",
            "name": "QuickBooks",
            "sourceType": "quickbooks",
            "workspaceId": "4c882d54-a6a7-459a-b617-aa6fff9a46f3",
            "configuration": {
                "sandbox": true,
                "start_date": "2024-06-01T00:00:00Z",
                "credentials": {
                    "realm_id": "**********",
                    "auth_type": "oauth2.0",
                    "client_id": "ABRSwH6l9FdVhteCHqm5ais6dKsJGa4UKCjIPci6NNc18i9nsO",
                    "access_token": "**********",
                    "client_secret": "**********",
                    "refresh_token": "**********",
                    "token_expiry_date": "2024-08-30T00:00:00Z"
                }
            }
        }```

<br>

---

This topic has been created from a Slack thread to give it more visibility.
It will be on Read-Only mode here. [Click here](https://airbytehq.slack.com/archives/C021JANJ6TY/p1718754995038699) if you want 
to access the original thread.

[Join the conversation on Slack](https://slack.airbyte.com)

<sub>
["quickbooks", "community-supported-source", "terraform", "connector-generation", "source-configuration"]
</sub>

there is airbyte_source_custom for that
https://registry.terraform.io/providers/airbytehq/airbyte/latest/docs/resources/source_custom

Yes, but the entire validation flow dosnt work with that. As we are automating the process using LLMs. Any way we can try to build our own provider alongside, or a custom validator?

Also is there a way to download the openapi spec @ https://reference.airbyte.com/reference/createsource

you can find openapi spec here
https://github.com/airbytehq/terraform-provider-airbyte/blob/main/airbyte.yaml

If you want custom resource for QuickBooks, you might consider generating your own version of terraform provider with speakeasy

Yes, but this yaml doesn’t include the spec for quickbooks, any way to generate it automatically?

I’d start with converting QuickBooks https://github.com/airbytehq/airbyte/blob/74fab0eba6ea38b5c71d6524a095e01b0e48e5bc[…]ations/connectors/source-quickbooks/source_quickbooks/spec.json|spec.json to YAML format
If you compare Amplitude https://github.com/airbytehq/airbyte/blob/74fab0eba6ea38b5c71d6524a095e01b0e48e5bc/airbyte-integrations/connectors/source-amplitude/source_amplitude/spec.yaml|spec.yaml with <terraform-provider-airbyte/airbyte.yaml at 70cef6484c13de8933ba40412c8c4fb09b8871d3 · airbytehq/terraform-provider-airbyte · GitHub (lines 52696-52797)>, you can find similar structure
probably you will need to add definitons for SourceQuickBooksCreateRequest, SourceQuickBooksPutRequest

in my opinion, it would be easier to use terraform validation and create a small module - a wrapper for airbyte_source_custom than creating your own version of terraform provider
keep in mind that any customizations will require future maintenance and updates

Firstly, thanks for your help in such a concise and articulate manner. Since I am new to terraform, I am not sure if I understand correctly what you mean by the difference between wrapper and terraform provider. I will try to explore just that, do point me to any resources if any.

By provider here I refer to https://github.com/airbytehq/terraform-provider-airbyte|terraform-provider-airbyte
By a wrapper here I mean small <https://developer.hashicorp.com/terraform/language/modules|terraform module> that will have mostly airbyte_source_custom resource, and variable will have some validations

If you are new to some technologies, keep it simple as much as possible; you can improve it later; introduce some validations and so on

So I tried building some wrappers or at least getting a sense of this verification before I hit terraform apply. So, honestly I couldn’t figure it out. Many of the validations that I built required to run a python script. and almost in every type of way, I had to hit terraform apply inorder for the verification to take place. Now, what i intend to do differently is being able to verify the script using terraform validate itself. Any idea how to do that?

Everytime based on the syntax the schema gets approved even if its not valid. One of the things I did was to use a null resource and run a python script inside it. <@U05JENRCF7C>

using null resource makes things more complicated
you can use built-in validation for variable
https://developer.hashicorp.com/terraform/language/values/variables#custom-validation-rules

and type constraint type = object(...)
https://developer.hashicorp.com/terraform/language/expressions/type-constraints

I haven’t tested it, but for your case, you could have something like this:

  type = object({
    sandbox    = bool
    start_date = string
    credentials = object({
      realm_id          = string
      auth_type         = string
      client_id         = string
      access_token      = string
      client_secret     = string
      refresh_token     = string
      token_expiry_date = string
    })
  })

  description = "Configuration for the application including credentials and settings."

  validation {
    condition = contains(["oauth2.0"], var.configuration.credentials.auth_type)
    error_message = "auth_type must be 'oauth2.0'."
  }
}```

you are right, but I am not looking for such a hardcoded validation, I want it to be dynamic based on the spec.json file.

Hi <@U078H8TAU6S>! Slightly unrelated question - are you using Kubernetes do deploy Airbyte? How were you able to expose the API?
I’d like to use Terraform as well but I’m having troubles with setting up the api.
Really appreciate your help on this!

Hey there, we are not using K8s, just plain and simple container deployment for now.

For a single docker container if you are not able to access the API let me know.

Any idea how I can do that? <@U05JENRCF7C>

Thanks for the response anyways! Did you have to expose it to other port or were you able to access it on /api endpoint?