Skip to content

Commit a850fee

Browse files
authored
Merge pull request #3 from spicehq/evgenii/2025-12-10/refactor
Refactor provider according to API Spec
2 parents a159db5 + eaedba1 commit a850fee

38 files changed

Lines changed: 4065 additions & 1241 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ website/vendor
3535
*.winfile eol=crlf
3636

3737
.env
38+
39+
# binary
40+
terraform-provider-spiceai

README.md

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terraform Provider for Spice.ai
22

3-
This Terraform provider allows you to manage [Spice.ai](https://spice.ai) resources including apps, app configurations, and deployments.
3+
This Terraform provider allows you to manage [Spice.ai Cloud](https://spice.ai) resources including apps and deployments.
44

55
## Requirements
66

@@ -61,75 +61,62 @@ provider "spiceai" {
6161

6262
### spiceai_app
6363

64-
Manages a Spice.ai app.
64+
Manages a Spice.ai app and its configuration. This resource combines app creation with spicepod and runtime configuration.
6565

6666
```hcl
6767
resource "spiceai_app" "example" {
6868
name = "my-app"
6969
description = "My Spice.ai application"
70-
visibility = "private" # or "public"
71-
}
72-
```
73-
74-
#### Attributes
75-
76-
| Name | Type | Required | Description |
77-
|------|------|----------|-------------|
78-
| `name` | string | Yes | The name of the app (min 4 chars, alphanumeric and hyphens only) |
79-
| `description` | string | No | A description of the app |
80-
| `visibility` | string | No | The visibility (`public` or `private`, default: `private`) |
81-
82-
#### Read-Only Attributes
83-
84-
- `id` - The unique identifier of the app
85-
- `region` - The region where the app is deployed
86-
- `created_at` - Timestamp when the app was created
87-
- `api_key` - The API key for the app (sensitive)
88-
89-
### spiceai_app_config
90-
91-
Applies configuration to a Spice.ai app.
92-
93-
```hcl
94-
resource "spiceai_app_config" "example" {
95-
app_id = spiceai_app.example.id
70+
visibility = "private"
9671
72+
# Spicepod configuration (YAML or JSON)
9773
spicepod = <<-YAML
9874
version: v1beta1
9975
kind: Spicepod
10076
name: my-app
10177
datasets:
102-
- name: my_dataset
103-
from: s3://bucket/path/
78+
- name: taxi_trips
79+
from: s3://spiceai-demo-datasets/taxi_trips/2024/
80+
params:
81+
file_format: parquet
10482
YAML
10583
106-
image_tag = "latest"
107-
replicas = 2
108-
node_group = "default"
109-
region = "us-east-1"
84+
# Runtime configuration
85+
image_tag = "latest"
86+
replicas = 2
87+
node_group = "default"
88+
region = "us-east-1"
11089
storage_claim_size_gb = 10.0
111-
production_branch = "main"
90+
production_branch = "main"
11291
}
11392
```
11493

115-
#### Attributes
94+
#### Arguments
11695

11796
| Name | Type | Required | Description |
11897
|------|------|----------|-------------|
119-
| `app_id` | string | Yes | The ID of the app to configure |
120-
| `spicepod` | string | No | Spicepod configuration (YAML or JSON) |
121-
| `image_tag` | string | No | Spice.ai runtime image tag |
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`) |
122103
| `replicas` | int | No | Number of replicas (1-10) |
123104
| `node_group` | string | No | Node group for deployment |
124105
| `region` | string | No | Deployment region |
125106
| `storage_claim_size_gb` | float | No | Storage claim size in GB |
126-
| `production_branch` | string | No | Production branch name |
127-
| `description` | string | No | App description |
128-
| `visibility` | string | No | App visibility |
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) |
129116

130117
### spiceai_deployment
131118

132-
Creates a deployment for a Spice.ai app.
119+
Creates a deployment for a Spice.ai app. Deployments are immutable - any changes will trigger creation of a new deployment.
133120

134121
```hcl
135122
resource "spiceai_deployment" "example" {
@@ -142,39 +129,39 @@ resource "spiceai_deployment" "example" {
142129
commit_sha = "abc123def456"
143130
commit_message = "Deploy from Terraform"
144131
debug = false
145-
146-
depends_on = [spiceai_app_config.example]
147132
}
148133
```
149134

150-
#### Attributes
135+
#### Arguments
151136

152137
| Name | Type | Required | Description |
153138
|------|------|----------|-------------|
154-
| `app_id` | string | Yes | The ID of the app to deploy |
155-
| `image_tag` | string | No | Override image tag for this deployment |
156-
| `replicas` | int | No | Override replicas (1-10) |
157-
| `branch` | string | No | Git branch name |
158-
| `commit_sha` | string | No | Git commit SHA |
159-
| `commit_message` | string | No | Git commit message |
160-
| `debug` | bool | No | Enable debug mode (default: false) |
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. |
161146

162147
#### Read-Only Attributes
163148

164-
- `id` - The unique identifier of the deployment
165-
- `status` - Current status (`queued`, `deploying`, `running`, `failed`, `stopped`)
166-
- `created_at` - Timestamp when the deployment was created
167-
- `started_at` - Timestamp when the deployment started
168-
- `finished_at` - Timestamp when the deployment finished
169-
- `error_message` - Error message if deployment failed
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 |
170157

171158
> **Note:** Deployments are immutable. Any changes to deployment parameters will trigger a replacement (new deployment).
172159
173160
## Data Sources
174161

175162
### spiceai_app
176163

177-
Retrieves details about an existing app.
164+
Retrieves details about an existing app by ID.
178165

179166
```hcl
180167
data "spiceai_app" "example" {
@@ -184,6 +171,10 @@ data "spiceai_app" "example" {
184171
output "app_name" {
185172
value = data.spiceai_app.example.name
186173
}
174+
175+
output "app_replicas" {
176+
value = data.spiceai_app.example.replicas
177+
}
187178
```
188179

189180
### spiceai_apps
@@ -196,6 +187,10 @@ data "spiceai_apps" "all" {}
196187
output "app_names" {
197188
value = [for app in data.spiceai_apps.all.apps : app.name]
198189
}
190+
191+
output "private_apps" {
192+
value = [for app in data.spiceai_apps.all.apps : app.name if app.visibility == "private"]
193+
}
199194
```
200195

201196
## Example Usage
@@ -210,18 +205,16 @@ terraform {
210205
}
211206
}
212207
213-
provider "spiceai" {}
208+
provider "spiceai" {
209+
# Credentials are read from environment variables:
210+
# SPICEAI_CLIENT_ID and SPICEAI_CLIENT_SECRET
211+
}
214212
215-
# Create an app
213+
# Create an app with configuration
216214
resource "spiceai_app" "example" {
217215
name = "my-terraform-app"
218216
description = "Managed by Terraform"
219217
visibility = "private"
220-
}
221-
222-
# Configure the app with a spicepod
223-
resource "spiceai_app_config" "example" {
224-
app_id = spiceai_app.example.id
225218
226219
spicepod = <<-YAML
227220
version: v1beta1
@@ -232,22 +225,26 @@ resource "spiceai_app_config" "example" {
232225
from: s3://spiceai-demo-datasets/taxi_trips/2024/
233226
params:
234227
file_format: parquet
235-
YAML
228+
YAML
236229
237-
replicas = 1
230+
image_tag = "latest"
231+
replicas = 1
238232
}
239233
240234
# Deploy the app
241235
resource "spiceai_deployment" "example" {
242236
app_id = spiceai_app.example.id
243-
244-
depends_on = [spiceai_app_config.example]
245237
}
246238
247239
output "app_id" {
248240
value = spiceai_app.example.id
249241
}
250242
243+
output "app_api_key" {
244+
value = spiceai_app.example.api_key
245+
sensitive = true
246+
}
247+
251248
output "deployment_status" {
252249
value = spiceai_deployment.example.status
253250
}
@@ -261,9 +258,6 @@ Resources can be imported using their IDs:
261258
# Import an app
262259
terraform import spiceai_app.example 12345
263260

264-
# Import an app config (uses app ID)
265-
terraform import spiceai_app_config.example 12345
266-
267261
# Import a deployment (format: app_id/deployment_id)
268262
terraform import spiceai_deployment.example 12345/67890
269263
```
@@ -295,6 +289,12 @@ provider_installation {
295289
}
296290
```
297291

292+
### Generating Documentation
293+
294+
```bash
295+
go generate ./...
296+
```
297+
298298
## License
299299

300300
MPL-2.0. See [LICENSE](LICENSE) file.

docs/data-sources/api_keys.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "spiceai_api_keys Data Source - spiceai"
4+
subcategory: ""
5+
description: |-
6+
Retrieves the API keys for a Spice.ai app. Each app has two API keys to support key rotation.
7+
---
8+
9+
# spiceai_api_keys (Data Source)
10+
11+
Retrieves the API keys for a Spice.ai app. Each app has two API keys to support key rotation.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `app_id` (String) The unique identifier of the app.
21+
22+
### Read-Only
23+
24+
- `api_key` (String, Sensitive) The primary API key for the app.
25+
- `api_key_2` (String, Sensitive) The secondary API key for the app.

docs/data-sources/app.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,57 @@
33
page_title: "spiceai_app Data Source - spiceai"
44
subcategory: ""
55
description: |-
6-
Retrieves details about a Spice.ai app by its ID.
6+
Retrieves details about an existing Spice.ai app by its ID.
77
---
88

99
# spiceai_app (Data Source)
1010

11-
Retrieves details about a Spice.ai app by its ID.
11+
Retrieves details about an existing Spice.ai app by its ID.
1212

1313
## Example Usage
1414

1515
```terraform
16+
# Get details about an existing app by ID
1617
data "spiceai_app" "example" {
1718
id = "12345"
1819
}
1920
21+
# Use data from an existing app
2022
output "app_name" {
21-
value = data.spiceai_app.example.name
23+
description = "The name of the app"
24+
value = data.spiceai_app.example.name
2225
}
2326
27+
output "app_visibility" {
28+
description = "The visibility of the app"
29+
value = data.spiceai_app.example.visibility
30+
}
31+
32+
output "app_region" {
33+
description = "The region where the app is deployed"
34+
value = data.spiceai_app.example.region
35+
}
36+
37+
output "app_replicas" {
38+
description = "The number of replicas configured for the app"
39+
value = data.spiceai_app.example.replicas
40+
}
41+
42+
output "app_image_tag" {
43+
description = "The runtime image tag for the app"
44+
value = data.spiceai_app.example.image_tag
45+
}
46+
47+
# Reference an app created by another resource
48+
data "spiceai_app" "from_resource" {
49+
id = spiceai_app.example.id
50+
}
51+
52+
# Use data source to get app API key for other configurations
2453
output "app_api_key" {
25-
value = data.spiceai_app.example.api_key
26-
sensitive = true
54+
description = "The API key for the app"
55+
value = data.spiceai_app.from_resource.api_key
56+
sensitive = true
2757
}
2858
```
2959

@@ -37,21 +67,15 @@ output "app_api_key" {
3767
### Read-Only
3868

3969
- `api_key` (String, Sensitive) The API key for the app.
40-
- `config` (Attributes) The configuration of the app. (see [below for nested schema](#nestedatt--config))
70+
- `cluster_id` (String) The Kubernetes cluster identifier where the app is deployed.
4171
- `created_at` (String) The timestamp when the app was created.
4272
- `description` (String) A description of the app.
73+
- `image_tag` (String) The Spice.ai runtime image tag.
4374
- `name` (String) The name of the app.
75+
- `node_group` (String) The node group for the app.
4476
- `production_branch` (String) The production branch for the app.
4577
- `region` (String) The region where the app is deployed.
46-
- `visibility` (String) The visibility of the app (public or private).
47-
48-
<a id="nestedatt--config"></a>
49-
### Nested Schema for `config`
50-
51-
Read-Only:
52-
53-
- `image_tag` (String) The Spice.ai runtime image tag.
54-
- `node_group` (String) The node group for the app.
5578
- `replicas` (Number) The number of replicas.
5679
- `spicepod` (String) The spicepod configuration as a JSON string.
5780
- `storage_claim_size_gb` (Number) The storage claim size in GB.
81+
- `visibility` (String) The visibility of the app (`public` or `private`).

0 commit comments

Comments
 (0)