This tutorial demonstrates how to use StreamNative Terraform Provider to deploy a Serverless cluster and use the Pulsar Terraform Provider to provision Pulsar resources in the Serverless cluster.
This tutorial provisions the following resources (assuming we name the application as sl-app
):
sl-instance
).sl-clu
).sl-app-sa
.sl-app-apikey
.sl-app-tenant
sl-app-ns
and grants produce
and consume
permissions to the Service Account on the namespace.sl-app-topic
.The code examples is available in the examples/terraform/serverless folder.
Create a new directory anywhere you’d like for this project.
First, you need to create a service account called tf-runner
with Super Admin access. Please refer to Create a Service Account for details.
After you have created the service account, download the OAuth2 credentials file and save it as tf-runner.json
in the terraform-getting-started
folder that you created earlier.
Create a module folder streamnative_cloud
.
Create a variables.tf
file inside the streamnative_cloud
folder and add the following code snippet to prepare the variables. Remember to replace <your-organization-id>
with your StreamNative Cloud organization id.
<your-organization-id>
with it.sl-instance
.sl-clu
.sl-app
.Create a main.tf
file inside the streamnative_cloud
folder and add the following code snippet to create the resources.
Use the StreamNative Terraform Provider version 0.7.0
or later.
Go back to the root folder terraform-getting-started
.
You can copy the variables.tf
file from the streamnative_cloud
module folder.
Create a main.tf
file in the root folder and add the following code snippet to create the resources.
Before running the Terraform commands, you need to expose the following variables:
Please replace the above placeholders with your actual values:
<your-org-id>
: Your StreamNative Cloud organization ID<your-instance-name>
: A unique name for your Pulsar instance (e.g., “sl-instance”)<your-cluster-name>
: A unique name for your Pulsar cluster (e.g., “sl-clu”)<your-app-name>
: A unique name for your application (e.g., “sl-app”)An example of exposing the variables is as follows:
After exposing the variables, you can run the following Terraform commands to provision the resources.
First, initialize the Terraform working directory.
Secondly, validate the Terraform configuration files.
Since we use two providers in this example (the StreamNative Provider and the Pulsar Provider), we need to provision the resources in two steps. The Pulsar Provider resources depend on the StreamNative Provider resources being created first.
Run a targeted plan to see the changes and preview the resources that will be created.
After that, run a targeted apply to create the resources.
Run terraform plan
to see the changes and preview the resources that will be created.
After that, run terraform apply
to create the resources.
You should see a similar output as follows:
Use the pulsarctl command to verify all the resources created. Make sure you have installed pulsarctl before running the command.
Copy the pulsarctl_command
output and run it in your terminal.
This command will set the context and get the topic details. It will verify the following resources are created:
sl-clu
sl-app-tenant
sl-app-ns
sl-app-topic
produce
and consume
permissions are granted to sl-app-sa
on the namespace sl-app-tenant/sl-app-ns
You should see the output as follows:
This tutorial demonstrates how to use StreamNative Terraform Provider to deploy a Serverless cluster and use the Pulsar Terraform Provider to provision Pulsar resources in the Serverless cluster.
This tutorial provisions the following resources (assuming we name the application as sl-app
):
sl-instance
).sl-clu
).sl-app-sa
.sl-app-apikey
.sl-app-tenant
sl-app-ns
and grants produce
and consume
permissions to the Service Account on the namespace.sl-app-topic
.The code examples is available in the examples/terraform/serverless folder.
Create a new directory anywhere you’d like for this project.
First, you need to create a service account called tf-runner
with Super Admin access. Please refer to Create a Service Account for details.
After you have created the service account, download the OAuth2 credentials file and save it as tf-runner.json
in the terraform-getting-started
folder that you created earlier.
Create a module folder streamnative_cloud
.
Create a variables.tf
file inside the streamnative_cloud
folder and add the following code snippet to prepare the variables. Remember to replace <your-organization-id>
with your StreamNative Cloud organization id.
<your-organization-id>
with it.sl-instance
.sl-clu
.sl-app
.Create a main.tf
file inside the streamnative_cloud
folder and add the following code snippet to create the resources.
Use the StreamNative Terraform Provider version 0.7.0
or later.
Go back to the root folder terraform-getting-started
.
You can copy the variables.tf
file from the streamnative_cloud
module folder.
Create a main.tf
file in the root folder and add the following code snippet to create the resources.
Before running the Terraform commands, you need to expose the following variables:
Please replace the above placeholders with your actual values:
<your-org-id>
: Your StreamNative Cloud organization ID<your-instance-name>
: A unique name for your Pulsar instance (e.g., “sl-instance”)<your-cluster-name>
: A unique name for your Pulsar cluster (e.g., “sl-clu”)<your-app-name>
: A unique name for your application (e.g., “sl-app”)An example of exposing the variables is as follows:
After exposing the variables, you can run the following Terraform commands to provision the resources.
First, initialize the Terraform working directory.
Secondly, validate the Terraform configuration files.
Since we use two providers in this example (the StreamNative Provider and the Pulsar Provider), we need to provision the resources in two steps. The Pulsar Provider resources depend on the StreamNative Provider resources being created first.
Run a targeted plan to see the changes and preview the resources that will be created.
After that, run a targeted apply to create the resources.
Run terraform plan
to see the changes and preview the resources that will be created.
After that, run terraform apply
to create the resources.
You should see a similar output as follows:
Use the pulsarctl command to verify all the resources created. Make sure you have installed pulsarctl before running the command.
Copy the pulsarctl_command
output and run it in your terminal.
This command will set the context and get the topic details. It will verify the following resources are created:
sl-clu
sl-app-tenant
sl-app-ns
sl-app-topic
produce
and consume
permissions are granted to sl-app-sa
on the namespace sl-app-tenant/sl-app-ns
You should see the output as follows: