- Configure
Configure Pulsar Terraform Provider
Install the Provider
You can install the Pulsar Terraform Provider using the following code snippet.
terraform {
required_providers {
pulsar = {
source = "streamnative/pulsar"
}
}
}
Configure the Provider
Once you have added the provider to your Terraform configuration, you need to configure the provider with your Pulsar Cluster service url and credentials.
Below is an example of configuring the provider to connect to a Pulsar cluster at <pulsar-cluster-service-url>
using Token authentication. Please make sure the token has the Super Admin permission in order to create resources within the Pulsar cluster.
provider "pulsar" {
web_service_url = "<pulsar-cluster-service-url>"
token = "<pulsar-cluster-token>"
}
Configure the Provider with Different Authentication Methods
Token Authentication
You can specify the token in the provider configuration. Make sure the token has the Super Admin permission in order to create resources within the Pulsar cluster.
provider "pulsar" {
web_service_url = "<pulsar-cluster-service-url>"
token = "<pulsar-cluster-token>"
}
OAuth2 Authentication
You can specify the OAuth2 key file path in the provider configuration. If your cluster is configured to require audience, you also need to specify the audience in the provider configuration.
provider "pulsar" {
web_service_url = "<pulsar-cluster-service-url>"
key_file_path = "<path-to-your-oauth2-key-file>"
audience = "<audience>"
}
Validate the Configuration
After you have configured the provider in your Terraform configuration, you can run the following command to download and install the providers defined in the configuration:
terraform init
You can then run the following command to ensure the configuration is syntactically valid and internally consistent:
terraform validate
Apply the configuration:
terraform plan
If you are not able to connect to the Pulsar cluster, you will see an error message similar to the following:
Error: failed to create pulsar oauth2 provider: authentication failed using client credentials: <error-message>
Otherwise, you should see a successful output.
Full Code Example
Below is the full code example of how to configure the Pulsar Terraform Provider.
terraform {
required_providers {
pulsar = {
source = "streamnative/pulsar"
}
}
}
provider "pulsar" {
web_service_url = "<pulsar-cluster-service-url>"
token = "<your-api-key>"
}