getVolumeSnapshot

Volume snapshots are saved instances of a block storage volume. Use this data source to retrieve the ID of a DigitalOcean volume snapshot for use in other resources.

Example Usage

Get the volume snapshot:

import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";
const snapshot = digitalocean.getVolumeSnapshot({
nameRegex: "^web",
region: "nyc3",
mostRecent: true,
});
import pulumi
import pulumi_digitalocean as digitalocean
snapshot = digitalocean.get_volume_snapshot(name_regex="^web",
region="nyc3",
most_recent=True)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;
return await Deployment.RunAsync(() =>
{
var snapshot = DigitalOcean.GetVolumeSnapshot.Invoke(new()
{
NameRegex = "^web",
Region = "nyc3",
MostRecent = true,
});
});
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.LookupVolumeSnapshot(ctx, &digitalocean.LookupVolumeSnapshotArgs{
NameRegex: pulumi.StringRef("^web"),
Region: pulumi.StringRef("nyc3"),
MostRecent: pulumi.BoolRef(true),
}, 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.GetVolumeSnapshotArgs;
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 snapshot = DigitaloceanFunctions.getVolumeSnapshot(GetVolumeSnapshotArgs.builder()
.nameRegex("^web")
.region("nyc3")
.mostRecent(true)
.build());
}
}
variables:
snapshot:
fn::invoke:
function: digitalocean:getVolumeSnapshot
arguments:
nameRegex: ^web
region: nyc3
mostRecent: true

Reuse the data about a volume snapshot to create a new volume based on it:

import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";
const snapshot = digitalocean.getVolumeSnapshot({
nameRegex: "^web",
region: "nyc3",
mostRecent: true,
});
const foobar = new digitalocean.Volume("foobar", {
region: digitalocean.Region.NYC3,
name: "baz",
size: 100,
snapshotId: snapshot.then(snapshot => snapshot.id),
});
import pulumi
import pulumi_digitalocean as digitalocean
snapshot = digitalocean.get_volume_snapshot(name_regex="^web",
region="nyc3",
most_recent=True)
foobar = digitalocean.Volume("foobar",
region=digitalocean.Region.NYC3,
name="baz",
size=100,
snapshot_id=snapshot.id)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;
return await Deployment.RunAsync(() =>
{
var snapshot = DigitalOcean.GetVolumeSnapshot.Invoke(new()
{
NameRegex = "^web",
Region = "nyc3",
MostRecent = true,
});
var foobar = new DigitalOcean.Volume("foobar", new()
{
Region = DigitalOcean.Region.NYC3,
Name = "baz",
Size = 100,
SnapshotId = snapshot.Apply(getVolumeSnapshotResult => getVolumeSnapshotResult.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 {
snapshot, err := digitalocean.LookupVolumeSnapshot(ctx, &digitalocean.LookupVolumeSnapshotArgs{
NameRegex: pulumi.StringRef("^web"),
Region: pulumi.StringRef("nyc3"),
MostRecent: pulumi.BoolRef(true),
}, nil)
if err != nil {
return err
}
_, err = digitalocean.NewVolume(ctx, "foobar", &digitalocean.VolumeArgs{
Region: pulumi.String(digitalocean.RegionNYC3),
Name: pulumi.String("baz"),
Size: pulumi.Int(100),
SnapshotId: pulumi.String(snapshot.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.GetVolumeSnapshotArgs;
import com.pulumi.digitalocean.Volume;
import com.pulumi.digitalocean.VolumeArgs;
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 snapshot = DigitaloceanFunctions.getVolumeSnapshot(GetVolumeSnapshotArgs.builder()
.nameRegex("^web")
.region("nyc3")
.mostRecent(true)
.build());
var foobar = new Volume("foobar", VolumeArgs.builder()
.region("nyc3")
.name("baz")
.size(100)
.snapshotId(snapshot.id())
.build());
}
}
resources:
foobar:
type: digitalocean:Volume
properties:
region: nyc3
name: baz
size: 100
snapshotId: ${snapshot.id}
variables:
snapshot:
fn::invoke:
function: digitalocean:getVolumeSnapshot
arguments:
nameRegex: ^web
region: nyc3
mostRecent: true

Return

A collection of values returned by getVolumeSnapshot.

Parameters

argument

A collection of arguments for invoking getVolumeSnapshot.


suspend fun getVolumeSnapshot(mostRecent: Boolean? = null, name: String? = null, nameRegex: String? = null, region: String? = null): GetVolumeSnapshotResult

Return

A collection of values returned by getVolumeSnapshot.

Parameters

mostRecent

If more than one result is returned, use the most recent volume snapshot.

NOTE: If more or less than a single match is returned by the search, the provider will fail. Ensure that your search is specific enough to return a single volume snapshot ID only, or use most_recent to choose the most recent one.

name

The name of the volume snapshot.

nameRegex

A regex string to apply to the volume snapshot list returned by DigitalOcean. This allows more advanced filtering not supported from the DigitalOcean API. This filtering is done locally on what DigitalOcean returns.

region

A "slug" representing a DigitalOcean region (e.g. nyc1). If set, only volume snapshots available in the region will be returned.

See also


Return

A collection of values returned by getVolumeSnapshot.

Parameters

argument

Builder for com.pulumi.digitalocean.kotlin.inputs.GetVolumeSnapshotPlainArgs.

See also