Skip to content

Commit f5fce0f

Browse files
[Fix] Add client side validation for volume_type (#4289)
## Changes This PR adds validation that the value provided for `volume_type` is one of the correct values. The server today provides an incorrect error message: ``` 10:30:10 DEBUG POST /api/2.1/unity-catalog/volumes > { > "catalog_name": "main", > "name": "cli-volume", > "schema_name": "schema-dec-dabs", > "volume_type": "managed" > } < HTTP/2.0 400 Bad Request < { < "details": [ < { < "@type": "type.googleapis.com/google.rpc.ErrorInfo", < "domain": "unity-catalog.databricks.com", < "metadata": { < "field_name": "volume_type" < }, < "reason": "INVALID_FIELD" < }, < { < "@type": "type.googleapis.com/google.rpc.RequestInfo", < "request_id": "2ca7e630-ce06-4c85-ad95-9b3b52987009", < "serving_data": "" < } < ], < "error_code": "INVALID_PARAMETER_VALUE", < "message": "CreateVolume Missing required field: volume_type" < } ``` ## Tests Unit tests
1 parent 0a055b3 commit f5fce0f

File tree

2 files changed

+74
-48
lines changed

2 files changed

+74
-48
lines changed

catalog/resource_volume.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/databricks/databricks-sdk-go/service/catalog"
99
"github.com/databricks/terraform-provider-databricks/common"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1112
)
1213

1314
// This structure contains the fields of catalog.UpdateVolumeRequestContent and catalog.CreateVolumeRequestContent
@@ -50,6 +51,13 @@ func ResourceVolume() common.Resource {
5051
Type: schema.TypeString,
5152
Computed: true,
5253
}
54+
// As of 3rd December 2024, the Volumes create API returns an incorrect
55+
// error message "CreateVolume Missing required field: volume_type"
56+
// if you specify an invalid value for volume_type (i.e. not one of "MANAGED" or "EXTERNAL").
57+
//
58+
// If server side validation is added in the future, this validation function
59+
// can be removed.
60+
common.CustomizeSchemaPath(m, "volume_type").SetValidateFunc(validation.StringInSlice([]string{"MANAGED", "EXTERNAL"}, false))
5361
return m
5462
})
5563
return common.Resource{

0 commit comments

Comments
 (0)