Skip to content

Commit d81aa42

Browse files
alexottnkvuong
andauthored
[Feature] Allow to specify budget policy for databricks_vector_search_endpoint (#4707)
## Changes <!-- Summary of your changes that are easy to understand --> For some reason, `custom_tags` cause configuration drift even if they are marked as read-only, so temporary removed it (and we need to wait for API anyway). ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] using Go SDK - [ ] using TF Plugin Framework Co-authored-by: vuong-nguyen <[email protected]>
1 parent 7bcc044 commit d81aa42

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

NEXT_CHANGELOG.md

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

55
### New Features and Improvements
66

7+
* Allow to specify budget policy for `databricks_vector_search_endpoint` [#4707](https://github.com/databricks/terraform-provider-databricks/pull/4707)
8+
79
### Bug Fixes
810

911
* Don't fail delete when `databricks_system_schema` can be disabled only by Databricks [#4727](https://github.com/databricks/terraform-provider-databricks/pull/4727)

docs/resources/vector_search_endpoint.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ resource "databricks_vector_search_endpoint" "this" {
1818

1919
## Argument Reference
2020

21-
The following arguments are supported (change of any parameter leads to recreation of the resource):
21+
The following arguments are supported:
2222

23-
* `name` - (Required) Name of the Mosaic AI Vector Search Endpoint to create.
24-
* `endpoint_type` (Required) Type of Mosaic AI Vector Search Endpoint. Currently only accepting single value: `STANDARD` (See [documentation](https://docs.databricks.com/api/workspace/vectorsearchendpoints/createendpoint) for the list of currently supported values).
23+
* `name` - (Required) Name of the Mosaic AI Vector Search Endpoint to create. (Change leads to recreation of the resource).
24+
* `endpoint_type` (Required) Type of Mosaic AI Vector Search Endpoint. Currently only accepting single value: `STANDARD` (See [documentation](https://docs.databricks.com/api/workspace/vectorsearchendpoints/createendpoint) for the list of currently supported values). (Change leads to recreation of the resource).
25+
* `budget_policy_id` - (Optional) The Budget Policy ID set for this resource.
2526

2627
## Attribute Reference
2728

@@ -32,6 +33,7 @@ In addition to all the arguments above, the following attributes are exported:
3233
* `creation_timestamp` - Timestamp of endpoint creation (milliseconds).
3334
* `last_updated_user` - User who last updated the endpoint.
3435
* `last_updated_timestamp` - Timestamp of the last update to the endpoint (milliseconds).
36+
* `effective_budget_policy_id` - The effective budget policy ID.
3537
* `endpoint_id` - Unique internal identifier of the endpoint (UUID).
3638
* `num_indexes` - Number of indexes on the endpoint.
3739
* `endpoint_status` - Object describing the current status of the endpoint consisting of the following fields:

vectorsearch/resource_vector_search_endpoint.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ func ResourceVectorSearchEndpoint() common.Resource {
2121
common.CustomizeSchemaPath(s, "name").SetRequired().SetForceNew()
2222
common.CustomizeSchemaPath(s, "endpoint_type").SetRequired().SetForceNew()
2323
delete(s, "id")
24-
common.CustomizeSchemaPath(s, "creator").SetReadOnly()
25-
common.CustomizeSchemaPath(s, "creation_timestamp").SetReadOnly()
26-
common.CustomizeSchemaPath(s, "last_updated_timestamp").SetReadOnly()
27-
common.CustomizeSchemaPath(s, "last_updated_user").SetReadOnly()
28-
common.CustomizeSchemaPath(s, "endpoint_status").SetReadOnly()
29-
common.CustomizeSchemaPath(s, "num_indexes").SetReadOnly()
24+
delete(s, "custom_tags")
25+
for _, field := range []string{"creator", "creation_timestamp", "last_updated_timestamp",
26+
"last_updated_user", "endpoint_status", "num_indexes", "effective_budget_policy_id"} {
27+
common.CustomizeSchemaPath(s, field).SetReadOnly()
28+
}
3029
common.CustomizeSchemaPath(s).AddNewField("endpoint_id", &schema.Schema{
3130
Type: schema.TypeString,
3231
Computed: true,
3332
})
33+
common.CustomizeSchemaPath(s).AddNewField("budget_policy_id", &schema.Schema{
34+
Type: schema.TypeString,
35+
Optional: true,
36+
Computed: true,
37+
})
3438

3539
return s
3640
})
@@ -72,9 +76,27 @@ func ResourceVectorSearchEndpoint() common.Resource {
7276
if err != nil {
7377
return err
7478
}
79+
d.Set("budget_policy_id", endpoint.EffectiveBudgetPolicyId)
7580
d.Set("endpoint_id", endpoint.Id)
7681
return nil
7782
},
83+
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
84+
w, err := c.WorkspaceClient()
85+
if err != nil {
86+
return err
87+
}
88+
if d.HasChange("budget_policy_id") {
89+
_, err := w.VectorSearchEndpoints.UpdateEndpointBudgetPolicy(ctx, vectorsearch.PatchEndpointBudgetPolicyRequest{
90+
EndpointName: d.Id(),
91+
BudgetPolicyId: d.Get("budget_policy_id").(string),
92+
})
93+
if err != nil {
94+
return err
95+
}
96+
}
97+
return nil
98+
},
99+
78100
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
79101
w, err := c.WorkspaceClient()
80102
if err != nil {

vectorsearch/resource_vector_search_endpoint_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,41 @@ func TestVectorSearchEndpointCreateTimeoutError(t *testing.T) {
105105
}.ExpectError(t, "timeout")
106106

107107
}
108+
109+
func TestVectorSearchEndpointUpdateBudgetPolicy(t *testing.T) {
110+
qa.ResourceFixture{
111+
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
112+
e := w.GetMockVectorSearchEndpointsAPI().EXPECT()
113+
e.UpdateEndpointBudgetPolicy(mock.Anything, vectorsearch.PatchEndpointBudgetPolicyRequest{
114+
EndpointName: "abc",
115+
BudgetPolicyId: "budget-123",
116+
}).Return(&vectorsearch.PatchEndpointBudgetPolicyResponse{
117+
EffectiveBudgetPolicyId: "budget-123",
118+
}, nil)
119+
e.GetEndpointByEndpointName(mock.Anything, "abc").Return(&vectorsearch.EndpointInfo{
120+
Id: "1234-5678",
121+
EffectiveBudgetPolicyId: "budget-123",
122+
EndpointStatus: &vectorsearch.EndpointStatus{State: "ONLINE"},
123+
EndpointType: "STANDARD",
124+
Name: "abc",
125+
}, nil)
126+
},
127+
Resource: ResourceVectorSearchEndpoint(),
128+
Update: true,
129+
ID: "abc",
130+
InstanceState: map[string]string{
131+
"endpoint_id": "1234-5678",
132+
"name": "abc",
133+
"endpoint_type": "STANDARD",
134+
"budget_policy_id": "budget-456",
135+
},
136+
HCL: `
137+
name = "abc"
138+
endpoint_type = "STANDARD"
139+
budget_policy_id = "budget-123"
140+
`,
141+
}.ApplyAndExpectData(t, map[string]any{
142+
"id": "abc",
143+
"budget_policy_id": "budget-123",
144+
})
145+
}

0 commit comments

Comments
 (0)