DigitalOcean

v4.16.0 published on Wednesday, Sep 28, 2022 by Pulumi

getVolume

Get information on a volume for use in other resources. This data source provides all of the volumes properties as configured on your DigitalOcean account. This is useful if the volume in question is not managed by the provider or you need to utilize any of the volumes data.

An error is triggered if the provided volume name does not exist.

Example Usage

Get the volume

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var example = DigitalOcean.GetVolume.Invoke(new()
    {
        Name = "app-data",
        Region = "nyc3",
    });

});
package main

import (
	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := digitalocean.LookupVolume(ctx, &GetVolumeArgs{
			Name:   "app-data",
			Region: pulumi.StringRef("nyc3"),
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DigitaloceanFunctions;
import com.pulumi.digitalocean.inputs.GetVolumeArgs;
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) {
        final var example = DigitaloceanFunctions.getVolume(GetVolumeArgs.builder()
            .name("app-data")
            .region("nyc3")
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example = digitalocean.get_volume(name="app-data",
    region="nyc3")
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example = pulumi.output(digitalocean.getVolume({
    name: "app-data",
    region: "nyc3",
}));
variables:
  example:
    Fn::Invoke:
      Function: digitalocean:getVolume
      Arguments:
        name: app-data
        region: nyc3

Reuse the data about a volume to attach it to a Droplet

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var exampleVolume = DigitalOcean.GetVolume.Invoke(new()
    {
        Name = "app-data",
        Region = "nyc3",
    });

    var exampleDroplet = new DigitalOcean.Droplet("exampleDroplet", new()
    {
        Size = "s-1vcpu-1gb",
        Image = "ubuntu-18-04-x64",
        Region = "nyc3",
    });

    var foobar = new DigitalOcean.VolumeAttachment("foobar", new()
    {
        DropletId = exampleDroplet.Id,
        VolumeId = exampleVolume.Apply(getVolumeResult => getVolumeResult.Id),
    });

});
package main

import (
	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		exampleVolume, err := digitalocean.LookupVolume(ctx, &GetVolumeArgs{
			Name:   "app-data",
			Region: pulumi.StringRef("nyc3"),
		}, nil)
		if err != nil {
			return err
		}
		exampleDroplet, err := digitalocean.NewDroplet(ctx, "exampleDroplet", &digitalocean.DropletArgs{
			Size:   pulumi.String("s-1vcpu-1gb"),
			Image:  pulumi.String("ubuntu-18-04-x64"),
			Region: pulumi.String("nyc3"),
		})
		if err != nil {
			return err
		}
		_, err = digitalocean.NewVolumeAttachment(ctx, "foobar", &digitalocean.VolumeAttachmentArgs{
			DropletId: exampleDroplet.ID(),
			VolumeId:  pulumi.String(exampleVolume.Id),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DigitaloceanFunctions;
import com.pulumi.digitalocean.inputs.GetVolumeArgs;
import com.pulumi.digitalocean.Droplet;
import com.pulumi.digitalocean.DropletArgs;
import com.pulumi.digitalocean.VolumeAttachment;
import com.pulumi.digitalocean.VolumeAttachmentArgs;
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) {
        final var exampleVolume = DigitaloceanFunctions.getVolume(GetVolumeArgs.builder()
            .name("app-data")
            .region("nyc3")
            .build());

        var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()        
            .size("s-1vcpu-1gb")
            .image("ubuntu-18-04-x64")
            .region("nyc3")
            .build());

        var foobar = new VolumeAttachment("foobar", VolumeAttachmentArgs.builder()        
            .dropletId(exampleDroplet.id())
            .volumeId(exampleVolume.applyValue(getVolumeResult -> getVolumeResult.id()))
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example_volume = digitalocean.get_volume(name="app-data",
    region="nyc3")
example_droplet = digitalocean.Droplet("exampleDroplet",
    size="s-1vcpu-1gb",
    image="ubuntu-18-04-x64",
    region="nyc3")
foobar = digitalocean.VolumeAttachment("foobar",
    droplet_id=example_droplet.id,
    volume_id=example_volume.id)
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const exampleVolume = digitalocean.getVolume({
    name: "app-data",
    region: "nyc3",
});
const exampleDroplet = new digitalocean.Droplet("exampleDroplet", {
    size: "s-1vcpu-1gb",
    image: "ubuntu-18-04-x64",
    region: "nyc3",
});
const foobar = new digitalocean.VolumeAttachment("foobar", {
    dropletId: exampleDroplet.id,
    volumeId: exampleVolume.then(exampleVolume => exampleVolume.id),
});
resources:
  exampleDroplet:
    type: digitalocean:Droplet
    properties:
      size: s-1vcpu-1gb
      image: ubuntu-18-04-x64
      region: nyc3
  foobar:
    type: digitalocean:VolumeAttachment
    properties:
      dropletId: ${exampleDroplet.id}
      volumeId: ${exampleVolume.id}
variables:
  exampleVolume:
    Fn::Invoke:
      Function: digitalocean:getVolume
      Arguments:
        name: app-data
        region: nyc3

Using getVolume

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getVolume(args: GetVolumeArgs, opts?: InvokeOptions): Promise<GetVolumeResult>
function getVolumeOutput(args: GetVolumeOutputArgs, opts?: InvokeOptions): Output<GetVolumeResult>
def get_volume(description: Optional[str] = None,
               name: Optional[str] = None,
               region: Optional[str] = None,
               opts: Optional[InvokeOptions] = None) -> GetVolumeResult
def get_volume_output(description: Optional[pulumi.Input[str]] = None,
               name: Optional[pulumi.Input[str]] = None,
               region: Optional[pulumi.Input[str]] = None,
               opts: Optional[InvokeOptions] = None) -> Output[GetVolumeResult]
func LookupVolume(ctx *Context, args *LookupVolumeArgs, opts ...InvokeOption) (*LookupVolumeResult, error)
func LookupVolumeOutput(ctx *Context, args *LookupVolumeOutputArgs, opts ...InvokeOption) LookupVolumeResultOutput

> Note: This function is named LookupVolume in the Go SDK.

public static class GetVolume 
{
    public static Task<GetVolumeResult> InvokeAsync(GetVolumeArgs args, InvokeOptions? opts = null)
    public static Output<GetVolumeResult> Invoke(GetVolumeInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetVolumeResult> getVolume(GetVolumeArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
  function: digitalocean:index/getVolume:getVolume
  arguments:
    # arguments dictionary

The following arguments are supported:

Name string

The name of block storage volume.

Description string

Text describing a block storage volume.

Region string

The region the block storage volume is provisioned in.

Name string

The name of block storage volume.

Description string

Text describing a block storage volume.

Region string

The region the block storage volume is provisioned in.

name String

The name of block storage volume.

description String

Text describing a block storage volume.

region String

The region the block storage volume is provisioned in.

name string

The name of block storage volume.

description string

Text describing a block storage volume.

region string

The region the block storage volume is provisioned in.

name str

The name of block storage volume.

description str

Text describing a block storage volume.

region str

The region the block storage volume is provisioned in.

name String

The name of block storage volume.

description String

Text describing a block storage volume.

region String

The region the block storage volume is provisioned in.

getVolume Result

The following output properties are available:

DropletIds List<int>

A list of associated Droplet ids.

FilesystemLabel string

Filesystem label currently in-use on the block storage volume.

FilesystemType string

Filesystem type currently in-use on the block storage volume.

Id string

The provider-assigned unique ID for this managed resource.

Name string
Size int

The size of the block storage volume in GiB.

Tags List<string>

A list of the tags associated to the Volume.

Urn string
Description string

Text describing a block storage volume.

Region string
DropletIds []int

A list of associated Droplet ids.

FilesystemLabel string

Filesystem label currently in-use on the block storage volume.

FilesystemType string

Filesystem type currently in-use on the block storage volume.

Id string

The provider-assigned unique ID for this managed resource.

Name string
Size int

The size of the block storage volume in GiB.

Tags []string

A list of the tags associated to the Volume.

Urn string
Description string

Text describing a block storage volume.

Region string
dropletIds List<Integer>

A list of associated Droplet ids.

filesystemLabel String

Filesystem label currently in-use on the block storage volume.

filesystemType String

Filesystem type currently in-use on the block storage volume.

id String

The provider-assigned unique ID for this managed resource.

name String
size Integer

The size of the block storage volume in GiB.

tags List<String>

A list of the tags associated to the Volume.

urn String
description String

Text describing a block storage volume.

region String
dropletIds number[]

A list of associated Droplet ids.

filesystemLabel string

Filesystem label currently in-use on the block storage volume.

filesystemType string

Filesystem type currently in-use on the block storage volume.

id string

The provider-assigned unique ID for this managed resource.

name string
size number

The size of the block storage volume in GiB.

tags string[]

A list of the tags associated to the Volume.

urn string
description string

Text describing a block storage volume.

region string
droplet_ids Sequence[int]

A list of associated Droplet ids.

filesystem_label str

Filesystem label currently in-use on the block storage volume.

filesystem_type str

Filesystem type currently in-use on the block storage volume.

id str

The provider-assigned unique ID for this managed resource.

name str
size int

The size of the block storage volume in GiB.

tags Sequence[str]

A list of the tags associated to the Volume.

urn str
description str

Text describing a block storage volume.

region str
dropletIds List<Number>

A list of associated Droplet ids.

filesystemLabel String

Filesystem label currently in-use on the block storage volume.

filesystemType String

Filesystem type currently in-use on the block storage volume.

id String

The provider-assigned unique ID for this managed resource.

name String
size Number

The size of the block storage volume in GiB.

tags List<String>

A list of the tags associated to the Volume.

urn String
description String

Text describing a block storage volume.

region String

Package Details

Repository
https://github.com/pulumi/pulumi-digitalocean
License
Apache-2.0
Notes

This Pulumi package is based on the digitalocean Terraform Provider.