1. Packages
  2. Databricks
  3. API Docs
  4. File
Databricks v1.50.2 published on Tuesday, Sep 24, 2024 by Pulumi

databricks.File

Explore with Pulumi AI

databricks logo
Databricks v1.50.2 published on Tuesday, Sep 24, 2024 by Pulumi

    This resource allows uploading and downloading files in databricks_volume.

    Notes:

    • Currently the limit is 5GiB in octet-stream.
    • Currently, only UC volumes are supported. The list of destinations may change.

    Example Usage

    In order to manage a file on Unity Catalog Volumes with Pulumi, you must specify the source attribute containing the full path to the file on the local filesystem.

    import * as pulumi from "@pulumi/pulumi";
    import * as databricks from "@pulumi/databricks";
    
    const sandbox = new databricks.Catalog("sandbox", {
        metastoreId: thisDatabricksMetastore.id,
        name: "sandbox",
        comment: "this catalog is managed by terraform",
        properties: {
            purpose: "testing",
        },
    });
    const things = new databricks.Schema("things", {
        catalogName: sandbox.name,
        name: "things",
        comment: "this schema is managed by terraform",
        properties: {
            kind: "various",
        },
    });
    const _this = new databricks.Volume("this", {
        name: "quickstart_volume",
        catalogName: sandbox.name,
        schemaName: things.name,
        volumeType: "MANAGED",
        comment: "this volume is managed by terraform",
    });
    const thisFile = new databricks.File("this", {
        source: "/full/path/on/local/system",
        path: pulumi.interpolate`${_this.volumePath}/fileName`,
    });
    
    import pulumi
    import pulumi_databricks as databricks
    
    sandbox = databricks.Catalog("sandbox",
        metastore_id=this_databricks_metastore["id"],
        name="sandbox",
        comment="this catalog is managed by terraform",
        properties={
            "purpose": "testing",
        })
    things = databricks.Schema("things",
        catalog_name=sandbox.name,
        name="things",
        comment="this schema is managed by terraform",
        properties={
            "kind": "various",
        })
    this = databricks.Volume("this",
        name="quickstart_volume",
        catalog_name=sandbox.name,
        schema_name=things.name,
        volume_type="MANAGED",
        comment="this volume is managed by terraform")
    this_file = databricks.File("this",
        source="/full/path/on/local/system",
        path=this.volume_path.apply(lambda volume_path: f"{volume_path}/fileName"))
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-databricks/sdk/go/databricks"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		sandbox, err := databricks.NewCatalog(ctx, "sandbox", &databricks.CatalogArgs{
    			MetastoreId: pulumi.Any(thisDatabricksMetastore.Id),
    			Name:        pulumi.String("sandbox"),
    			Comment:     pulumi.String("this catalog is managed by terraform"),
    			Properties: pulumi.StringMap{
    				"purpose": pulumi.String("testing"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		things, err := databricks.NewSchema(ctx, "things", &databricks.SchemaArgs{
    			CatalogName: sandbox.Name,
    			Name:        pulumi.String("things"),
    			Comment:     pulumi.String("this schema is managed by terraform"),
    			Properties: pulumi.StringMap{
    				"kind": pulumi.String("various"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		this, err := databricks.NewVolume(ctx, "this", &databricks.VolumeArgs{
    			Name:        pulumi.String("quickstart_volume"),
    			CatalogName: sandbox.Name,
    			SchemaName:  things.Name,
    			VolumeType:  pulumi.String("MANAGED"),
    			Comment:     pulumi.String("this volume is managed by terraform"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = databricks.NewFile(ctx, "this", &databricks.FileArgs{
    			Source: pulumi.String("/full/path/on/local/system"),
    			Path: this.VolumePath.ApplyT(func(volumePath string) (string, error) {
    				return fmt.Sprintf("%v/fileName", volumePath), nil
    			}).(pulumi.StringOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Databricks = Pulumi.Databricks;
    
    return await Deployment.RunAsync(() => 
    {
        var sandbox = new Databricks.Catalog("sandbox", new()
        {
            MetastoreId = thisDatabricksMetastore.Id,
            Name = "sandbox",
            Comment = "this catalog is managed by terraform",
            Properties = 
            {
                { "purpose", "testing" },
            },
        });
    
        var things = new Databricks.Schema("things", new()
        {
            CatalogName = sandbox.Name,
            Name = "things",
            Comment = "this schema is managed by terraform",
            Properties = 
            {
                { "kind", "various" },
            },
        });
    
        var @this = new Databricks.Volume("this", new()
        {
            Name = "quickstart_volume",
            CatalogName = sandbox.Name,
            SchemaName = things.Name,
            VolumeType = "MANAGED",
            Comment = "this volume is managed by terraform",
        });
    
        var thisFile = new Databricks.File("this", new()
        {
            Source = "/full/path/on/local/system",
            Path = @this.VolumePath.Apply(volumePath => $"{volumePath}/fileName"),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.databricks.Catalog;
    import com.pulumi.databricks.CatalogArgs;
    import com.pulumi.databricks.Schema;
    import com.pulumi.databricks.SchemaArgs;
    import com.pulumi.databricks.Volume;
    import com.pulumi.databricks.VolumeArgs;
    import com.pulumi.databricks.File;
    import com.pulumi.databricks.FileArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var sandbox = new Catalog("sandbox", CatalogArgs.builder()
                .metastoreId(thisDatabricksMetastore.id())
                .name("sandbox")
                .comment("this catalog is managed by terraform")
                .properties(Map.of("purpose", "testing"))
                .build());
    
            var things = new Schema("things", SchemaArgs.builder()
                .catalogName(sandbox.name())
                .name("things")
                .comment("this schema is managed by terraform")
                .properties(Map.of("kind", "various"))
                .build());
    
            var this_ = new Volume("this", VolumeArgs.builder()
                .name("quickstart_volume")
                .catalogName(sandbox.name())
                .schemaName(things.name())
                .volumeType("MANAGED")
                .comment("this volume is managed by terraform")
                .build());
    
            var thisFile = new File("thisFile", FileArgs.builder()
                .source("/full/path/on/local/system")
                .path(this_.volumePath().applyValue(volumePath -> String.format("%s/fileName", volumePath)))
                .build());
    
        }
    }
    
    resources:
      sandbox:
        type: databricks:Catalog
        properties:
          metastoreId: ${thisDatabricksMetastore.id}
          name: sandbox
          comment: this catalog is managed by terraform
          properties:
            purpose: testing
      things:
        type: databricks:Schema
        properties:
          catalogName: ${sandbox.name}
          name: things
          comment: this schema is managed by terraform
          properties:
            kind: various
      this:
        type: databricks:Volume
        properties:
          name: quickstart_volume
          catalogName: ${sandbox.name}
          schemaName: ${things.name}
          volumeType: MANAGED
          comment: this volume is managed by terraform
      thisFile:
        type: databricks:File
        name: this
        properties:
          source: /full/path/on/local/system
          path: ${this.volumePath}/fileName
    

    You can also inline sources through content_base64 attribute.

    import * as pulumi from "@pulumi/pulumi";
    import * as databricks from "@pulumi/databricks";
    import * as std from "@pulumi/std";
    
    const initScript = new databricks.File("init_script", {
        contentBase64: std.base64encode({
            input: `#!/bin/bash
    echo "Hello World"
    `,
        }).then(invoke => invoke.result),
        path: `${_this.volumePath}/fileName`,
    });
    
    import pulumi
    import pulumi_databricks as databricks
    import pulumi_std as std
    
    init_script = databricks.File("init_script",
        content_base64=std.base64encode(input="""#!/bin/bash
    echo "Hello World"
    """).result,
        path=f"{this['volumePath']}/fileName")
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-databricks/sdk/go/databricks"
    	"github.com/pulumi/pulumi-std/sdk/go/std"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		invokeBase64encode, err := std.Base64encode(ctx, &std.Base64encodeArgs{
    			Input: "#!/bin/bash\necho \"Hello World\"\n",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = databricks.NewFile(ctx, "init_script", &databricks.FileArgs{
    			ContentBase64: pulumi.String(invokeBase64encode.Result),
    			Path:          pulumi.Sprintf("%v/fileName", this.VolumePath),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Databricks = Pulumi.Databricks;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        var initScript = new Databricks.File("init_script", new()
        {
            ContentBase64 = Std.Base64encode.Invoke(new()
            {
                Input = @"#!/bin/bash
    echo ""Hello World""
    ",
            }).Apply(invoke => invoke.Result),
            Path = $"{@this.VolumePath}/fileName",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.databricks.File;
    import com.pulumi.databricks.FileArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var initScript = new File("initScript", FileArgs.builder()
                .contentBase64(StdFunctions.base64encode(Base64encodeArgs.builder()
                    .input("""
    #!/bin/bash
    echo "Hello World"
                    """)
                    .build()).result())
                .path(String.format("%s/fileName", this_.volumePath()))
                .build());
    
        }
    }
    
    resources:
      initScript:
        type: databricks:File
        name: init_script
        properties:
          contentBase64:
            fn::invoke:
              Function: std:base64encode
              Arguments:
                input: |
                  #!/bin/bash
                  echo "Hello World"              
              Return: result
          path: ${this.volumePath}/fileName
    

    The following resources are often used in the same context:

    Create File Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new File(name: string, args: FileArgs, opts?: CustomResourceOptions);
    @overload
    def File(resource_name: str,
             args: FileArgs,
             opts: Optional[ResourceOptions] = None)
    
    @overload
    def File(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             path: Optional[str] = None,
             content_base64: Optional[str] = None,
             md5: Optional[str] = None,
             remote_file_modified: Optional[bool] = None,
             source: Optional[str] = None)
    func NewFile(ctx *Context, name string, args FileArgs, opts ...ResourceOption) (*File, error)
    public File(string name, FileArgs args, CustomResourceOptions? opts = null)
    public File(String name, FileArgs args)
    public File(String name, FileArgs args, CustomResourceOptions options)
    
    type: databricks:File
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args FileArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args FileArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args FileArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args FileArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args FileArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var fileResource = new Databricks.File("fileResource", new()
    {
        Path = "string",
        ContentBase64 = "string",
        Md5 = "string",
        RemoteFileModified = false,
        Source = "string",
    });
    
    example, err := databricks.NewFile(ctx, "fileResource", &databricks.FileArgs{
    	Path:               pulumi.String("string"),
    	ContentBase64:      pulumi.String("string"),
    	Md5:                pulumi.String("string"),
    	RemoteFileModified: pulumi.Bool(false),
    	Source:             pulumi.String("string"),
    })
    
    var fileResource = new File("fileResource", FileArgs.builder()
        .path("string")
        .contentBase64("string")
        .md5("string")
        .remoteFileModified(false)
        .source("string")
        .build());
    
    file_resource = databricks.File("fileResource",
        path="string",
        content_base64="string",
        md5="string",
        remote_file_modified=False,
        source="string")
    
    const fileResource = new databricks.File("fileResource", {
        path: "string",
        contentBase64: "string",
        md5: "string",
        remoteFileModified: false,
        source: "string",
    });
    
    type: databricks:File
    properties:
        contentBase64: string
        md5: string
        path: string
        remoteFileModified: false
        source: string
    

    File Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The File resource accepts the following input properties:

    Path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    ContentBase64 string
    Contents in base 64 format. Conflicts with source.
    Md5 string
    RemoteFileModified bool
    Source string
    The full absolute path to the file. Conflicts with content_base64.
    Path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    ContentBase64 string
    Contents in base 64 format. Conflicts with source.
    Md5 string
    RemoteFileModified bool
    Source string
    The full absolute path to the file. Conflicts with content_base64.
    path String
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    contentBase64 String
    Contents in base 64 format. Conflicts with source.
    md5 String
    remoteFileModified Boolean
    source String
    The full absolute path to the file. Conflicts with content_base64.
    path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    contentBase64 string
    Contents in base 64 format. Conflicts with source.
    md5 string
    remoteFileModified boolean
    source string
    The full absolute path to the file. Conflicts with content_base64.
    path str
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    content_base64 str
    Contents in base 64 format. Conflicts with source.
    md5 str
    remote_file_modified bool
    source str
    The full absolute path to the file. Conflicts with content_base64.
    path String
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    contentBase64 String
    Contents in base 64 format. Conflicts with source.
    md5 String
    remoteFileModified Boolean
    source String
    The full absolute path to the file. Conflicts with content_base64.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the File resource produces the following output properties:

    FileSize int
    The file size of the file that is being tracked by this resource in bytes.
    Id string
    The provider-assigned unique ID for this managed resource.
    ModificationTime string
    The last time stamp when the file was modified
    FileSize int
    The file size of the file that is being tracked by this resource in bytes.
    Id string
    The provider-assigned unique ID for this managed resource.
    ModificationTime string
    The last time stamp when the file was modified
    fileSize Integer
    The file size of the file that is being tracked by this resource in bytes.
    id String
    The provider-assigned unique ID for this managed resource.
    modificationTime String
    The last time stamp when the file was modified
    fileSize number
    The file size of the file that is being tracked by this resource in bytes.
    id string
    The provider-assigned unique ID for this managed resource.
    modificationTime string
    The last time stamp when the file was modified
    file_size int
    The file size of the file that is being tracked by this resource in bytes.
    id str
    The provider-assigned unique ID for this managed resource.
    modification_time str
    The last time stamp when the file was modified
    fileSize Number
    The file size of the file that is being tracked by this resource in bytes.
    id String
    The provider-assigned unique ID for this managed resource.
    modificationTime String
    The last time stamp when the file was modified

    Look up Existing File Resource

    Get an existing File resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: FileState, opts?: CustomResourceOptions): File
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            content_base64: Optional[str] = None,
            file_size: Optional[int] = None,
            md5: Optional[str] = None,
            modification_time: Optional[str] = None,
            path: Optional[str] = None,
            remote_file_modified: Optional[bool] = None,
            source: Optional[str] = None) -> File
    func GetFile(ctx *Context, name string, id IDInput, state *FileState, opts ...ResourceOption) (*File, error)
    public static File Get(string name, Input<string> id, FileState? state, CustomResourceOptions? opts = null)
    public static File get(String name, Output<String> id, FileState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    ContentBase64 string
    Contents in base 64 format. Conflicts with source.
    FileSize int
    The file size of the file that is being tracked by this resource in bytes.
    Md5 string
    ModificationTime string
    The last time stamp when the file was modified
    Path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    RemoteFileModified bool
    Source string
    The full absolute path to the file. Conflicts with content_base64.
    ContentBase64 string
    Contents in base 64 format. Conflicts with source.
    FileSize int
    The file size of the file that is being tracked by this resource in bytes.
    Md5 string
    ModificationTime string
    The last time stamp when the file was modified
    Path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    RemoteFileModified bool
    Source string
    The full absolute path to the file. Conflicts with content_base64.
    contentBase64 String
    Contents in base 64 format. Conflicts with source.
    fileSize Integer
    The file size of the file that is being tracked by this resource in bytes.
    md5 String
    modificationTime String
    The last time stamp when the file was modified
    path String
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    remoteFileModified Boolean
    source String
    The full absolute path to the file. Conflicts with content_base64.
    contentBase64 string
    Contents in base 64 format. Conflicts with source.
    fileSize number
    The file size of the file that is being tracked by this resource in bytes.
    md5 string
    modificationTime string
    The last time stamp when the file was modified
    path string
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    remoteFileModified boolean
    source string
    The full absolute path to the file. Conflicts with content_base64.
    content_base64 str
    Contents in base 64 format. Conflicts with source.
    file_size int
    The file size of the file that is being tracked by this resource in bytes.
    md5 str
    modification_time str
    The last time stamp when the file was modified
    path str
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    remote_file_modified bool
    source str
    The full absolute path to the file. Conflicts with content_base64.
    contentBase64 String
    Contents in base 64 format. Conflicts with source.
    fileSize Number
    The file size of the file that is being tracked by this resource in bytes.
    md5 String
    modificationTime String
    The last time stamp when the file was modified
    path String
    The path of the file in which you wish to save. For example, /Volumes/main/default/volume1/file.txt.
    remoteFileModified Boolean
    source String
    The full absolute path to the file. Conflicts with content_base64.

    Import

    The resource databricks_file can be imported using the path of the file:

    bash

    $ pulumi import databricks:index/file:File this <path>
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    databricks pulumi/pulumi-databricks
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the databricks Terraform Provider.
    databricks logo
    Databricks v1.50.2 published on Tuesday, Sep 24, 2024 by Pulumi