1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. storage
  5. Folder
Google Cloud v8.25.0 published on Thursday, Apr 3, 2025 by Pulumi

gcp.storage.Folder

Explore with Pulumi AI

A Google Cloud Storage Folder.

The Folder resource represents a folder in a Cloud Storage bucket with hierarchical namespace enabled

To get more information about Folder, see:

Example Usage

Storage Folder Basic

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const bucket = new gcp.storage.Bucket("bucket", {
    name: "my-bucket",
    location: "EU",
    uniformBucketLevelAccess: true,
    hierarchicalNamespace: {
        enabled: true,
    },
});
const folder = new gcp.storage.Folder("folder", {
    bucket: bucket.name,
    name: "parent-folder/",
});
const subfolder = new gcp.storage.Folder("subfolder", {
    bucket: bucket.name,
    name: pulumi.interpolate`${folder.name}subfolder/`,
});
Copy
import pulumi
import pulumi_gcp as gcp

bucket = gcp.storage.Bucket("bucket",
    name="my-bucket",
    location="EU",
    uniform_bucket_level_access=True,
    hierarchical_namespace={
        "enabled": True,
    })
folder = gcp.storage.Folder("folder",
    bucket=bucket.name,
    name="parent-folder/")
subfolder = gcp.storage.Folder("subfolder",
    bucket=bucket.name,
    name=folder.name.apply(lambda name: f"{name}subfolder/"))
Copy
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/storage"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		bucket, err := storage.NewBucket(ctx, "bucket", &storage.BucketArgs{
			Name:                     pulumi.String("my-bucket"),
			Location:                 pulumi.String("EU"),
			UniformBucketLevelAccess: pulumi.Bool(true),
			HierarchicalNamespace: &storage.BucketHierarchicalNamespaceArgs{
				Enabled: pulumi.Bool(true),
			},
		})
		if err != nil {
			return err
		}
		folder, err := storage.NewFolder(ctx, "folder", &storage.FolderArgs{
			Bucket: bucket.Name,
			Name:   pulumi.String("parent-folder/"),
		})
		if err != nil {
			return err
		}
		_, err = storage.NewFolder(ctx, "subfolder", &storage.FolderArgs{
			Bucket: bucket.Name,
			Name: folder.Name.ApplyT(func(name string) (string, error) {
				return fmt.Sprintf("%vsubfolder/", name), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() => 
{
    var bucket = new Gcp.Storage.Bucket("bucket", new()
    {
        Name = "my-bucket",
        Location = "EU",
        UniformBucketLevelAccess = true,
        HierarchicalNamespace = new Gcp.Storage.Inputs.BucketHierarchicalNamespaceArgs
        {
            Enabled = true,
        },
    });

    var folder = new Gcp.Storage.Folder("folder", new()
    {
        Bucket = bucket.Name,
        Name = "parent-folder/",
    });

    var subfolder = new Gcp.Storage.Folder("subfolder", new()
    {
        Bucket = bucket.Name,
        Name = folder.Name.Apply(name => $"{name}subfolder/"),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.storage.Bucket;
import com.pulumi.gcp.storage.BucketArgs;
import com.pulumi.gcp.storage.inputs.BucketHierarchicalNamespaceArgs;
import com.pulumi.gcp.storage.Folder;
import com.pulumi.gcp.storage.FolderArgs;
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) {
        var bucket = new Bucket("bucket", BucketArgs.builder()
            .name("my-bucket")
            .location("EU")
            .uniformBucketLevelAccess(true)
            .hierarchicalNamespace(BucketHierarchicalNamespaceArgs.builder()
                .enabled(true)
                .build())
            .build());

        var folder = new Folder("folder", FolderArgs.builder()
            .bucket(bucket.name())
            .name("parent-folder/")
            .build());

        var subfolder = new Folder("subfolder", FolderArgs.builder()
            .bucket(bucket.name())
            .name(folder.name().applyValue(name -> String.format("%ssubfolder/", name)))
            .build());

    }
}
Copy
resources:
  bucket:
    type: gcp:storage:Bucket
    properties:
      name: my-bucket
      location: EU
      uniformBucketLevelAccess: true
      hierarchicalNamespace:
        enabled: true
  folder:
    type: gcp:storage:Folder
    properties:
      bucket: ${bucket.name}
      name: parent-folder/
  subfolder:
    type: gcp:storage:Folder
    properties:
      bucket: ${bucket.name}
      name: ${folder.name}subfolder/
Copy

Create Folder Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new Folder(name: string, args: FolderArgs, opts?: CustomResourceOptions);
@overload
def Folder(resource_name: str,
           args: FolderArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def Folder(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           bucket: Optional[str] = None,
           force_destroy: Optional[bool] = None,
           name: Optional[str] = None)
func NewFolder(ctx *Context, name string, args FolderArgs, opts ...ResourceOption) (*Folder, error)
public Folder(string name, FolderArgs args, CustomResourceOptions? opts = null)
public Folder(String name, FolderArgs args)
public Folder(String name, FolderArgs args, CustomResourceOptions options)
type: gcp:storage:Folder
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. FolderArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. FolderArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. FolderArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. FolderArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. FolderArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var gcpFolderResource = new Gcp.Storage.Folder("gcpFolderResource", new()
{
    Bucket = "string",
    ForceDestroy = false,
    Name = "string",
});
Copy
example, err := storage.NewFolder(ctx, "gcpFolderResource", &storage.FolderArgs{
	Bucket:       pulumi.String("string"),
	ForceDestroy: pulumi.Bool(false),
	Name:         pulumi.String("string"),
})
Copy
var gcpFolderResource = new Folder("gcpFolderResource", FolderArgs.builder()
    .bucket("string")
    .forceDestroy(false)
    .name("string")
    .build());
Copy
gcp_folder_resource = gcp.storage.Folder("gcpFolderResource",
    bucket="string",
    force_destroy=False,
    name="string")
Copy
const gcpFolderResource = new gcp.storage.Folder("gcpFolderResource", {
    bucket: "string",
    forceDestroy: false,
    name: "string",
});
Copy
type: gcp:storage:Folder
properties:
    bucket: string
    forceDestroy: false
    name: string
Copy

Folder Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The Folder resource accepts the following input properties:

Bucket
This property is required.
Changes to this property will trigger replacement.
string
The name of the bucket that contains the folder.
ForceDestroy bool
If set to true, items within folder if any will be force destroyed.
Name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


Bucket
This property is required.
Changes to this property will trigger replacement.
string
The name of the bucket that contains the folder.
ForceDestroy bool
If set to true, items within folder if any will be force destroyed.
Name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


bucket
This property is required.
Changes to this property will trigger replacement.
String
The name of the bucket that contains the folder.
forceDestroy Boolean
If set to true, items within folder if any will be force destroyed.
name Changes to this property will trigger replacement. String
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


bucket
This property is required.
Changes to this property will trigger replacement.
string
The name of the bucket that contains the folder.
forceDestroy boolean
If set to true, items within folder if any will be force destroyed.
name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


bucket
This property is required.
Changes to this property will trigger replacement.
str
The name of the bucket that contains the folder.
force_destroy bool
If set to true, items within folder if any will be force destroyed.
name Changes to this property will trigger replacement. str
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


bucket
This property is required.
Changes to this property will trigger replacement.
String
The name of the bucket that contains the folder.
forceDestroy Boolean
If set to true, items within folder if any will be force destroyed.
name Changes to this property will trigger replacement. String
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


Outputs

All input properties are implicitly available as output properties. Additionally, the Folder resource produces the following output properties:

CreateTime string
The timestamp at which this folder was created.
Id string
The provider-assigned unique ID for this managed resource.
Metageneration string
The metadata generation of the folder.
SelfLink string
The URI of the created resource.
UpdateTime string
The timestamp at which this folder was most recently updated.
CreateTime string
The timestamp at which this folder was created.
Id string
The provider-assigned unique ID for this managed resource.
Metageneration string
The metadata generation of the folder.
SelfLink string
The URI of the created resource.
UpdateTime string
The timestamp at which this folder was most recently updated.
createTime String
The timestamp at which this folder was created.
id String
The provider-assigned unique ID for this managed resource.
metageneration String
The metadata generation of the folder.
selfLink String
The URI of the created resource.
updateTime String
The timestamp at which this folder was most recently updated.
createTime string
The timestamp at which this folder was created.
id string
The provider-assigned unique ID for this managed resource.
metageneration string
The metadata generation of the folder.
selfLink string
The URI of the created resource.
updateTime string
The timestamp at which this folder was most recently updated.
create_time str
The timestamp at which this folder was created.
id str
The provider-assigned unique ID for this managed resource.
metageneration str
The metadata generation of the folder.
self_link str
The URI of the created resource.
update_time str
The timestamp at which this folder was most recently updated.
createTime String
The timestamp at which this folder was created.
id String
The provider-assigned unique ID for this managed resource.
metageneration String
The metadata generation of the folder.
selfLink String
The URI of the created resource.
updateTime String
The timestamp at which this folder was most recently updated.

Look up Existing Folder Resource

Get an existing Folder resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: FolderState, opts?: CustomResourceOptions): Folder
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        bucket: Optional[str] = None,
        create_time: Optional[str] = None,
        force_destroy: Optional[bool] = None,
        metageneration: Optional[str] = None,
        name: Optional[str] = None,
        self_link: Optional[str] = None,
        update_time: Optional[str] = None) -> Folder
func GetFolder(ctx *Context, name string, id IDInput, state *FolderState, opts ...ResourceOption) (*Folder, error)
public static Folder Get(string name, Input<string> id, FolderState? state, CustomResourceOptions? opts = null)
public static Folder get(String name, Output<String> id, FolderState state, CustomResourceOptions options)
resources:  _:    type: gcp:storage:Folder    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Bucket Changes to this property will trigger replacement. string
The name of the bucket that contains the folder.
CreateTime string
The timestamp at which this folder was created.
ForceDestroy bool
If set to true, items within folder if any will be force destroyed.
Metageneration string
The metadata generation of the folder.
Name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


SelfLink string
The URI of the created resource.
UpdateTime string
The timestamp at which this folder was most recently updated.
Bucket Changes to this property will trigger replacement. string
The name of the bucket that contains the folder.
CreateTime string
The timestamp at which this folder was created.
ForceDestroy bool
If set to true, items within folder if any will be force destroyed.
Metageneration string
The metadata generation of the folder.
Name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


SelfLink string
The URI of the created resource.
UpdateTime string
The timestamp at which this folder was most recently updated.
bucket Changes to this property will trigger replacement. String
The name of the bucket that contains the folder.
createTime String
The timestamp at which this folder was created.
forceDestroy Boolean
If set to true, items within folder if any will be force destroyed.
metageneration String
The metadata generation of the folder.
name Changes to this property will trigger replacement. String
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


selfLink String
The URI of the created resource.
updateTime String
The timestamp at which this folder was most recently updated.
bucket Changes to this property will trigger replacement. string
The name of the bucket that contains the folder.
createTime string
The timestamp at which this folder was created.
forceDestroy boolean
If set to true, items within folder if any will be force destroyed.
metageneration string
The metadata generation of the folder.
name Changes to this property will trigger replacement. string
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


selfLink string
The URI of the created resource.
updateTime string
The timestamp at which this folder was most recently updated.
bucket Changes to this property will trigger replacement. str
The name of the bucket that contains the folder.
create_time str
The timestamp at which this folder was created.
force_destroy bool
If set to true, items within folder if any will be force destroyed.
metageneration str
The metadata generation of the folder.
name Changes to this property will trigger replacement. str
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


self_link str
The URI of the created resource.
update_time str
The timestamp at which this folder was most recently updated.
bucket Changes to this property will trigger replacement. String
The name of the bucket that contains the folder.
createTime String
The timestamp at which this folder was created.
forceDestroy Boolean
If set to true, items within folder if any will be force destroyed.
metageneration String
The metadata generation of the folder.
name Changes to this property will trigger replacement. String
The name of the folder expressed as a path. Must include trailing '/'. For example, example_dir/example_dir2/, example@#/, a-b/d-f/.


selfLink String
The URI of the created resource.
updateTime String
The timestamp at which this folder was most recently updated.

Import

Folder can be imported using any of these accepted formats:

  • {{bucket}}/folders/{{name}}

  • {{bucket}}/{{name}}

When using the pulumi import command, Folder can be imported using one of the formats above. For example:

$ pulumi import gcp:storage/folder:Folder default {{bucket}}/folders/{{name}}
Copy
$ pulumi import gcp:storage/folder:Folder default {{bucket}}/{{name}}
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Google Cloud (GCP) Classic pulumi/pulumi-gcp
License
Apache-2.0
Notes
This Pulumi package is based on the google-beta Terraform Provider.