|
| 1 | +--- |
| 2 | +subcategory: "Storage" |
| 3 | +--- |
| 4 | +# databricks_file Resource |
| 5 | + |
| 6 | +This resource allows uploading and downloading files in [databricks_volume](volume.md). |
| 7 | + |
| 8 | +Notes: |
| 9 | +* Currently the limit is 5GiB in octet-stream. |
| 10 | +* Currently, only UC volumes are supported. The list of destinations may change. |
| 11 | + |
| 12 | +## Example Usage |
| 13 | + |
| 14 | +In order to manage a file on Unity Catalog Volumes with Terraform, you must specify the `source` attribute containing the full path to the file on the local filesystem. |
| 15 | + |
| 16 | +```hcl |
| 17 | +resource "databricks_catalog" "sandbox" { |
| 18 | + metastore_id = databricks_metastore.this.id |
| 19 | + name = "sandbox" |
| 20 | + comment = "this catalog is managed by terraform" |
| 21 | + properties = { |
| 22 | + purpose = "testing" |
| 23 | + } |
| 24 | +} |
| 25 | +
|
| 26 | +resource "databricks_schema" "things" { |
| 27 | + catalog_name = databricks_catalog.sandbox.name |
| 28 | + name = "things" |
| 29 | + comment = "this schema is managed by terraform" |
| 30 | + properties = { |
| 31 | + kind = "various" |
| 32 | + } |
| 33 | +} |
| 34 | +
|
| 35 | +resource "databricks_volume" "this" { |
| 36 | + name = "quickstart_volume" |
| 37 | + catalog_name = databricks_catalog.sandbox.name |
| 38 | + schema_name = databricks_schema.things.name |
| 39 | + volume_type = "MANAGED" |
| 40 | + comment = "this volume is managed by terraform" |
| 41 | +} |
| 42 | +
|
| 43 | +resource "databricks_file" "this" { |
| 44 | + source = "/full/path/on/local/system" |
| 45 | + path = "${databricks_volume.this.volume_path}/fileName" |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +You can also inline sources through `content_base64` attribute. |
| 50 | + |
| 51 | +```hcl |
| 52 | +resource "databricks_file" "init_script" { |
| 53 | + content_base64 = base64encode(<<-EOT |
| 54 | + #!/bin/bash |
| 55 | + echo "Hello World" |
| 56 | + EOT |
| 57 | + ) |
| 58 | + path = "${databricks_volume.this.volume_path}/fileName" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +## Argument Reference |
| 63 | + |
| 64 | +The following arguments are supported: |
| 65 | + |
| 66 | +* `source` - The full absolute path to the file. Conflicts with `content_base64`. |
| 67 | +* `content_base64` - Contents in base 64 format. Conflicts with `source`. |
| 68 | +* `path` - The path of the file in which you wish to save. For example, `/Volumes/main/default/volume1/file.txt`. |
| 69 | + |
| 70 | +## Attribute Reference |
| 71 | + |
| 72 | +In addition to all arguments above, the following attributes are exported: |
| 73 | + |
| 74 | +* `id` - Same as `path`. |
| 75 | +* `file_size` - The file size of the file that is being tracked by this resource in bytes. |
| 76 | +* `modification_time` - The last time stamp when the file was modified |
| 77 | + |
| 78 | + |
| 79 | +## Import |
| 80 | + |
| 81 | +The resource `databricks_file` can be imported using the path of the file: |
| 82 | + |
| 83 | +```bash |
| 84 | +$ terraform import databricks_file.this <path> |
| 85 | +``` |
| 86 | + |
| 87 | +## Related Resources |
| 88 | + |
| 89 | +The following resources are often used in the same context: |
| 90 | + |
| 91 | +* [databricks_workspace_file](./workspace_file.md) |
| 92 | +* [End to end workspace management](../guides/workspace-management.md) guide. |
| 93 | +* [databricks_volume](../resources/volume.md) to manage [volumes within Unity Catalog](https://docs.databricks.com/en/connect/unity-catalog/volumes.html). |
0 commit comments