> ## Documentation Index
> Fetch the complete documentation index at: https://docs.streamnative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure StreamNative Terraform Provider

## Install the Provider

You can install the StreamNative Terraform Provider using the following code snippet.

```hcl theme={null}
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](/cloud/security/authentication/service-accounts/manage-service-accounts#create-a-service-account) and [download the OAuth2 credentials file](/cloud/security/authentication/service-accounts/use-oauth/oauth-overview#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:

```hcl theme={null}
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](https://support.hashicorp.com/hc/en-us/articles/4547786359571-Reading-and-using-environment-variables-in-Terraform-runs) or in the Terraform configuration file.

```hcl theme={null}
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](https://registry.terraform.io/providers/streamnative/streamnative/latest/docs/data-sources/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.

```hcl theme={null}
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:

```sh theme={null}
terraform init
```

You can then run the following command to ensure the configuration is syntactically valid and internally consistent:

```sh theme={null}
terraform validate
```

Apply the configuration:

```sh theme={null}
terraform apply
```

You should be able to see a similar output as follows:

```sh theme={null}
...

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.

```hcl theme={null}
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
}
```
