get Spaces Bucket Object
The Spaces object data source allows access to the metadata and optionally (see below) content of an object stored inside a Spaces bucket.
Note: The content of an object (
body
field) is available only for objects which have a human-readableContent-Type
(text/*
andapplication/json
). This is to prevent printing unsafe characters and potentially downloading large amount of data which would be thrown away in favor of metadata.
Example Usage
The following example retrieves a text object (which must have a Content-Type
value starting with text/
) and uses it as the user_data
for a Droplet:
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";
const bootstrapScript = digitalocean.getSpacesBucketObject({
bucket: "ourcorp-deploy-config",
region: "nyc3",
key: "droplet-bootstrap-script.sh",
});
const web = new digitalocean.Droplet("web", {
image: "ubuntu-18-04-x64",
name: "web-1",
region: digitalocean.Region.NYC2,
size: digitalocean.DropletSlug.DropletS1VCPU1GB,
userData: bootstrapScript.then(bootstrapScript => bootstrapScript.body),
});
import pulumi
import pulumi_digitalocean as digitalocean
bootstrap_script = digitalocean.get_spaces_bucket_object(bucket="ourcorp-deploy-config",
region="nyc3",
key="droplet-bootstrap-script.sh")
web = digitalocean.Droplet("web",
image="ubuntu-18-04-x64",
name="web-1",
region=digitalocean.Region.NYC2,
size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
user_data=bootstrap_script.body)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;
return await Deployment.RunAsync(() =>
{
var bootstrapScript = DigitalOcean.GetSpacesBucketObject.Invoke(new()
{
Bucket = "ourcorp-deploy-config",
Region = "nyc3",
Key = "droplet-bootstrap-script.sh",
});
var web = new DigitalOcean.Droplet("web", new()
{
Image = "ubuntu-18-04-x64",
Name = "web-1",
Region = DigitalOcean.Region.NYC2,
Size = DigitalOcean.DropletSlug.DropletS1VCPU1GB,
UserData = bootstrapScript.Apply(getSpacesBucketObjectResult => getSpacesBucketObjectResult.Body),
});
});
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 {
bootstrapScript, err := digitalocean.LookupSpacesBucketObject(ctx, &digitalocean.LookupSpacesBucketObjectArgs{
Bucket: "ourcorp-deploy-config",
Region: "nyc3",
Key: "droplet-bootstrap-script.sh",
}, nil)
if err != nil {
return err
}
_, err = digitalocean.NewDroplet(ctx, "web", &digitalocean.DropletArgs{
Image: pulumi.String("ubuntu-18-04-x64"),
Name: pulumi.String("web-1"),
Region: pulumi.String(digitalocean.RegionNYC2),
Size: pulumi.String(digitalocean.DropletSlugDropletS1VCPU1GB),
UserData: pulumi.String(bootstrapScript.Body),
})
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.GetSpacesBucketObjectArgs;
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 bootstrapScript = DigitaloceanFunctions.getSpacesBucketObject(GetSpacesBucketObjectArgs.builder()
.bucket("ourcorp-deploy-config")
.region("nyc3")
.key("droplet-bootstrap-script.sh")
.build());
var web = new Droplet("web", DropletArgs.builder()
.image("ubuntu-18-04-x64")
.name("web-1")
.region("nyc2")
.size("s-1vcpu-1gb")
.userData(bootstrapScript.body())
.build());
}
}
resources:
web:
type: digitalocean:Droplet
properties:
image: ubuntu-18-04-x64
name: web-1
region: nyc2
size: s-1vcpu-1gb
userData: ${bootstrapScript.body}
variables:
bootstrapScript:
fn::invoke:
function: digitalocean:getSpacesBucketObject
arguments:
bucket: ourcorp-deploy-config
region: nyc3
key: droplet-bootstrap-script.sh
Return
A collection of values returned by getSpacesBucketObject. */
Parameters
A collection of arguments for invoking getSpacesBucketObject.
Return
A collection of values returned by getSpacesBucketObject.
Parameters
The name of the bucket to read the object from.
The full path to the object inside the bucket
The slug of the region where the bucket is stored.
Specific version ID of the object returned (defaults to latest version)
See also
Return
A collection of values returned by getSpacesBucketObject.
Parameters
Builder for com.pulumi.digitalocean.kotlin.inputs.GetSpacesBucketObjectPlainArgs.