- Configure
Configure StreamNative Terraform Provider
Install the Provider
You can install the StreamNative Terraform Provider using the following code snippet.
terraform {
required_providers {
streamnative = {
source = "streamnative/streamnative"
version = ">= 0.7.0"
}
}
}
Configure the Provider
Once you have added the provider to your Terraform configuration, you need to configure the provider with your StreamNative Cloud credentials.
StreamNative Cloud currently only supports OAuth2 authentication. You need to create a service account with Super Admin access and download the OAuth2 credentials file. Assume your service account name is test-sa
and the OAuth2 key file is stored in /path/to/your/service/account/key.json
. You can configure the provider as follows:
provider "streamnative" {
key_file_path = "/path/to/your/service/account/key.json"
}
Alternatively, if you can't access file in your Terraform setup, you can choose to configure the provider with client_id
and client_secret
. You can put the actual values of client_id
and client_secret
as system environment variables or in the Terraform configuration file.
provider "streamnative" {
client_id = "<client-id>"
client_secret = "<client-secret>"
}
Validate the Configuration
In order to validate the provider is configured correctly, you can try to access the Service Account data source of the SA you used to configure the provider. Below is an example of how to do so. You can replace <organization>
and <service-account-name>
with your actual values.
data "streamnative_service_account" "test-sa" {
organization = "<organization>"
name = "<service-account-name>"
}
output "service_account_id" {
value = data.streamnative_service_account.test-sa
}
After you have configured the provider and added the code snippet above to 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 apply
You should be able to see a similar output as follows:
...
service_account_id = {
"admin" = true
"id" = "<organization>/<service-account-name>"
"name" = "<service-account-name>"
"organization" = "<organization>"
"private_key_data" = "<private-key-data>"
}
Full Code Example
Below is the full code example of how to configure the StreamNative Terraform Provider.
terraform {
required_providers {
streamnative = {
source = "streamnative/streamnative"
}
}
}
provider "streamnative" {
client_id = "<client-id>"
client_secret = "<client-secret>"
}
data "streamnative_service_account" "test-sa" {
organization = "<organization>"
name = "<service-account-name>"
}
output "service_account_id" {
value = data.streamnative_service_account.test-sa
}