published on Thursday, Mar 12, 2026 by Pulumi
published on Thursday, Mar 12, 2026 by Pulumi
Gets existing object contents inside an existing bucket in Google Cloud Storage service (GCS). See the official documentation and API.
Warning: The object content will be saved in the state, and visible to everyone who has access to the state file.
Warning: This data source loads all object contents into memory. Limit the results with
match_globorprefix.
Example Usage
Extract object base64 contents from objects:
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const example = gcp.storage.getBucketObjectContents({
bucket: "example-bucket",
matchGlob: "example-{foo,bar}.json",
prefix: "example",
});
export const base64EncodedJsonContents = example.then(example => example.bucketObjects.map(__item => __item.contentBase64));
import pulumi
import pulumi_gcp as gcp
example = gcp.storage.get_bucket_object_contents(bucket="example-bucket",
match_glob="example-{foo,bar}.json",
prefix="example")
pulumi.export("base64EncodedJsonContents", [__item.content_base64 for __item in example.bucket_objects])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/storage"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := storage.GetBucketObjectContents(ctx, &storage.GetBucketObjectContentsArgs{
Bucket: "example-bucket",
MatchGlob: pulumi.StringRef("example-{foo,bar}.json"),
Prefix: pulumi.StringRef("example"),
}, nil);
if err != nil {
return err
}
ctx.Export("base64EncodedJsonContents", pulumi.StringArray(%!v(PANIC=Format method: fatal: A failure has occurred: unlowered splat expression @ example.pp:7,11-49)))
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var example = Gcp.Storage.GetBucketObjectContents.Invoke(new()
{
Bucket = "example-bucket",
MatchGlob = "example-{foo,bar}.json",
Prefix = "example",
});
return new Dictionary<string, object?>
{
["base64EncodedJsonContents"] = example.Apply(getBucketObjectContentsResult => getBucketObjectContentsResult.BucketObjects).Select(__item => __item.ContentBase64).ToList(),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.StorageFunctions;
import com.pulumi.gcp.storage.inputs.GetBucketObjectContentsArgs;
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 = StorageFunctions.getBucketObjectContents(GetBucketObjectContentsArgs.builder()
.bucket("example-bucket")
.matchGlob("example-{foo,bar}.json")
.prefix("example")
.build());
ctx.export("base64EncodedJsonContents", example.bucketObjects().stream().map(element -> element.contentBase64()).collect(toList()));
}
}
Example coming soon!
Using getBucketObjectContents
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 getBucketObjectContents(args: GetBucketObjectContentsArgs, opts?: InvokeOptions): Promise<GetBucketObjectContentsResult>
function getBucketObjectContentsOutput(args: GetBucketObjectContentsOutputArgs, opts?: InvokeOptions): Output<GetBucketObjectContentsResult>def get_bucket_object_contents(bucket: Optional[str] = None,
match_glob: Optional[str] = None,
prefix: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetBucketObjectContentsResult
def get_bucket_object_contents_output(bucket: Optional[pulumi.Input[str]] = None,
match_glob: Optional[pulumi.Input[str]] = None,
prefix: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetBucketObjectContentsResult]func GetBucketObjectContents(ctx *Context, args *GetBucketObjectContentsArgs, opts ...InvokeOption) (*GetBucketObjectContentsResult, error)
func GetBucketObjectContentsOutput(ctx *Context, args *GetBucketObjectContentsOutputArgs, opts ...InvokeOption) GetBucketObjectContentsResultOutput> Note: This function is named GetBucketObjectContents in the Go SDK.
public static class GetBucketObjectContents
{
public static Task<GetBucketObjectContentsResult> InvokeAsync(GetBucketObjectContentsArgs args, InvokeOptions? opts = null)
public static Output<GetBucketObjectContentsResult> Invoke(GetBucketObjectContentsInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetBucketObjectContentsResult> getBucketObjectContents(GetBucketObjectContentsArgs args, InvokeOptions options)
public static Output<GetBucketObjectContentsResult> getBucketObjectContents(GetBucketObjectContentsArgs args, InvokeOptions options)
fn::invoke:
function: gcp:storage/getBucketObjectContents:getBucketObjectContents
arguments:
# arguments dictionaryThe following arguments are supported:
- bucket str
- The name of the containing bucket.
- match_
glob str - A glob pattern used to filter results (for example,
foo*bar). - prefix str
- Filter results to include only objects whose names begin with this prefix.
getBucketObjectContents Result
The following output properties are available:
- Bucket string
- Bucket
Objects List<GetBucket Object Contents Bucket Object> - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- Id string
- The provider-assigned unique ID for this managed resource.
- Match
Glob string - Prefix string
- Bucket string
- Bucket
Objects []GetBucket Object Contents Bucket Object - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- Id string
- The provider-assigned unique ID for this managed resource.
- Match
Glob string - Prefix string
- bucket String
- bucket
Objects List<GetBucket Object Contents Bucket Object> - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- id String
- The provider-assigned unique ID for this managed resource.
- match
Glob String - prefix String
- bucket string
- bucket
Objects GetBucket Object Contents Bucket Object[] - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- id string
- The provider-assigned unique ID for this managed resource.
- match
Glob string - prefix string
- bucket str
- bucket_
objects Sequence[GetBucket Object Contents Bucket Object] - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- id str
- The provider-assigned unique ID for this managed resource.
- match_
glob str - prefix str
- bucket String
- bucket
Objects List<Property Map> - A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
- id String
- The provider-assigned unique ID for this managed resource.
- match
Glob String - prefix String
Supporting Types
GetBucketObjectContentsBucketObject
- Content string
- The content of the object.
- Content
Base64 string - Base64 encoded version of the object content. Use this when dealing with binary data.
- Content
Base64sha512 string - Base64 encoded SHA512 checksum of file content.
- Content
Hexsha512 string - Hex encoded SHA512 checksum of file content.
- Content
Type string - Content-Type of the object data.
- Media
Link string - A url reference to download this object.
- Name string
- The name of the object.
- Self
Link string - A url reference to this object.
- Content string
- The content of the object.
- Content
Base64 string - Base64 encoded version of the object content. Use this when dealing with binary data.
- Content
Base64sha512 string - Base64 encoded SHA512 checksum of file content.
- Content
Hexsha512 string - Hex encoded SHA512 checksum of file content.
- Content
Type string - Content-Type of the object data.
- Media
Link string - A url reference to download this object.
- Name string
- The name of the object.
- Self
Link string - A url reference to this object.
- content String
- The content of the object.
- content
Base64 String - Base64 encoded version of the object content. Use this when dealing with binary data.
- content
Base64sha512 String - Base64 encoded SHA512 checksum of file content.
- content
Hexsha512 String - Hex encoded SHA512 checksum of file content.
- content
Type String - Content-Type of the object data.
- media
Link String - A url reference to download this object.
- name String
- The name of the object.
- self
Link String - A url reference to this object.
- content string
- The content of the object.
- content
Base64 string - Base64 encoded version of the object content. Use this when dealing with binary data.
- content
Base64sha512 string - Base64 encoded SHA512 checksum of file content.
- content
Hexsha512 string - Hex encoded SHA512 checksum of file content.
- content
Type string - Content-Type of the object data.
- media
Link string - A url reference to download this object.
- name string
- The name of the object.
- self
Link string - A url reference to this object.
- content str
- The content of the object.
- content_
base64 str - Base64 encoded version of the object content. Use this when dealing with binary data.
- content_
base64sha512 str - Base64 encoded SHA512 checksum of file content.
- content_
hexsha512 str - Hex encoded SHA512 checksum of file content.
- content_
type str - Content-Type of the object data.
- media_
link str - A url reference to download this object.
- name str
- The name of the object.
- self_
link str - A url reference to this object.
- content String
- The content of the object.
- content
Base64 String - Base64 encoded version of the object content. Use this when dealing with binary data.
- content
Base64sha512 String - Base64 encoded SHA512 checksum of file content.
- content
Hexsha512 String - Hex encoded SHA512 checksum of file content.
- content
Type String - Content-Type of the object data.
- media
Link String - A url reference to download this object.
- name String
- The name of the object.
- self
Link String - A url reference to this object.
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
google-betaTerraform Provider.
published on Thursday, Mar 12, 2026 by Pulumi
