Skip to content

Commit 4df47fb

Browse files
committed
fix app resources
1 parent 69ecda8 commit 4df47fb

2 files changed

Lines changed: 60 additions & 22 deletions

File tree

examples/test/main.tf

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ provider "spiceai" {
2323
}
2424

2525
# Create a test app with full configuration
26-
resource "spiceai_app" "test" {
27-
name = "terraform-test-app"
28-
description = "Test app for Terraform provider validation"
29-
visibility = "private"
30-
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"
47-
}
26+
# resource "spiceai_app" "test" {
27+
# name = "terraform-test-app-2"
28+
# description = "Test app for Terraform provider validation, test"
29+
# visibility = "private"
30+
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"
47+
# }
4848

4949
# # Create a deployment for the test app
5050
# resource "spiceai_deployment" "test" {

internal/provider/resource_app.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,37 +137,44 @@ resource "spiceai_app" "example" {
137137
"production_branch": schema.StringAttribute{
138138
MarkdownDescription: "The production branch for the app. Used for git-based deployments.",
139139
Optional: true,
140+
Computed: true,
140141
},
141142

142143
// Spicepod configuration
143144
"spicepod": schema.StringAttribute{
144145
MarkdownDescription: "The spicepod configuration as a YAML or JSON string. This defines the datasets, models, and other spicepod settings for the app.",
145146
Optional: true,
147+
Computed: true,
146148
},
147149

148150
// Runtime configuration attributes
149151
"image_tag": schema.StringAttribute{
150152
MarkdownDescription: "The Spice.ai runtime image tag to use for deployments (e.g., `latest`, `v0.18.0`).",
151153
Optional: true,
154+
Computed: true,
152155
},
153156
"replicas": schema.Int64Attribute{
154157
MarkdownDescription: "The number of replicas for the app. Must be between 1 and 10.",
155158
Optional: true,
159+
Computed: true,
156160
Validators: []validator.Int64{
157161
int64validator.Between(1, 10),
158162
},
159163
},
160164
"node_group": schema.StringAttribute{
161165
MarkdownDescription: "The node group for the app deployment.",
162166
Optional: true,
167+
Computed: true,
163168
},
164169
"region": schema.StringAttribute{
165170
MarkdownDescription: "The region for the app deployment.",
166171
Optional: true,
172+
Computed: true,
167173
},
168174
"storage_claim_size_gb": schema.Float64Attribute{
169175
MarkdownDescription: "The storage claim size in GB for the app.",
170176
Optional: true,
177+
Computed: true,
171178
},
172179

173180
// Read-only attributes
@@ -418,50 +425,81 @@ func (r *AppResource) mapAppToModel(data *AppResourceModel, app *client.App) {
418425

419426
if app.Description != "" {
420427
data.Description = types.StringValue(app.Description)
428+
} else {
429+
data.Description = types.StringNull()
421430
}
422431

423432
if app.Visibility != "" {
424433
data.Visibility = types.StringValue(app.Visibility)
434+
} else {
435+
data.Visibility = types.StringNull()
425436
}
426437

427438
if app.ProductionBranch != "" {
428439
data.ProductionBranch = types.StringValue(app.ProductionBranch)
440+
} else {
441+
data.ProductionBranch = types.StringNull()
429442
}
430443

431444
if app.Region != "" {
432445
data.Region = types.StringValue(app.Region)
446+
} else {
447+
data.Region = types.StringNull()
433448
}
434449

435450
if app.CreatedAt != "" {
436451
data.CreatedAt = types.StringValue(app.CreatedAt)
452+
} else {
453+
data.CreatedAt = types.StringNull()
437454
}
438455

439456
if app.APIKey != "" {
440457
data.APIKey = types.StringValue(app.APIKey)
458+
} else {
459+
data.APIKey = types.StringNull()
441460
}
442461

443462
// Map config fields if available
444463
if app.Config != nil {
445464
if app.Config.ImageTag != "" {
446465
data.ImageTag = types.StringValue(app.Config.ImageTag)
466+
} else {
467+
data.ImageTag = types.StringNull()
447468
}
448469

449470
if app.Config.Replicas > 0 {
450471
data.Replicas = types.Int64Value(int64(app.Config.Replicas))
472+
} else {
473+
data.Replicas = types.Int64Null()
451474
}
452475

453476
if app.Config.NodeGroup != "" {
454477
data.NodeGroup = types.StringValue(app.Config.NodeGroup)
478+
} else {
479+
data.NodeGroup = types.StringNull()
455480
}
456481

457482
if app.Config.StorageClaimSizeGB > 0 {
458483
data.StorageClaimSizeGB = types.Float64Value(app.Config.StorageClaimSizeGB)
484+
} else {
485+
data.StorageClaimSizeGB = types.Float64Null()
459486
}
460487

461488
if app.Config.Spicepod != nil {
462489
if spicepodBytes, err := json.Marshal(app.Config.Spicepod); err == nil {
463490
data.Spicepod = types.StringValue(string(spicepodBytes))
491+
} else {
492+
data.Spicepod = types.StringNull()
464493
}
494+
} else {
495+
data.Spicepod = types.StringNull()
465496
}
497+
} else {
498+
// No config returned, set all config fields to null
499+
data.ImageTag = types.StringNull()
500+
data.Replicas = types.Int64Null()
501+
data.NodeGroup = types.StringNull()
502+
data.StorageClaimSizeGB = types.Float64Null()
503+
data.Spicepod = types.StringNull()
466504
}
467505
}

0 commit comments

Comments
 (0)