Skip to content

Commit

Permalink
[Fix] Add client side validation for volume_type (#4289)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
shreyas-goenka authored Dec 4, 2024
1 parent 0a055b3 commit f5fce0f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 48 deletions.
8 changes: 8 additions & 0 deletions catalog/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

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

0 comments on commit f5fce0f

Please sign in to comment.