Skip to content

Commit 66033cb

Browse files
committed
wip - first implementation draft
1 parent 06474fc commit 66033cb

23 files changed

Lines changed: 3300 additions & 857 deletions

README.md

Lines changed: 300 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,300 @@
1-
# Terraform Spiceai Provider
1+
# Terraform Provider for Spice.ai
2+
3+
This Terraform provider allows you to manage [Spice.ai](https://spice.ai) resources including apps, app configurations, and deployments.
4+
5+
## Requirements
6+
7+
- [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
10+
11+
## Installation
12+
13+
### From Terraform Registry (Recommended)
14+
15+
```hcl
16+
terraform {
17+
required_providers {
18+
spiceai = {
19+
source = "spiceai/spiceai"
20+
version = "~> 0.1"
21+
}
22+
}
23+
}
24+
```
25+
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+
36+
## Authentication
37+
38+
The provider uses OAuth client credentials to authenticate with the Spice.ai API. You can obtain these credentials from your Spice.ai account.
39+
40+
### Configuration Options
41+
42+
```hcl
43+
provider "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
48+
}
49+
```
50+
51+
### Environment Variables
52+
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.
65+
66+
```hcl
67+
resource "spiceai_app" "example" {
68+
name = "my-app"
69+
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
96+
97+
spicepod = <<-YAML
98+
version: v1beta1
99+
kind: Spicepod
100+
name: my-app
101+
datasets:
102+
- name: my_dataset
103+
from: s3://bucket/path/
104+
YAML
105+
106+
image_tag = "latest"
107+
replicas = 2
108+
node_group = "default"
109+
region = "us-east-1"
110+
storage_claim_size_gb = 10.0
111+
production_branch = "main"
112+
}
113+
```
114+
115+
#### Attributes
116+
117+
| Name | Type | Required | Description |
118+
|------|------|----------|-------------|
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 |
122+
| `replicas` | int | No | Number of replicas (1-10) |
123+
| `node_group` | string | No | Node group for deployment |
124+
| `region` | string | No | Deployment region |
125+
| `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 |
129+
130+
### spiceai_deployment
131+
132+
Creates a deployment for a Spice.ai app.
133+
134+
```hcl
135+
resource "spiceai_deployment" "example" {
136+
app_id = spiceai_app.example.id
137+
138+
# Optional overrides
139+
image_tag = "v0.18.0"
140+
replicas = 2
141+
branch = "main"
142+
commit_sha = "abc123def456"
143+
commit_message = "Deploy from Terraform"
144+
debug = false
145+
146+
depends_on = [spiceai_app_config.example]
147+
}
148+
```
149+
150+
#### Attributes
151+
152+
| Name | Type | Required | Description |
153+
|------|------|----------|-------------|
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) |
161+
162+
#### Read-Only Attributes
163+
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
170+
171+
> **Note:** Deployments are immutable. Any changes to deployment parameters will trigger a replacement (new deployment).
172+
173+
## Data Sources
174+
175+
### spiceai_app
176+
177+
Retrieves details about an existing app.
178+
179+
```hcl
180+
data "spiceai_app" "example" {
181+
id = "12345"
182+
}
183+
184+
output "app_name" {
185+
value = data.spiceai_app.example.name
186+
}
187+
```
188+
189+
### spiceai_apps
190+
191+
Lists all apps in the organization.
192+
193+
```hcl
194+
data "spiceai_apps" "all" {}
195+
196+
output "app_names" {
197+
value = [for app in data.spiceai_apps.all.apps : app.name]
198+
}
199+
```
200+
201+
## Example Usage
202+
203+
```hcl
204+
terraform {
205+
required_providers {
206+
spiceai = {
207+
source = "spiceai/spiceai"
208+
version = "~> 0.1"
209+
}
210+
}
211+
}
212+
213+
provider "spiceai" {}
214+
215+
# Create an app
216+
resource "spiceai_app" "example" {
217+
name = "my-terraform-app"
218+
description = "Managed by Terraform"
219+
visibility = "private"
220+
}
221+
222+
# Configure the app with a spicepod
223+
resource "spiceai_app_config" "example" {
224+
app_id = spiceai_app.example.id
225+
226+
spicepod = <<-YAML
227+
version: v1beta1
228+
kind: Spicepod
229+
name: my-terraform-app
230+
datasets:
231+
- name: taxi_trips
232+
from: s3://spiceai-demo-datasets/taxi_trips/2024/
233+
params:
234+
file_format: parquet
235+
YAML
236+
237+
replicas = 1
238+
}
239+
240+
# Deploy the app
241+
resource "spiceai_deployment" "example" {
242+
app_id = spiceai_app.example.id
243+
244+
depends_on = [spiceai_app_config.example]
245+
}
246+
247+
output "app_id" {
248+
value = spiceai_app.example.id
249+
}
250+
251+
output "deployment_status" {
252+
value = spiceai_deployment.example.status
253+
}
254+
```
255+
256+
## Import
257+
258+
Resources can be imported using their IDs:
259+
260+
```bash
261+
# Import an app
262+
terraform import spiceai_app.example 12345
263+
264+
# Import an app config (uses app ID)
265+
terraform import spiceai_app_config.example 12345
266+
267+
# Import a deployment (format: app_id/deployment_id)
268+
terraform import spiceai_deployment.example 12345/67890
269+
```
270+
271+
## Development
272+
273+
### Building
274+
275+
```bash
276+
go build -o terraform-provider-spiceai
277+
```
278+
279+
### Testing
280+
281+
```bash
282+
go test ./...
283+
```
284+
285+
### Running Locally
286+
287+
Create a `~/.terraformrc` file with a dev override:
288+
289+
```hcl
290+
provider_installation {
291+
dev_overrides {
292+
"spiceai/spiceai" = "/path/to/terraform-provider-spiceai"
293+
}
294+
direct {}
295+
}
296+
```
297+
298+
## License
299+
300+
MPL-2.0. See [LICENSE](LICENSE) file.

0 commit comments

Comments
 (0)