On This Page

Home / Cribl as Code/ Terraform Provider (Preview)/ Terraform Code Examples/Configure Resources with the Cribl Terraform Provider

Configure Resources with the Cribl Terraform Provider

Preview Feature

The Cribl Terraform provider is a Preview feature that is still being developed. We do not recommend using it in a production environment, because the feature might not be fully tested or optimized for performance, and related documentation could be incomplete.

Please continue to submit feedback through normal Cribl support channels, but assistance might be limited while the feature remains in Preview.

This code example demonstrates how to use the Cribl Terraform provider to create the following resources in Cribl Stream:

  • A Worker Group to manage the configuration.
  • A Syslog Source to receive data on port 9021.
  • An S3 Destination to store processed data.
  • A Pipeline that filters events and keeps only data in the eventSource and eventID fields.
  • A Route that connects the Source, Pipeline, and Destination.

This example also commits and deploys the resource configurations to the Worker Group to make them active.

About Code Examples

Code examples require you to authenticate with the Cribl Terraform provider. Read the Terraform provider authentication documentation to learn how to configure authentication. The API Credential (Cribl.Cloud and hybrid) or login credentials (on-prem) that you use must have the necessary Permissions for the operations in the code examples.

Replace the variables in code examples with the corresponding information for your Cribl deployment.

For on-prem deployments, if CRIBL_ONPREM_SERVER_URL uses https, you must configure Transport Layer Security (TLS).

Code examples do not include all available resource arguments. For a complete list of arguments for specific resources, refer to the documentation in the Terraform Registry.

The Terraform configuration in this example is split into four files that together form one Terraform module:

Copy the example files into an empty local working directory as you complete the following sections. When you run the example, Terraform reads the files in your local working directory, resolves dependencies from attribute references (such as group_id), and creates resources in a single terraform apply.

Declare Input Variables with variables.tf

Copy variables.tf from the example into your local working directory. The file declares the input variables for the module. Each variable block gives a name, data type, and description for a value that you supply at apply time (for example, the Worker Group ID or S3 bucket name). Sensitive values such as API credentials and AWS keys are marked sensitive = true so Terraform does not print them in logs.

In the Cribl.Cloud example, this file also declares variables for Organization ID, Workspace name, and API Credential values. The on-prem example declares only the Worker Group and S3 variables because on-prem login credentials are supplied through environment variables or a credentials file as described in Authenticate in On-Prem Deployments.

variables.tf (Cribl.Cloud)variables.tf (On-Prem)

Set Variable Values with terraform.tfvars

This example uses a terraform.tfvars file to supply the values for the input variables declared in variables.tf. Copy terraform.tfvars from the example into your local working directory and replace each placeholder with a value for your deployment. Terraform loads terraform.tfvars automatically when you run terraform plan or terraform apply.

If you don’t want to use a terraform.tfvars file to set variable values, you can use one of these methods instead:

  • Pass values on the command line with -var or -var-file.
  • Set TF_VAR_<variable_name> environment variables.

Do not commit terraform.tfvars or any other files that contain sensitive information to version control.

terraform.tfvars (Cribl.Cloud)terraform.tfvars (On-Prem)

Configure Terraform Provider with provider.tf

Copy provider.tf from the example into your local working directory. The file configures the Cribl Terraform provider and declares the criblio provider source and minimum version in a terraform block.

  • In the Cribl.Cloud example, the provider "criblio" block sets Organization ID, Workspace name, and API Credential values from the variables you supply in terraform.tfvars.
  • In the on-prem example, the provider "criblio" block is empty. Configure authentication using environment variables or a credentials file as described in Authenticate in On-Prem Deployments.
provider.tf (Cribl.Cloud)provider.tf (On-Prem)

Create Cribl Stream Resources with main.tf

Copy main.tf from the example into your local working directory. The file defines the Cribl Stream resources that the example creates, in dependency order:

  1. criblio_group creates a new Worker Group.
  2. criblio_source creates a Syslog Source that listens on port 9021.
  3. criblio_destination creates an S3 Destination that uses aws_bucket_name, aws_region, aws_api_key, and aws_secret_key.
  4. criblio_pipeline creates a Pipeline with an Eval function that keeps only the eventSource and eventID fields.
  5. criblio_routes updates the Routing table with a Route from the Syslog Source through the Pipeline to the S3 Destination. The criblio_routes resource requires a complete representation of the Routing table, so the example includes a default catch-all Route to preserve existing behavior.
  6. criblio_commit commits the Worker Group configuration.
  7. criblio_config_version (data source) reads the version ID produced by the commit.
  8. criblio_deploy deploys the committed configuration to the Worker Group.

In the Cribl.Cloud example, the Worker Group is provisioned in AWS (on_prem = false). In the on-prem example, the Worker Group sets on_prem = true and omits cloud provisioning settings.

main.tf (Cribl.Cloud)main.tf (On-Prem)

Run the Example

Complete the preceding sections to copy the example files into your local working directory and set variable values in terraform.tfvars. Before you run the example, confirm that Terraform 1.0 or later is installed.

Run Example (Cribl.Cloud)Run Example (On-Prem)

After a successful terraform apply, your Cribl Stream deployment has a new Worker Group with a Syslog Source on port 9021, a Pipeline, an S3 Destination, and a Route that connects them. The Worker Group configuration is committed and deployed.