Configuration As Code

Configuration As Code

Configuration As Code

Partite.ai Mesh supports managing all configuration as code using Terraform. Both code-first and UI first approaches are supported.

Prerequisites

To use the Partite.ai Terraform provider, an API Key with Configuration Read and Configuration Write scopes is required.

Provider Configuration

The next step is to configure Terraform to use the Partite.ai provider. This is done in two parts:

  • In the terraform block, declare the provider as required for this configuration
  • Declare a provider block containing the configuration for the Partite.ai provider

An example configuration looks like:

terraform {
  required_providers {
    partiteai = {
      source  = "tf.partite.ai/partite-ai/partiteai"
      version = "1.0.10"
    }
  }
}

provider "partiteai" {
  api_key    = "<your api key>"
  api_secret = "<your api secret>"
}

Instead of setting api_key and api_secret in your provider configuration, you can set the environment variables PARTITE_AI_API_KEY and PARTITE_AI_API_SECRET to provide the necessary credentials. This can be useful if you wish to maintain secrets in a CI/CD system or other secret store.

By default, the Partite.ai Terraform provider will connect to the Partite.ai Hosted Cloud service. To connect to a self hosted instance, set the endpoint parameter of the partiteai provider block.

For example:

provider "partiteai" {
  api_key    = "<your api key>"
  api_secret = "<your api secret>"
  endpoint   = "http://localhost:8080/graphql"
}

You may also set the PARTITE_AI_ENDPOINT environment variable.

State Storage

Terraform requires storage of a state file that tracks the state of the last apply of the configuration. If you have an existing strategy to store your Terraform state files, you may skip this section, otherwise read on for options.

If you’re unfamiliar with Terraform’s state storage, you might want to read the Terraform Documentation covering state storage backends.

Local State Storage

One option for storing the state is to use the Terraform default local state storage. In this case, the state file will be stored as a file called terraform.tfstate in the directory where your Terraform files are stored. After each run, you must preserve this file, for example by committing it to source control. If you configure API Keys or Webhook Destinations in your Terraform, this state file may contain sensitive information, so you should encrypt it prior to storage.

See Terraform local Backend Documentation for more information on this option.

Cloud Hosted State Storage

To simplify the usage of Partite.ai, we provide the ability to store Terraform state in the Partite.ai Cloud using Terraform’s http backend. The Cloud hosted service supports storing multiple state files so you can maintain multiple different Terraform configurations for different projects.

To use the Cloud hosted state storage, configure Terraform’s http Backend to use https://api.dev.partite.ai/tfstate/<state file name> as the address, lock_address and unlock_address, and use your API Key/API Secret and the username and password. <state file name> can be any string that uniquely identifies the current project within your account, for example project1 or myapp-prod.

Example:

terraform {
  required_providers {
    partiteai = {
      source  = "tf.partite.ai/partite-ai/partiteai"
      version = "1.0.10"
    }
  }

  backend "http" {
    address        = "https://api.partite.ai/tfstate/<state file name>"
    lock_address   = "https://api.partite.ai/tfstate/<state file name>"
    unlock_address = "https://api.partite.ai/tfstate/<state file name>"
    username       = "<your api key>"
    password       = "<your api secret>"
  }
}

Resources

Once you’ve configured the provider, you’re ready to define your resources. This can be done code first by writing Terraform, or UI first by configuring in the Partite.ai UI and using the export to Terraform functionality. A common workflow is to create an initial version in the UI, and then as the configuration solidifies export to Terraform to manage as code.

To export a resource as Terraform in the UI, navigate to the list page for that resource. In the Actions column on each row, you’ll find a button labeled “Export As Terraform”. Clicking this button will bring up a dialog with the Terraform definitions of that resource, along with all dependent resources by default. If you wish, you can turn off the export of the dependent resources. By default, import blocks for each resource are also generated to allow the initial apply of the Terraform resources to import the resources that have been configured in the UI.

See the Terraform registry hosted documentation for the Partite.ai provider for a complete list of available resources and data sources, along with their configuration parameters.

Applying

Once your provider configuration and resources are defined, you can use terraform plan and terraform apply to apply changes to your Partite.ai configuration.