Skip to content

Commit 9837623

Browse files
committed
manage id from regional or not
1 parent 796068e commit 9837623

File tree

10 files changed

+903
-513
lines changed

10 files changed

+903
-513
lines changed

docs/resources/inference_custom_model.md

Whitespace-only changes.

docs/resources/inference_deployment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For more information, see the [API documentation](https://www.scaleway.com/en/de
1616
resource "scaleway_inference_deployment" "deployment" {
1717
name = "tf-inference-deployment"
1818
node_type = "L4"
19-
model_name = "meta/llama-3.1-8b-instruct:fp8"
19+
model_id = "d33fb5fd-75ca-4dfb-8952-8af8b8b28be5"
2020
public_endpoint {
2121
is_enabled = true
2222
}
@@ -26,7 +26,7 @@ resource "scaleway_inference_deployment" "deployment" {
2626

2727
## Argument Reference
2828

29-
- `model_name` - (Required) The model name to use for the deployment. Model names can be found in Console or using Scaleway's CLI (`scw inference model list`)
29+
- `model_id` - The model id used for the deployment.
3030
- `node_type` - (Required) The node type to use for the deployment. Node types can be found using Scaleway's CLI (`scw inference node-type list`)
3131
- `name` - (Optional) The deployment name.
3232
- `accept_eula` - (Optional) Some models (e.g Meta Llama) require end-user license agreements. Set `true` to accept.
@@ -48,7 +48,7 @@ resource "scaleway_inference_deployment" "deployment" {
4848
In addition to all arguments above, the following attributes are exported:
4949

5050
- `id` - The ID of the deployment.
51-
- `model_id` - The model id used for the deployment.
51+
- `model_name` - (Required) The model name to use for the deployment. Model names can be found in Console or using Scaleway's CLI (`scw inference model list`)
5252
- `size` - The size of the pool.
5353
- `status` - The status of the deployment.
5454
- `created_at` - The date and time of the creation of the deployment.

internal/services/inference/custom_model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func ResourceCustomModelCreate(ctx context.Context, d *schema.ResourceData, m in
181181

182182
func ResourceCustomModelRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
183183
api, region, id, err := NewAPIWithRegionAndID(m, d.Id())
184+
184185
if err != nil {
185186
return diag.FromErr(err)
186187
}
@@ -195,7 +196,7 @@ func ResourceCustomModelRead(ctx context.Context, d *schema.ResourceData, m inte
195196

196197
return diag.FromErr(err)
197198
}
198-
199+
199200
_ = d.Set("parameter_size_bits", model.ParameterSizeBits)
200201
_ = d.Set("size_bits", model.SizeBytes)
201202
_ = d.Set("name", model.Name)

internal/services/inference/custom_model_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
const (
1616
modelURLCompatible = "https://huggingface.co/agentica-org/DeepCoder-14B-Preview"
1717
modelURLNotCompatible = "https://huggingface.co/google/gemma-3-4b-it"
18+
nodeTypeH100 = "H100"
1819
)
1920

2021
func TestAccCustomModel_Basic(t *testing.T) {
@@ -66,6 +67,43 @@ func TestAccCustomModel_NotCompatible(t *testing.T) {
6667
})
6768
}
6869

70+
func TestAccCustomModel_DeployModelOnServer(t *testing.T) {
71+
tt := acctest.NewTestTools(t)
72+
defer tt.Cleanup()
73+
74+
modelName := "TestAccCustomModel_DeployModelOnServer"
75+
76+
resource.ParallelTest(t, resource.TestCase{
77+
PreCheck: func() { acctest.PreCheck(t) },
78+
ProviderFactories: tt.ProviderFactories,
79+
CheckDestroy: inferencetestfuncs.IsCustomModelDestroyed(tt),
80+
Steps: []resource.TestStep{
81+
{
82+
Config: fmt.Sprintf(`
83+
resource "scaleway_inference_custom_model" "test" {
84+
name = "%s"
85+
url = "%s"
86+
}
87+
resource "scaleway_inference_deployment" "main" {
88+
name = "%s"
89+
node_type = "%s"
90+
model_id = scaleway_inference_custom_model.test.id
91+
public_endpoint {
92+
is_enabled = true
93+
}
94+
accept_eula = true
95+
}
96+
`, modelName, modelURLCompatible, modelName, nodeTypeH100),
97+
Check: resource.ComposeTestCheckFunc(
98+
testAccCheckDeploymentExists(tt, "scaleway_inference_deployment.main"),
99+
resource.TestCheckResourceAttr("scaleway_inference_deployment.main", "model_name", modelName),
100+
resource.TestCheckTypeSetElemAttrPair("scaleway_inference_deployment.main", "model_id", "scaleway_inference_custom_model.test", "id"),
101+
),
102+
},
103+
},
104+
})
105+
}
106+
69107
func testAccCheckCustomModelExists(tt *acctest.TestTools, n string) resource.TestCheckFunc {
70108
return func(state *terraform.State) error {
71109
rs, ok := state.RootModule().Resources[n]

internal/services/inference/deployment.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
99
"github.com/scaleway/scaleway-sdk-go/api/inference/v1"
1010
"github.com/scaleway/scaleway-sdk-go/scw"
11+
scwvalidation "github.com/scaleway/scaleway-sdk-go/validation"
1112
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
@@ -182,12 +183,18 @@ func ResourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, m int
182183
return diag.FromErr(err)
183184
}
184185

186+
modelID := d.Get("model_id")
187+
188+
if !scwvalidation.IsUUID(modelID.(string)) {
189+
modelID = regional.ExpandID(modelID).ID
190+
}
191+
185192
req := &inference.CreateDeploymentRequest{
186193
Region: region,
187194
ProjectID: d.Get("project_id").(string),
188195
Name: d.Get("name").(string),
189196
NodeTypeName: d.Get("node_type").(string),
190-
ModelID: d.Get("model_id").(string),
197+
ModelID: modelID.(string),
191198
Tags: types.ExpandStrings(d.Get("tags")),
192199
Endpoints: buildEndpoints(d),
193200
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package inference

0 commit comments

Comments
 (0)