Create and manage managed folders

This guide describes how to create, list, and delete managed folders .

Before you begin

Before you begin, make sure you have the required Identity and Access Management (IAM) role to create and manage managed folders, and enable uniform bucket-level access.

Get required roles

To get the permissions that you need to create and manage managed folders, ask your administrator to grant you the Storage Folder Admin ( roles/storage.folderAdmin ) IAM role for the bucket.

This predefined role contains the permissions required to create and manage managed folders. To see the exact permissions that are required, expand the Required permissionssection:

Required permissions

  • storage.managedfolders.create
  • storage.managedfolders.delete
  • storage.managedfolders.get
  • storage.managedfolders.list
  • storage.objects.list
    • This permission is only required if you want to validate newly created managed folders by listing them.

You can also get these permissions with other predefined roles or custom roles .

For information about granting roles on buckets, see Use IAM with buckets .

Enable uniform bucket-level access

If you haven't already, enable uniform bucket-level access .

Create a managed folder

Console

When using the Google Cloud console, you create managed folders by converting simulated folders. The following steps describe how to create a simulated folder and convert it to a managed folder.

  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. In the list of buckets, click the name of the bucket you want to create managed folders in.

  3. In the Bucket detailspage, click Create folderto create a new folder. If the folder you want to convert to a managed folder already exists, skip to the step describing how to access the More options menu.

  4. In the Namefield, enter a name for your folder. For naming considerations, see Managed folder names .

  5. Click Create.

    Your newly created folder appears in the Folder browserpane.

  6. In the Folder browserpane, click the More options menu next to the folder you want to convert to a managed folder and click Edit access.

    The Create managed folderdialog appears.

  7. Click Attach managed folder.

    Your folder converts to a managed folder. A Permissions for MANAGED_FOLDER_NAME pane appears that displays the IAM policies on the folder by principal and role. To create new IAM policies, see Set an IAM policy on a managed folder .

Command line

To create a managed folder, run the gcloud storage managed-folders create command :

gcloud storage managed-folders create gs:// BUCKET_NAME 
/ MANAGED_FOLDER_NAME 

Where:

  • BUCKET_NAME is the name of the bucket in which you want to create a managed folder. For example, my-bucket .

  • MANAGED_FOLDER_NAME is the name of the managed folder you want to create. For example, my-managed-folder/ .

To confirm that the managed folder was created, run the gcloud storage managed-folders describe command:

gcloud storage managed-folders describe gs:// BUCKET_NAME 
/ MANAGED_FOLDER_NAME 

Where:

  • BUCKET_NAME is the name of the bucket in which you created a managed folder.

  • MANAGED_FOLDER_NAME is the name of the managed folder you created.

Client libraries

Java

For more information, see the Cloud Storage Java API reference documentation .

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

 import com.google.storage.control.v2.BucketName;
import com.google.storage.control.v2.CreateManagedFolderRequest;
import com.google.storage.control.v2.ManagedFolder;
import com.google.storage.control.v2.StorageControlClient;

public class CreateManagedFolder {
  public static void managedFolderCreate(String bucketName, String managedFolderId)
      throws Exception {

    // Instantiates a client in a try-with-resource to automatically cleanup underlying resources
    try (StorageControlClient storageControlClient = StorageControlClient.create()) {
      CreateManagedFolderRequest request =
          CreateManagedFolderRequest.newBuilder()
              // Set project to "_" to signify global bucket
              .setParent(BucketName.format("_", bucketName))
              .setManagedFolder(ManagedFolder.newBuilder().build())
              .setManagedFolderId(managedFolderId)
              .build();
      String response = storageControlClient.createManagedFolder(request).getName();
      System.out.printf("Performed createManagedFolder request for %s%n", response);
    }
  }
}