Skip to content

Commit 69ecda8

Browse files
committed
update example
1 parent e0cc63e commit 69ecda8

4 files changed

Lines changed: 101 additions & 77 deletions

File tree

examples/provider/provider.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ provider "spiceai" {
1919

2020
# Optional: Custom API endpoint (defaults to https://api.spice.ai)
2121
# api_endpoint = "https://api.spice.ai"
22+
api_endpoint = "https://dev-api.spice.ai"
2223

2324
# Optional: Custom OAuth endpoint (defaults to https://spice.ai/api/oauth/token)
2425
# oauth_endpoint = "https://spice.ai/api/oauth/token"
26+
oauth_endpoint = "https://dev.spice.ai/api/oauth/token"
2527
}
2628

2729
# Variables for credentials
@@ -42,4 +44,4 @@ variable "spiceai_client_secret" {
4244
# # Credentials are automatically read from:
4345
# # - SPICEAI_CLIENT_ID
4446
# # - SPICEAI_CLIENT_SECRET
45-
# }
47+
# }

examples/test/main.tf

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,93 @@ terraform {
88
}
99
}
1010

11-
# Provider configuration using environment variables
12-
# Set SPICEAI_CLIENT_ID and SPICEAI_CLIENT_SECRET before running
13-
provider "spiceai" {}
11+
# Provider configuration
12+
provider "spiceai" {
13+
# Optional: Custom API endpoint (defaults to https://api.spice.ai)
14+
# api_endpoint = "https://api.spice.ai"
15+
api_endpoint = "https://dev-api.spice.ai"
16+
17+
# Optional: Custom OAuth endpoint (defaults to https://spice.ai/api/oauth/token)
18+
# oauth_endpoint = "https://spice.ai/api/oauth/token"
19+
oauth_endpoint = "https://dev.spice.ai/api/oauth/token"
20+
21+
# Optional: Vercel protection bypass token for preview deployments
22+
# vercel_protection_bypass = "cgWEL8HZ32wB6byCBh96gQepmx4HskWd"
23+
}
1424

1525
# Create a test app with full configuration
1626
resource "spiceai_app" "test" {
1727
name = "terraform-test-app"
1828
description = "Test app for Terraform provider validation"
1929
visibility = "private"
2030

21-
# Spicepod configuration
22-
spicepod = <<-YAML
23-
version: v1beta1
24-
kind: Spicepod
25-
name: terraform-test-app
26-
datasets:
27-
- name: test_dataset
28-
from: s3://spiceai-demo-datasets/taxi_trips/2024/
29-
params:
30-
file_format: parquet
31-
YAML
32-
33-
# Runtime configuration
34-
image_tag = "latest"
35-
replicas = 1
36-
production_branch = "main"
31+
# # Spicepod configuration
32+
# spicepod = <<-YAML
33+
# version: v1beta1
34+
# kind: Spicepod
35+
# name: terraform-test-app
36+
# datasets:
37+
# - name: test_dataset
38+
# from: s3://spiceai-demo-datasets/taxi_trips/2024/
39+
# params:
40+
# file_format: parquet
41+
# YAML
42+
43+
# # Runtime configuration
44+
# image_tag = "latest"
45+
# replicas = 1
46+
# production_branch = "main"
3747
}
3848

39-
# Create a deployment for the test app
40-
resource "spiceai_deployment" "test" {
41-
app_id = spiceai_app.test.id
49+
# # Create a deployment for the test app
50+
# resource "spiceai_deployment" "test" {
51+
# app_id = spiceai_app.test.id
4252

43-
# Use app defaults
44-
debug = false
45-
}
53+
# # Use app defaults
54+
# debug = false
55+
# }
4656

47-
# Data source: Read back the app we created
48-
data "spiceai_app" "test" {
49-
id = spiceai_app.test.id
50-
}
57+
# # Data source: Read back the app we created
58+
# data "spiceai_app" "test" {
59+
# id = spiceai_app.test.id
60+
# }
5161

52-
# Data source: List all apps
53-
data "spiceai_apps" "all" {}
62+
# # Data source: List all apps
63+
# data "spiceai_apps" "all" {}
5464

55-
# Outputs for verification
56-
output "app_id" {
57-
description = "The ID of the test app"
58-
value = spiceai_app.test.id
59-
}
65+
# # Outputs for verification
66+
# output "app_id" {
67+
# description = "The ID of the test app"
68+
# value = spiceai_app.test.id
69+
# }
6070

61-
output "app_name" {
62-
description = "The name of the test app"
63-
value = spiceai_app.test.name
64-
}
71+
# output "app_name" {
72+
# description = "The name of the test app"
73+
# value = spiceai_app.test.name
74+
# }
6575

66-
output "app_api_key" {
67-
description = "The API key for the test app"
68-
value = spiceai_app.test.api_key
69-
sensitive = true
70-
}
76+
# output "app_api_key" {
77+
# description = "The API key for the test app"
78+
# value = spiceai_app.test.api_key
79+
# sensitive = true
80+
# }
7181

72-
output "deployment_id" {
73-
description = "The ID of the deployment"
74-
value = spiceai_deployment.test.id
75-
}
82+
# output "deployment_id" {
83+
# description = "The ID of the deployment"
84+
# value = spiceai_deployment.test.id
85+
# }
7686

77-
output "deployment_status" {
78-
description = "The status of the deployment"
79-
value = spiceai_deployment.test.status
80-
}
87+
# output "deployment_status" {
88+
# description = "The status of the deployment"
89+
# value = spiceai_deployment.test.status
90+
# }
8191

82-
output "data_source_app_name" {
83-
description = "App name from data source"
84-
value = data.spiceai_app.test.name
85-
}
92+
# output "data_source_app_name" {
93+
# description = "App name from data source"
94+
# value = data.spiceai_app.test.name
95+
# }
8696

87-
output "all_apps_count" {
88-
description = "Total number of apps in the organization"
89-
value = length(data.spiceai_apps.all.apps)
90-
}
97+
# output "all_apps_count" {
98+
# description = "Total number of apps in the organization"
99+
# value = length(data.spiceai_apps.all.apps)
100+
# }

internal/client/client.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ const (
2323

2424
// SpiceAIClient is the client for interacting with the Spice.ai API.
2525
type SpiceAIClient struct {
26-
httpClient *http.Client
27-
apiEndpoint string
28-
oauthEndpoint string
29-
clientID string
30-
clientSecret string
26+
httpClient *http.Client
27+
apiEndpoint string
28+
oauthEndpoint string
29+
clientID string
30+
clientSecret string
31+
vercelProtectionBypass string
3132

3233
// Token management
3334
accessToken string
@@ -43,7 +44,7 @@ type TokenResponse struct {
4344
}
4445

4546
// NewSpiceAIClient creates a new Spice.ai API client.
46-
func NewSpiceAIClient(clientID, clientSecret, apiEndpoint, oauthEndpoint string) *SpiceAIClient {
47+
func NewSpiceAIClient(clientID, clientSecret, apiEndpoint, oauthEndpoint, vercelProtectionBypass string) *SpiceAIClient {
4748
if apiEndpoint == "" {
4849
apiEndpoint = DefaultAPIEndpoint
4950
}
@@ -55,10 +56,11 @@ func NewSpiceAIClient(clientID, clientSecret, apiEndpoint, oauthEndpoint string)
5556
httpClient: &http.Client{
5657
Timeout: 30 * time.Second,
5758
},
58-
apiEndpoint: strings.TrimSuffix(apiEndpoint, "/"),
59-
oauthEndpoint: oauthEndpoint,
60-
clientID: clientID,
61-
clientSecret: clientSecret,
59+
apiEndpoint: strings.TrimSuffix(apiEndpoint, "/"),
60+
oauthEndpoint: oauthEndpoint,
61+
clientID: clientID,
62+
clientSecret: clientSecret,
63+
vercelProtectionBypass: vercelProtectionBypass,
6264
}
6365
}
6466

@@ -142,6 +144,9 @@ func (c *SpiceAIClient) doRequest(ctx context.Context, method, path string, body
142144
req.Header.Set("Authorization", "Bearer "+token)
143145
req.Header.Set("Content-Type", "application/json")
144146
req.Header.Set("Accept", "application/json")
147+
if c.vercelProtectionBypass != "" {
148+
req.Header.Set("x-vercel-protection-bypass", c.vercelProtectionBypass)
149+
}
145150

146151
return c.httpClient.Do(req)
147152
}

internal/provider/provider.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ type SpiceAIProvider struct {
3131

3232
// SpiceAIProviderModel describes the provider data model.
3333
type SpiceAIProviderModel struct {
34-
ClientID types.String `tfsdk:"client_id"`
35-
ClientSecret types.String `tfsdk:"client_secret"`
36-
APIEndpoint types.String `tfsdk:"api_endpoint"`
37-
OAuthEndpoint types.String `tfsdk:"oauth_endpoint"`
34+
ClientID types.String `tfsdk:"client_id"`
35+
ClientSecret types.String `tfsdk:"client_secret"`
36+
APIEndpoint types.String `tfsdk:"api_endpoint"`
37+
OAuthEndpoint types.String `tfsdk:"oauth_endpoint"`
38+
VercelProtectionBypass types.String `tfsdk:"vercel_protection_bypass"`
3839
}
3940

4041
func (p *SpiceAIProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
@@ -83,6 +84,11 @@ provider "spiceai" {
8384
MarkdownDescription: "The Spice.ai OAuth token endpoint. Defaults to `https://spice.ai/api/oauth/token`. Can also be set via the `SPICEAI_OAUTH_ENDPOINT` environment variable.",
8485
Optional: true,
8586
},
87+
"vercel_protection_bypass": schema.StringAttribute{
88+
MarkdownDescription: "Optional bypass token for Vercel deployment protection. When set, adds the `x-vercel-protection-bypass` header to API requests. Can also be set via the `SPICEAI_VERCEL_PROTECTION_BYPASS` environment variable.",
89+
Optional: true,
90+
Sensitive: true,
91+
},
8692
},
8793
}
8894
}
@@ -100,6 +106,7 @@ func (p *SpiceAIProvider) Configure(ctx context.Context, req provider.ConfigureR
100106
clientSecret := getConfigValue(data.ClientSecret, "SPICEAI_CLIENT_SECRET")
101107
apiEndpoint := getConfigValue(data.APIEndpoint, "SPICEAI_API_ENDPOINT")
102108
oauthEndpoint := getConfigValue(data.OAuthEndpoint, "SPICEAI_OAUTH_ENDPOINT")
109+
vercelProtectionBypass := getConfigValue(data.VercelProtectionBypass, "SPICEAI_VERCEL_PROTECTION_BYPASS")
103110

104111
// Validate required configuration
105112
if clientID == "" {
@@ -123,7 +130,7 @@ func (p *SpiceAIProvider) Configure(ctx context.Context, req provider.ConfigureR
123130
}
124131

125132
// Create the Spice.ai API client
126-
spiceClient := client.NewSpiceAIClient(clientID, clientSecret, apiEndpoint, oauthEndpoint)
133+
spiceClient := client.NewSpiceAIClient(clientID, clientSecret, apiEndpoint, oauthEndpoint, vercelProtectionBypass)
127134

128135
// Make the client available to resources and data sources
129136
resp.DataSourceData = spiceClient

0 commit comments

Comments
 (0)