Skip to content

Commit cf8b820

Browse files
committed
fix update and min_size, max_size
1 parent bdb7283 commit cf8b820

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

internal/services/inference/deployment.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ func ResourceDeployment() *schema.Resource {
6969
"min_size": {
7070
Type: schema.TypeInt,
7171
Optional: true,
72-
Computed: true,
72+
Default: 1,
7373
Description: "The minimum size of the pool",
7474
},
7575
"max_size": {
7676
Type: schema.TypeInt,
7777
Optional: true,
78-
Computed: true,
78+
Default: 1,
7979
Description: "The maximum size of the pool",
8080
},
8181
"size": {
@@ -112,7 +112,7 @@ func ResourceDeployment() *schema.Resource {
112112
Description: "The id of the private endpoint",
113113
Computed: true,
114114
},
115-
"private_endpoint_id": {
115+
"private_network_id": {
116116
Type: schema.TypeString,
117117
Description: "The id of the private network",
118118
Optional: true,
@@ -188,6 +188,14 @@ func ResourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, m int
188188
req.AcceptEula = scw.BoolPtr(isAcceptingEula.(bool))
189189
}
190190

191+
if minSize, ok := d.GetOk("min_size"); ok {
192+
req.MinSize = scw.Uint32Ptr(uint32(minSize.(int)))
193+
}
194+
195+
if maxSize, ok := d.GetOk("max_size"); ok {
196+
req.MaxSize = scw.Uint32Ptr(uint32(maxSize.(int)))
197+
}
198+
191199
deployment, err := api.CreateDeployment(req, scw.WithContext(ctx))
192200
if err != nil {
193201
return diag.FromErr(err)
@@ -219,7 +227,7 @@ func buildEndpoints(d *schema.ResourceData) []*inference.EndpointSpec {
219227

220228
if privateEndpoint, ok := d.GetOk("private_endpoint"); ok {
221229
privateEndpointMap := privateEndpoint.([]interface{})[0].(map[string]interface{})
222-
if privateID, exists := privateEndpointMap["private_endpoint_id"]; exists {
230+
if privateID, exists := privateEndpointMap["private_network_id"]; exists {
223231
privateEp := inference.EndpointSpec{
224232
PrivateNetwork: &inference.EndpointSpecPrivateNetwork{
225233
PrivateNetworkID: regional.ExpandID(privateID.(string)).ID,
@@ -258,6 +266,7 @@ func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter
258266
_ = d.Set("size", int(deployment.Size))
259267
_ = d.Set("status", deployment.Status)
260268
_ = d.Set("model_id", deployment.ModelID)
269+
_ = d.Set("tags", types.ExpandUpdatedStringsPtr(deployment.Tags))
261270
_ = d.Set("created_at", types.FlattenTime(deployment.CreatedAt))
262271
_ = d.Set("updated_at", types.FlattenTime(deployment.UpdatedAt))
263272
var privateEndpoints []map[string]interface{}
@@ -266,10 +275,10 @@ func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter
266275
for _, endpoint := range deployment.Endpoints {
267276
if endpoint.PrivateNetwork != nil {
268277
privateEndpointSpec := map[string]interface{}{
269-
"id": endpoint.ID,
270-
"private_endpoint_id": regional.NewID(deployment.Region, endpoint.PrivateNetwork.PrivateNetworkID).String(),
271-
"disable_auth": endpoint.DisableAuth,
272-
"url": endpoint.URL,
278+
"id": endpoint.ID,
279+
"private_network_id": regional.NewID(deployment.Region, endpoint.PrivateNetwork.PrivateNetworkID).String(),
280+
"disable_auth": endpoint.DisableAuth,
281+
"url": endpoint.URL,
273282
}
274283
privateEndpoints = append(privateEndpoints, privateEndpointSpec)
275284
}
@@ -284,10 +293,10 @@ func ResourceDeploymentRead(ctx context.Context, d *schema.ResourceData, m inter
284293
}
285294
}
286295

287-
if len(privateEndpoints) > 0 {
296+
if privateEndpoints != nil {
288297
_ = d.Set("private_endpoint", privateEndpoints)
289298
}
290-
if len(publicEndpoints) > 0 {
299+
if publicEndpoints != nil {
291300
_ = d.Set("public_endpoint", publicEndpoints)
292301
}
293302
return nil
@@ -307,6 +316,7 @@ func ResourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int
307316
}
308317
return diag.FromErr(err)
309318
}
319+
310320
req := &inference.UpdateDeploymentRequest{
311321
Region: region,
312322
DeploymentID: deployment.ID,
@@ -316,6 +326,18 @@ func ResourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int
316326
req.Name = types.ExpandUpdatedStringPtr(d.Get("name"))
317327
}
318328

329+
if d.HasChange("tags") {
330+
req.Tags = types.ExpandUpdatedStringsPtr(d.Get("tags"))
331+
}
332+
333+
if d.HasChange("min_size") {
334+
req.MinSize = types.ExpandUint32Ptr(d.Get("min_size"))
335+
}
336+
337+
if d.HasChange("max_size") {
338+
req.MaxSize = types.ExpandUint32Ptr(d.Get("max_size"))
339+
}
340+
319341
if _, err := api.UpdateDeployment(req, scw.WithContext(ctx)); err != nil {
320342
return diag.FromErr(err)
321343
}

internal/services/inference/deployment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestAccDeployment_Endpoint(t *testing.T) {
6161
node_type = "L4"
6262
model_name = "meta/llama-3.1-8b-instruct:fp8"
6363
private_endpoint {
64-
private_endpoint_id = "${scaleway_vpc_private_network.pn01.id}"
64+
private_network_id = "${scaleway_vpc_private_network.pn01.id}"
6565
}
6666
accept_eula = true
6767
}
@@ -70,7 +70,7 @@ func TestAccDeployment_Endpoint(t *testing.T) {
7070
testAccCheckDeploymentExists(tt, "scaleway_inference_deployment.main"),
7171
resource.TestCheckResourceAttr("scaleway_inference_deployment.main", "name", "test-inference-deployment-endpoint-private"),
7272
resource.TestCheckResourceAttr("scaleway_inference_deployment.main", "node_type", "L4"),
73-
resource.TestCheckResourceAttrPair("scaleway_inference_deployment.main", "private_endpoint.0.private_endpoint_id", "scaleway_vpc_private_network.pn01", "id"),
73+
resource.TestCheckResourceAttrPair("scaleway_inference_deployment.main", "private_endpoint.0.private_network_id", "scaleway_vpc_private_network.pn01", "id"),
7474
),
7575
},
7676
{
@@ -83,7 +83,7 @@ func TestAccDeployment_Endpoint(t *testing.T) {
8383
node_type = "L4"
8484
model_name = "meta/llama-3.1-8b-instruct:fp8"
8585
private_endpoint {
86-
private_endpoint_id = "${scaleway_vpc_private_network.pn01.id}"
86+
private_network_id = "${scaleway_vpc_private_network.pn01.id}"
8787
}
8888
public_endpoint {
8989
is_enabled = true
@@ -95,7 +95,7 @@ func TestAccDeployment_Endpoint(t *testing.T) {
9595
testAccCheckDeploymentExists(tt, "scaleway_inference_deployment.main"),
9696
resource.TestCheckResourceAttr("scaleway_inference_deployment.main", "name", "test-inference-deployment-basic-endpoints-private-public"),
9797
resource.TestCheckResourceAttr("scaleway_inference_deployment.main", "public_endpoint.0.is_enabled", "true"),
98-
resource.TestCheckResourceAttrPair("scaleway_inference_deployment.main", "private_endpoint.0.private_endpoint_id", "scaleway_vpc_private_network.pn01", "id"),
98+
resource.TestCheckResourceAttrPair("scaleway_inference_deployment.main", "private_endpoint.0.private_network_id", "scaleway_vpc_private_network.pn01", "id"),
9999
),
100100
},
101101
},

0 commit comments

Comments
 (0)