Skip to content

Commit 7a055a1

Browse files
mgyuchtalexott
andauthored
Fix incorrect SetSuppressDiff() for workload_size in databricks_model_serving (#5152)
## Changes This PR removes the `SetSuppressDiff()` calls for `workload_size` that were added in #5111 (commit 1617350). The previous PR (#5111) made a faulty assumption that `workload_size` would be returned by the API when `min_provisioned_concurrency`/`max_provisioned_concurrency` were specified. As a result, it added `SetSuppressDiff()` to prevent Terraform from detecting changes. However, the API actually does **not** return `workload_size` when `min_provisioned_concurrency`/`max_provisioned_concurrency` are set. This means that no diff suppression is needed, and these fields can be simply treated as optional (which is the default behavior). ## Tests - [x] Manual test: Verify that switching between `workload_size` and `min_provisioned_concurrency`/`max_provisioned_concurrency` works correctly without unexpected diffs When adding the concurrency parameters and removing workload size: ``` Terraform will perform the following actions: # databricks_model_serving.llama_endpoint will be updated in-place ~ resource "databricks_model_serving" "llama_endpoint" { id = "llama-3-2-1b-instruct-endpoint" name = "llama-3-2-1b-instruct-endpoint" # (3 unchanged attributes hidden) ~ config { ~ served_entities { ~ max_provisioned_concurrency = 0 -> 4 name = "llama_v3_2_1b_instruct-2" - workload_size = "Small" -> null # (10 unchanged attributes hidden) } # (1 unchanged block hidden) } } ``` And vice-versa: ``` # databricks_model_serving.llama_endpoint will be updated in-place ~ resource "databricks_model_serving" "llama_endpoint" { id = "llama-3-2-1b-instruct-endpoint" name = "llama-3-2-1b-instruct-endpoint" # (3 unchanged attributes hidden) ~ config { ~ served_entities { - max_provisioned_concurrency = 4 -> null name = "llama_v3_2_1b_instruct-2" + workload_size = "Small" # (10 unchanged attributes hidden) } # (1 unchanged block hidden) } ``` The applies complete without error, and the plan is empty after apply. ## Related - Previous PR: #5111 - Previous commit: 1617350 --------- Co-authored-by: Alex Ott <[email protected]>
1 parent a42dec7 commit 7a055a1

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Bug Fixes
1212

13+
* Remove unnecessary `SetSuppressDiff()` for `workload_size` in `databricks_model_serving` ([#5152](https://github.com/databricks/terraform-provider-databricks/pull/5152)).
14+
1315
### Documentation
1416

1517
### Exporter

serving/resource_model_serving.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,47 @@ func updateAiGateway(ctx context.Context, w *databricks.WorkspaceClient, name st
131131
return err
132132
}
133133

134+
// cleanWorkloadSize clears the workload_size field from the config (the API response) if it is not set in the corresponding schema.ResourceData.
135+
// This is applied to both the ServedModels and ServedEntities fields.
136+
//
137+
// If neither workload_size nor min_provisioned_concurrency/max_provisioned_concurrency are provided in API requests, workload_size is set in the
138+
// API response. This results in a configuration drift for workload_size.
139+
//
140+
// The resulting behavior is:
141+
//
142+
// - If the workload_size is set in the ResourceData, the provider respects the value specified in the API response.
143+
// - If the workload_size is not set in the ResourceData, the provider clears the workload_size from the API response.
144+
func cleanWorkloadSize(s map[string]*schema.Schema, d *schema.ResourceData, apiResponse *serving.EndpointCoreConfigOutput) {
145+
var config serving.CreateServingEndpoint
146+
common.DataToStructPointer(d, s, &config)
147+
148+
if config.Config == nil {
149+
return
150+
}
151+
for _, configModel := range config.Config.ServedModels {
152+
if configModel.WorkloadSize != "" {
153+
continue
154+
}
155+
for i, apiModel := range apiResponse.ServedModels {
156+
if apiModel.Name == configModel.Name {
157+
apiResponse.ServedModels[i].WorkloadSize = ""
158+
break
159+
}
160+
}
161+
}
162+
for _, configEntity := range config.Config.ServedEntities {
163+
if configEntity.WorkloadSize != "" {
164+
continue
165+
}
166+
for i, apiEntity := range apiResponse.ServedEntities {
167+
if apiEntity.Name == configEntity.Name {
168+
apiResponse.ServedEntities[i].WorkloadSize = ""
169+
break
170+
}
171+
}
172+
}
173+
}
174+
134175
func ResourceModelServing() common.Resource {
135176
s := common.StructToSchema(
136177
serving.CreateServingEndpoint{},
@@ -154,14 +195,12 @@ func ResourceModelServing() common.Resource {
154195

155196
common.CustomizeSchemaPath(m, "config", "served_models", "name").SetComputed()
156197
common.CustomizeSchemaPath(m, "config", "served_models", "workload_type").SetComputed()
157-
common.CustomizeSchemaPath(m, "config", "served_models", "workload_size").SetSuppressDiff()
158198
common.CustomizeSchemaPath(m, "config", "served_models", "scale_to_zero_enabled").SetOptional().SetDefault(true)
159199
common.CustomizeSchemaPath(m, "config", "served_models").SetDeprecated("Please use 'config.served_entities' instead of 'config.served_models'.")
160200
common.CustomizeSchemaPath(m, "rate_limits").SetDeprecated("Please use AI Gateway to manage rate limits.")
161201

162202
common.CustomizeSchemaPath(m, "config", "served_entities", "name").SetComputed()
163203
common.CustomizeSchemaPath(m, "config", "served_entities", "workload_type").SetComputed()
164-
common.CustomizeSchemaPath(m, "config", "served_entities", "workload_size").SetSuppressDiff()
165204

166205
// Apply custom suppress diff to traffic config routes for served_model_name and served_entity_name
167206
common.CustomizeSchemaPath(m, "config", "traffic_config", "routes", "served_model_name").SetCustomSuppressDiff(suppressRouteModelEntityNameDiff)
@@ -234,6 +273,8 @@ func ResourceModelServing() common.Resource {
234273
endpoint.Config.ServedEntities = nil
235274
}
236275
}
276+
cleanWorkloadSize(s, d, endpoint.Config)
277+
237278
err = common.StructToData(*endpoint, s, d)
238279
if err != nil {
239280
return err

0 commit comments

Comments
 (0)