11# Terraform Provider for Spice.ai
22
3- This Terraform provider allows you to manage [ Spice.ai Cloud] ( https://spice.ai ) resources including apps and deployments.
3+ [ ![ Terraform Registry] ( https://img.shields.io/badge/terraform-registry-blueviolet?logo=terraform )] ( https://registry.terraform.io/providers/spiceai/spiceai/latest )
4+ [ ![ CI] ( https://github.com/spiceai/terraform-provider-spiceai/actions/workflows/test.yml/badge.svg )] ( https://github.com/spiceai/terraform-provider-spiceai/actions/workflows/test.yml )
5+ [ ![ License: MPL-2.0] ( https://img.shields.io/badge/License-MPL--2.0-brightgreen.svg )] ( LICENSE )
6+
7+ Terraform provider for managing [ Spice.ai Cloud] ( https://spice.ai ) resources.
48
59## Requirements
610
711- [ Terraform] ( https://www.terraform.io/downloads.html ) >= 1.0 (or [ OpenTofu] ( https://opentofu.org/ ) >= 1.0)
8- - [ Go] ( https://golang.org/doc/install ) >= 1.21 (for building from source)
9- - A Spice.ai account with OAuth client credentials
12+ - A [ Spice.ai Cloud] ( https://spice.ai ) account with [ OAuth client credentials] ( https://docs.spice.ai/api/management#id-2.-oauth-2.0-client-credentials )
1013
1114## Installation
1215
13- ### From Terraform Registry (Recommended)
16+ Add the provider to your Terraform configuration:
1417
1518``` hcl
1619terraform {
@@ -23,177 +26,29 @@ terraform {
2326}
2427```
2528
26- ### Building from Source
27-
28- ``` bash
29- git clone https://github.com/spiceai/terraform-provider-spiceai.git
30- cd terraform-provider-spiceai
31- go build -o terraform-provider-spiceai
32- ```
33-
34- Then move the binary to your Terraform plugins directory or use a [ dev override] ( https://developer.hashicorp.com/terraform/cli/config/config-file#development-overrides-for-provider-developers ) .
35-
3629## Authentication
3730
38- The provider uses OAuth client credentials to authenticate with the Spice.ai API. You can obtain these credentials from your Spice.ai account .
31+ The provider authenticates using OAuth 2.0 client credentials. Create an OAuth client in [ Spice.ai Cloud ] ( https://docs.spice.ai/api/management#id-2.-oauth-2.0-client-credentials ) to obtain a client ID and secret .
3932
40- ### Configuration Options
33+ ### Configuration
4134
4235``` hcl
4336provider "spiceai" {
44- client_id = "your-client-id" # Or use SPICEAI_CLIENT_ID env var
45- client_secret = "your-client-secret" # Or use SPICEAI_CLIENT_SECRET env var
46- api_endpoint = "https://api.spice.ai" # Optional
47- oauth_endpoint = "https://spice.ai/api/oauth/token" # Optional
37+ client_id = var.spiceai_client_id # Or set SPICEAI_CLIENT_ID env var
38+ client_secret = var.spiceai_client_secret # Or set SPICEAI_CLIENT_SECRET env var
4839}
4940```
5041
5142### Environment Variables
5243
53- | Variable | Description |
54- | ----------| -------------|
55- | ` SPICEAI_CLIENT_ID ` | OAuth client ID |
56- | ` SPICEAI_CLIENT_SECRET ` | OAuth client secret |
57- | ` SPICEAI_API_ENDPOINT ` | API endpoint (default: ` https://api.spice.ai ` ) |
58- | ` SPICEAI_OAUTH_ENDPOINT ` | OAuth token endpoint (default: ` https://spice.ai/api/oauth/token ` ) |
59-
60- ## Resources
61-
62- ### spiceai_app
63-
64- Manages a Spice.ai app and its configuration. This resource combines app creation with spicepod and runtime configuration.
65-
66- ``` hcl
67- resource "spiceai_app" "example" {
68- name = "my-app"
69- description = "My Spice.ai application"
70- visibility = "private"
71-
72- # Spicepod configuration (YAML or JSON)
73- spicepod = <<-YAML
74- version: v1beta1
75- kind: Spicepod
76- name: my-app
77- datasets:
78- - name: taxi_trips
79- from: s3://spiceai-demo-datasets/taxi_trips/2024/
80- params:
81- file_format: parquet
82- YAML
83-
84- # Runtime configuration
85- image_tag = "latest"
86- replicas = 2
87- node_group = "default"
88- region = "us-east-1"
89- storage_claim_size_gb = 10.0
90- production_branch = "main"
91- }
92- ```
93-
94- #### Arguments
95-
96- | Name | Type | Required | Description |
97- | ------| ------| ----------| -------------|
98- | ` name ` | string | Yes | The name of the app (min 4 chars, alphanumeric and hyphens only). Changing this forces a new resource. |
99- | ` description ` | string | No | A description of the app |
100- | ` visibility ` | string | No | The visibility (` public ` or ` private ` , default: ` private ` ) |
101- | ` spicepod ` | string | No | Spicepod configuration (YAML or JSON string) |
102- | ` image_tag ` | string | No | Spice.ai runtime image tag (e.g., ` latest ` , ` v0.18.0 ` ) |
103- | ` replicas ` | int | No | Number of replicas (1-10) |
104- | ` node_group ` | string | No | Node group for deployment |
105- | ` region ` | string | No | Deployment region |
106- | ` storage_claim_size_gb ` | float | No | Storage claim size in GB |
107- | ` production_branch ` | string | No | Production branch name for git-based deployments |
108-
109- #### Read-Only Attributes
110-
111- | Name | Description |
112- | ------| -------------|
113- | ` id ` | The unique identifier of the app |
114- | ` created_at ` | Timestamp when the app was created |
115- | ` api_key ` | The API key for the app (sensitive) |
116-
117- ### spiceai_deployment
118-
119- Creates a deployment for a Spice.ai app. Deployments are immutable - any changes will trigger creation of a new deployment.
120-
121- ``` hcl
122- resource "spiceai_deployment" "example" {
123- app_id = spiceai_app.example.id
124-
125- # Optional overrides
126- image_tag = "v0.18.0"
127- replicas = 2
128- branch = "main"
129- commit_sha = "abc123def456"
130- commit_message = "Deploy from Terraform"
131- debug = false
132- }
133- ```
134-
135- #### Arguments
136-
137- | Name | Type | Required | Description |
138- | ------| ------| ----------| -------------|
139- | ` app_id ` | string | Yes | The ID of the app to deploy. Changing this forces a new deployment. |
140- | ` image_tag ` | string | No | Override image tag for this deployment. Changing this forces a new deployment. |
141- | ` replicas ` | int | No | Override replicas (1-10). Changing this forces a new deployment. |
142- | ` branch ` | string | No | Git branch name. Changing this forces a new deployment. |
143- | ` commit_sha ` | string | No | Git commit SHA. Changing this forces a new deployment. |
144- | ` commit_message ` | string | No | Git commit message. Changing this forces a new deployment. |
145- | ` debug ` | bool | No | Enable debug mode (default: false). Changing this forces a new deployment. |
146-
147- #### Read-Only Attributes
148-
149- | Name | Description |
150- | ------| -------------|
151- | ` id ` | The unique identifier of the deployment |
152- | ` status ` | Current status (` queued ` , ` deploying ` , ` running ` , ` failed ` , ` stopped ` ) |
153- | ` created_at ` | Timestamp when the deployment was created |
154- | ` started_at ` | Timestamp when the deployment started running |
155- | ` finished_at ` | Timestamp when the deployment finished |
156- | ` error_message ` | Error message if deployment failed |
157-
158- > ** Note:** Deployments are immutable. Any changes to deployment parameters will trigger a replacement (new deployment).
159-
160- ## Data Sources
161-
162- ### spiceai_app
163-
164- Retrieves details about an existing app by ID.
165-
166- ``` hcl
167- data "spiceai_app" "example" {
168- id = "12345"
169- }
170-
171- output "app_name" {
172- value = data.spiceai_app.example.name
173- }
174-
175- output "app_replicas" {
176- value = data.spiceai_app.example.replicas
177- }
178- ```
179-
180- ### spiceai_apps
181-
182- Lists all apps in the organization.
183-
184- ``` hcl
185- data "spiceai_apps" "all" {}
186-
187- output "app_names" {
188- value = [for app in data.spiceai_apps.all.apps : app.name]
189- }
190-
191- output "private_apps" {
192- value = [for app in data.spiceai_apps.all.apps : app.name if app.visibility == "private"]
193- }
194- ```
44+ | Variable | Description |
45+ | ------------------------------ | ------------------------------------------------------------------ |
46+ | ` SPICEAI_CLIENT_ID ` | OAuth client ID |
47+ | ` SPICEAI_CLIENT_SECRET ` | OAuth client secret |
48+ | ` SPICEAI_API_ENDPOINT ` | API endpoint (default: ` https://api.spice.ai ` ) |
49+ | ` SPICEAI_OAUTH_ENDPOINT ` | OAuth token endpoint (default: ` https://spice.ai/api/oauth/token ` ) |
19550
196- ## Example Usage
51+ ## Example
19752
19853``` hcl
19954terraform {
@@ -205,96 +60,23 @@ terraform {
20560 }
20661}
20762
208- provider "spiceai" {
209- # Credentials are read from environment variables:
210- # SPICEAI_CLIENT_ID and SPICEAI_CLIENT_SECRET
211- }
212-
213- # Create an app with configuration
214- resource "spiceai_app" "example" {
215- name = "my-terraform-app"
216- description = "Managed by Terraform"
217- visibility = "private"
218-
219- spicepod = <<-YAML
220- version: v1beta1
221- kind: Spicepod
222- name: my-terraform-app
223- datasets:
224- - name: taxi_trips
225- from: s3://spiceai-demo-datasets/taxi_trips/2024/
226- params:
227- file_format: parquet
228- YAML
229-
230- image_tag = "latest"
231- replicas = 1
232- }
233-
234- # Deploy the app
235- resource "spiceai_deployment" "example" {
236- app_id = spiceai_app.example.id
237- }
238-
239- output "app_id" {
240- value = spiceai_app.example.id
241- }
242-
243- output "app_api_key" {
244- value = spiceai_app.example.api_key
245- sensitive = true
63+ resource "spiceai_app" "app" {
64+ name = "my-spice-cloud-app"
65+ cname = "us-west-2-prod-aws-data"
24666}
24767
248- output "deployment_status " {
249- value = spiceai_deployment.example.status
68+ resource "spiceai_deployment" "deploy " {
69+ app_id = spiceai_app.app.id
25070}
25171```
25272
253- ## Import
254-
255- Resources can be imported using their IDs:
256-
257- ``` bash
258- # Import an app
259- terraform import spiceai_app.example 12345
260-
261- # Import a deployment (format: app_id/deployment_id)
262- terraform import spiceai_deployment.example 12345/67890
263- ```
264-
265- ## Development
266-
267- ### Building
268-
269- ``` bash
270- go build -o terraform-provider-spiceai
271- ```
272-
273- ### Testing
73+ ## Documentation
27474
275- ``` bash
276- go test ./...
277- ```
278-
279- ### Running Locally
280-
281- Create a ` ~/.terraformrc ` file with a dev override:
282-
283- ``` hcl
284- provider_installation {
285- dev_overrides {
286- "spiceai/spiceai" = "/path/to/terraform-provider-spiceai"
287- }
288- direct {}
289- }
290- ```
75+ For detailed documentation on all resources, data sources, and their attributes, see the [ docs] ( docs/ ) directory:
29176
292- ### Generating Documentation
293-
294- ``` bash
295- go generate ./...
296- ```
77+ - ** Resources:** [ spiceai_app] ( docs/resources/app.md ) · [ spiceai_deployment] ( docs/resources/deployment.md ) · [ spiceai_secret] ( docs/resources/secret.md ) · [ spiceai_member] ( docs/resources/member.md )
78+ - ** Data Sources:** [ spiceai_app] ( docs/data-sources/app.md ) · [ spiceai_apps] ( docs/data-sources/apps.md ) · [ spiceai_regions] ( docs/data-sources/regions.md ) · [ spiceai_secrets] ( docs/data-sources/secrets.md ) · [ spiceai_members] ( docs/data-sources/members.md ) · [ spiceai_api_keys] ( docs/data-sources/api_keys.md ) · [ spiceai_container_images] ( docs/data-sources/container_images.md )
29779
29880## License
29981
300- MPL-2.0. See [ LICENSE] ( LICENSE ) file.
82+ MPL-2.0. See [ LICENSE] ( LICENSE ) file.
0 commit comments