Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

File

The vsphere.File resource can be used to upload files (such as virtual disk files) from the host machine that this provider is running on to a target datastore. The resource can also be used to copy files between datastores, or from one location to another on the same datastore.

Updates to destination parameters such as datacenter, datastore, or destination_file will move the managed file a new destination based on the values of the new settings. If any source parameter is changed, such as source_datastore, source_datacenter or source_file), the resource will be re-created. Depending on if destination parameters are being changed as well, this may result in the destination file either being overwritten or deleted at the old location.

Example Usage

Uploading a file

using Pulumi;
using VSphere = Pulumi.VSphere;

class MyStack : Stack
{
    public MyStack()
    {
        var ubuntuDiskUpload = new VSphere.File("ubuntuDiskUpload", new VSphere.FileArgs
        {
            Datacenter = "my_datacenter",
            Datastore = "local",
            DestinationFile = "/my_path/disks/custom_ubuntu.vmdk",
            SourceFile = "/home/ubuntu/my_disks/custom_ubuntu.vmdk",
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-vsphere/sdk/v2/go/vsphere"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        _, err := vsphere.NewFile(ctx, "ubuntuDiskUpload", &vsphere.FileArgs{
            Datacenter:      pulumi.String("my_datacenter"),
            Datastore:       pulumi.String("local"),
            DestinationFile: pulumi.String("/my_path/disks/custom_ubuntu.vmdk"),
            SourceFile:      pulumi.String("/home/ubuntu/my_disks/custom_ubuntu.vmdk"),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_vsphere as vsphere

ubuntu_disk_upload = vsphere.File("ubuntuDiskUpload",
    datacenter="my_datacenter",
    datastore="local",
    destination_file="/my_path/disks/custom_ubuntu.vmdk",
    source_file="/home/ubuntu/my_disks/custom_ubuntu.vmdk")
import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const ubuntuDiskUpload = new vsphere.File("ubuntu_disk_upload", {
    datacenter: "my_datacenter",
    datastore: "local",
    destinationFile: "/my_path/disks/custom_ubuntu.vmdk",
    sourceFile: "/home/ubuntu/my_disks/custom_ubuntu.vmdk",
});

Copying a file

using Pulumi;
using VSphere = Pulumi.VSphere;

class MyStack : Stack
{
    public MyStack()
    {
        var ubuntuDiskCopy = new VSphere.File("ubuntuDiskCopy", new VSphere.FileArgs
        {
            Datacenter = "my_datacenter",
            Datastore = "local",
            DestinationFile = "/my_path/custom_ubuntu_id.vmdk",
            SourceDatacenter = "my_datacenter",
            SourceDatastore = "local",
            SourceFile = "/my_path/disks/custom_ubuntu.vmdk",
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-vsphere/sdk/v2/go/vsphere"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        _, err := vsphere.NewFile(ctx, "ubuntuDiskCopy", &vsphere.FileArgs{
            Datacenter:       pulumi.String("my_datacenter"),
            Datastore:        pulumi.String("local"),
            DestinationFile:  pulumi.String("/my_path/custom_ubuntu_id.vmdk"),
            SourceDatacenter: pulumi.String("my_datacenter"),
            SourceDatastore:  pulumi.String("local"),
            SourceFile:       pulumi.String("/my_path/disks/custom_ubuntu.vmdk"),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_vsphere as vsphere

ubuntu_disk_copy = vsphere.File("ubuntuDiskCopy",
    datacenter="my_datacenter",
    datastore="local",
    destination_file="/my_path/custom_ubuntu_id.vmdk",
    source_datacenter="my_datacenter",
    source_datastore="local",
    source_file="/my_path/disks/custom_ubuntu.vmdk")
import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const ubuntuDiskCopy = new vsphere.File("ubuntu_disk_copy", {
    datacenter: "my_datacenter",
    datastore: "local",
    destinationFile: "/my_path/custom_ubuntu_id.vmdk",
    sourceDatacenter: "my_datacenter",
    sourceDatastore: "local",
    sourceFile: "/my_path/disks/custom_ubuntu.vmdk",
});

Create a File Resource

new File(name: string, args: FileArgs, opts?: CustomResourceOptions);
def File(resource_name: str, opts: Optional[ResourceOptions] = None, create_directories: Optional[bool] = None, datacenter: Optional[str] = None, datastore: Optional[str] = None, destination_file: Optional[str] = None, source_datacenter: Optional[str] = None, source_datastore: Optional[str] = None, source_file: Optional[str] = None)
func NewFile(ctx *Context, name string, args FileArgs, opts ...ResourceOption) (*File, error)
public File(string name, FileArgs args, CustomResourceOptions? opts = null)
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.
opts ResourceOptions
A bag of options that control this 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.

File Resource Properties

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

Inputs

The File resource accepts the following input properties:

Datastore string

The name of the datastore in which to upload the file to.

DestinationFile string

The path to where the file should be uploaded or copied to on vSphere.

SourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

CreateDirectories bool

Create directories in destination_file path parameter if any missing for copy operation.

Datacenter string

The name of a datacenter in which the file will be uploaded to.

SourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

SourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

Datastore string

The name of the datastore in which to upload the file to.

DestinationFile string

The path to where the file should be uploaded or copied to on vSphere.

SourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

CreateDirectories bool

Create directories in destination_file path parameter if any missing for copy operation.

Datacenter string

The name of a datacenter in which the file will be uploaded to.

SourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

SourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

datastore string

The name of the datastore in which to upload the file to.

destinationFile string

The path to where the file should be uploaded or copied to on vSphere.

sourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

createDirectories boolean

Create directories in destination_file path parameter if any missing for copy operation.

datacenter string

The name of a datacenter in which the file will be uploaded to.

sourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

sourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

datastore str

The name of the datastore in which to upload the file to.

destination_file str

The path to where the file should be uploaded or copied to on vSphere.

source_file str

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

create_directories bool

Create directories in destination_file path parameter if any missing for copy operation.

datacenter str

The name of a datacenter in which the file will be uploaded to.

source_datacenter str

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

source_datastore str

The name of the datastore in which file will be copied from. Forces a new resource if changed.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an 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, create_directories: Optional[bool] = None, datacenter: Optional[str] = None, datastore: Optional[str] = None, destination_file: Optional[str] = None, source_datacenter: Optional[str] = None, source_datastore: Optional[str] = None, source_file: 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)
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.

The following state arguments are supported:

CreateDirectories bool

Create directories in destination_file path parameter if any missing for copy operation.

Datacenter string

The name of a datacenter in which the file will be uploaded to.

Datastore string

The name of the datastore in which to upload the file to.

DestinationFile string

The path to where the file should be uploaded or copied to on vSphere.

SourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

SourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

SourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

CreateDirectories bool

Create directories in destination_file path parameter if any missing for copy operation.

Datacenter string

The name of a datacenter in which the file will be uploaded to.

Datastore string

The name of the datastore in which to upload the file to.

DestinationFile string

The path to where the file should be uploaded or copied to on vSphere.

SourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

SourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

SourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

createDirectories boolean

Create directories in destination_file path parameter if any missing for copy operation.

datacenter string

The name of a datacenter in which the file will be uploaded to.

datastore string

The name of the datastore in which to upload the file to.

destinationFile string

The path to where the file should be uploaded or copied to on vSphere.

sourceDatacenter string

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

sourceDatastore string

The name of the datastore in which file will be copied from. Forces a new resource if changed.

sourceFile string

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

create_directories bool

Create directories in destination_file path parameter if any missing for copy operation.

datacenter str

The name of a datacenter in which the file will be uploaded to.

datastore str

The name of the datastore in which to upload the file to.

destination_file str

The path to where the file should be uploaded or copied to on vSphere.

source_datacenter str

The name of a datacenter in which the file will be copied from. Forces a new resource if changed.

source_datastore str

The name of the datastore in which file will be copied from. Forces a new resource if changed.

source_file str

The path to the file being uploaded from the host to vSphere or copied within vSphere. Forces a new resource if changed.

Package Details

Repository
https://github.com/pulumi/pulumi-vsphere
License
Apache-2.0
Notes
This Pulumi package is based on the vsphere Terraform Provider.