DigitalOcean

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

getImage

Get information on an image for use in other resources (e.g. creating a Droplet based on snapshot). This data source provides all of the image properties as configured on your DigitalOcean account. This is useful if the image in question is not managed by the provider or you need to utilize any of the image’s data.

An error is triggered if zero or more than one result is returned by the query.

Example Usage

Get the data about a snapshot

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

return await Deployment.RunAsync(() => 
{
    var example1 = DigitalOcean.GetImage.Invoke(new()
    {
        Name = "example-1.0.0",
    });

});
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.GetImage(ctx, &GetImageArgs{
			Name: pulumi.StringRef("example-1.0.0"),
		}, 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.GetImageArgs;
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 example1 = DigitaloceanFunctions.getImage(GetImageArgs.builder()
            .name("example-1.0.0")
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example1 = digitalocean.get_image(name="example-1.0.0")
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example1 = pulumi.output(digitalocean.getImage({
    name: "example-1.0.0",
}));
variables:
  example1:
    Fn::Invoke:
      Function: digitalocean:getImage
      Arguments:
        name: example-1.0.0

Reuse the data about a snapshot to create a Droplet

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

return await Deployment.RunAsync(() => 
{
    var exampleImage = DigitalOcean.GetImage.Invoke(new()
    {
        Name = "example-1.0.0",
    });

    var exampleDroplet = new DigitalOcean.Droplet("exampleDroplet", new()
    {
        Image = exampleImage.Apply(getImageResult => getImageResult.Id),
        Region = "nyc2",
        Size = "s-1vcpu-1gb",
    });

});
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 {
		exampleImage, err := digitalocean.GetImage(ctx, &GetImageArgs{
			Name: pulumi.StringRef("example-1.0.0"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDroplet(ctx, "exampleDroplet", &digitalocean.DropletArgs{
			Image:  pulumi.Int(exampleImage.Id),
			Region: pulumi.String("nyc2"),
			Size:   pulumi.String("s-1vcpu-1gb"),
		})
		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.GetImageArgs;
import com.pulumi.digitalocean.Droplet;
import com.pulumi.digitalocean.DropletArgs;
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 exampleImage = DigitaloceanFunctions.getImage(GetImageArgs.builder()
            .name("example-1.0.0")
            .build());

        var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()        
            .image(exampleImage.applyValue(getImageResult -> getImageResult.id()))
            .region("nyc2")
            .size("s-1vcpu-1gb")
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example_image = digitalocean.get_image(name="example-1.0.0")
example_droplet = digitalocean.Droplet("exampleDroplet",
    image=example_image.id,
    region="nyc2",
    size="s-1vcpu-1gb")
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const exampleImage = digitalocean.getImage({
    name: "example-1.0.0",
});
const exampleDroplet = new digitalocean.Droplet("exampleDroplet", {
    image: exampleImage.then(exampleImage => exampleImage.id),
    region: "nyc2",
    size: "s-1vcpu-1gb",
});
resources:
  exampleDroplet:
    type: digitalocean:Droplet
    properties:
      image: ${exampleImage.id}
      region: nyc2
      size: s-1vcpu-1gb
variables:
  exampleImage:
    Fn::Invoke:
      Function: digitalocean:getImage
      Arguments:
        name: example-1.0.0

Get the data about an official image

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

return await Deployment.RunAsync(() => 
{
    var example2 = DigitalOcean.GetImage.Invoke(new()
    {
        Slug = "ubuntu-18-04-x64",
    });

});
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.GetImage(ctx, &GetImageArgs{
			Slug: pulumi.StringRef("ubuntu-18-04-x64"),
		}, 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.GetImageArgs;
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 example2 = DigitaloceanFunctions.getImage(GetImageArgs.builder()
            .slug("ubuntu-18-04-x64")
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example2 = digitalocean.get_image(slug="ubuntu-18-04-x64")
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example2 = pulumi.output(digitalocean.getImage({
    slug: "ubuntu-18-04-x64",
}));
variables:
  example2:
    Fn::Invoke:
      Function: digitalocean:getImage
      Arguments:
        slug: ubuntu-18-04-x64

Using getImage

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 getImage(args: GetImageArgs, opts?: InvokeOptions): Promise<GetImageResult>
function getImageOutput(args: GetImageOutputArgs, opts?: InvokeOptions): Output<GetImageResult>
def get_image(id: Optional[int] = None,
              name: Optional[str] = None,
              slug: Optional[str] = None,
              source: Optional[str] = None,
              opts: Optional[InvokeOptions] = None) -> GetImageResult
def get_image_output(id: Optional[pulumi.Input[int]] = None,
              name: Optional[pulumi.Input[str]] = None,
              slug: Optional[pulumi.Input[str]] = None,
              source: Optional[pulumi.Input[str]] = None,
              opts: Optional[InvokeOptions] = None) -> Output[GetImageResult]
func GetImage(ctx *Context, args *GetImageArgs, opts ...InvokeOption) (*GetImageResult, error)
func GetImageOutput(ctx *Context, args *GetImageOutputArgs, opts ...InvokeOption) GetImageResultOutput

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

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

The following arguments are supported:

Id int

The id of the image

Name string

The name of the image.

Slug string

The slug of the official image.

Source string

Restrict the search to one of the following categories of images:

Id int

The id of the image

Name string

The name of the image.

Slug string

The slug of the official image.

Source string

Restrict the search to one of the following categories of images:

id Integer

The id of the image

name String

The name of the image.

slug String

The slug of the official image.

source String

Restrict the search to one of the following categories of images:

id number

The id of the image

name string

The name of the image.

slug string

The slug of the official image.

source string

Restrict the search to one of the following categories of images:

id int

The id of the image

name str

The name of the image.

slug str

The slug of the official image.

source str

Restrict the search to one of the following categories of images:

id Number

The id of the image

name String

The name of the image.

slug String

The slug of the official image.

source String

Restrict the search to one of the following categories of images:

getImage Result

The following output properties are available:

Created string
Description string
Distribution string

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
ErrorMessage string
Id int
Image string

The id of the image (legacy parameter).

MinDiskSize int
Name string
Private bool

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
Regions List<string>
SizeGigabytes double
Slug string
Status string
Tags List<string>
Type string
Source string
Created string
Description string
Distribution string

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
ErrorMessage string
Id int
Image string

The id of the image (legacy parameter).

MinDiskSize int
Name string
Private bool

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
Regions []string
SizeGigabytes float64
Slug string
Status string
Tags []string
Type string
Source string
created String
description String
distribution String

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
errorMessage String
id Integer
image String

The id of the image (legacy parameter).

minDiskSize Integer
name String
private_ Boolean

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
regions List<String>
sizeGigabytes Double
slug String
status String
tags List<String>
type String
source String
created string
description string
distribution string

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
errorMessage string
id number
image string

The id of the image (legacy parameter).

minDiskSize number
name string
private boolean

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
regions string[]
sizeGigabytes number
slug string
status string
tags string[]
type string
source string
created str
description str
distribution str

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
error_message str
id int
image str

The id of the image (legacy parameter).

min_disk_size int
name str
private bool

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
regions Sequence[str]
size_gigabytes float
slug str
status str
tags Sequence[str]
type str
source str
created String
description String
distribution String

The name of the distribution of the OS of the image.

  • min_disk_size: The minimum 'disk' required for the image.
  • size_gigabytes: The size of the image in GB.
errorMessage String
id Number
image String

The id of the image (legacy parameter).

minDiskSize Number
name String
private Boolean

Is image a public image or not. Public images represent Linux distributions or One-Click Applications, while non-public images represent snapshots and backups and are only available within your account.

  • regions: A set of the regions that the image is available in.
  • tags: A set of tags applied to the image
  • created: When the image was created
  • status: Current status of the image
  • error_message: Any applicable error message pertaining to the image
regions List<String>
sizeGigabytes Number
slug String
status String
tags List<String>
type String
source 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.