Package com.pulumi.gcp.storage
Class Bucket
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.gcp.storage.Bucket
-
public class Bucket extends com.pulumi.resources.CustomResource
Creates a new bucket in Google cloud storage service (GCS). Once a bucket has been created, its location can't be changed. For more information see [the official documentation](https://cloud.google.com/storage/docs/overview) and [API](https://cloud.google.com/storage/docs/json_api/v1/buckets). **Note**: If the project id is not set on the resource or in the provider block it will be dynamically determined which will require enabling the compute api. ## Example Usage ### Creating A Private Bucket In Standard Storage, In The EU Region. Bucket Configured As Static Website And CORS Configurations ```java 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.BucketCorArgs; import com.pulumi.gcp.storage.inputs.BucketWebsiteArgs; 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 static_site = new Bucket("static-site", BucketArgs.builder() .cors(BucketCorArgs.builder() .maxAgeSeconds(3600) .methods( "GET", "HEAD", "PUT", "POST", "DELETE") .origins("http://image-store.com") .responseHeaders("*") .build()) .forceDestroy(true) .location("EU") .uniformBucketLevelAccess(true) .website(BucketWebsiteArgs.builder() .mainPageSuffix("index.html") .notFoundPage("404.html") .build()) .build()); } } ``` ### Life Cycle Settings For Storage Bucket Objects ```java 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.BucketLifecycleRuleArgs; import com.pulumi.gcp.storage.inputs.BucketLifecycleRuleActionArgs; import com.pulumi.gcp.storage.inputs.BucketLifecycleRuleConditionArgs; 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 auto_expire = new Bucket("auto-expire", BucketArgs.builder() .forceDestroy(true) .lifecycleRules( BucketLifecycleRuleArgs.builder() .action(BucketLifecycleRuleActionArgs.builder() .type("Delete") .build()) .condition(BucketLifecycleRuleConditionArgs.builder() .age(3) .build()) .build(), BucketLifecycleRuleArgs.builder() .action(BucketLifecycleRuleActionArgs.builder() .type("AbortIncompleteMultipartUpload") .build()) .condition(BucketLifecycleRuleConditionArgs.builder() .age(1) .build()) .build()) .location("US") .build()); } } ``` ### Enabling Public Access Prevention ```java 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 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 auto_expire = new Bucket("auto-expire", BucketArgs.builder() .forceDestroy(true) .location("US") .publicAccessPrevention("enforced") .build()); } } ``` ## Import Storage buckets can be imported using the `name` or `project/name`. If the project is not passed to the import command it will be inferred from the provider block or environment variables. If it cannot be inferred it will be queried from the Compute API (this will fail if the API is not enabled). * `{{project_id}}/{{bucket}}` * `{{bucket}}` In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Storage buckets using one of the formats above. For exampletf import { id = "{{project_id}}/{{bucket}}" to = google_storage_bucket.default } ```sh $ pulumi import gcp:storage/bucket:Bucket When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Storage buckets can be imported using one of the formats above. For example ``` ```sh $ pulumi import gcp:storage/bucket:Bucket default {{bucket}} ``` ```sh $ pulumi import gcp:storage/bucket:Bucket default {{project_id}}/{{bucket}} ``` `false` in state. If you've set it to `true` in config, run `pulumi up` to update the value set in state. If you delete this resource before updating the value, objects in the bucket will not be destroyed.
-
-
Constructor Summary
Constructors Constructor Description Bucket(java.lang.String name)
Bucket(java.lang.String name, BucketArgs args)
Bucket(java.lang.String name, BucketArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.pulumi.core.Output<java.util.Optional<BucketAutoclass>>
autoclass()
com.pulumi.core.Output<java.util.Optional<java.util.List<BucketCor>>>
cors()
com.pulumi.core.Output<java.util.Optional<BucketCustomPlacementConfig>>
customPlacementConfig()
com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>
defaultEventBasedHold()
com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>>
effectiveLabels()
com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>
enableObjectRetention()
com.pulumi.core.Output<java.util.Optional<BucketEncryption>>
encryption()
com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>
forceDestroy()
static Bucket
get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, BucketState state, com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>>
labels()
com.pulumi.core.Output<java.util.Optional<java.util.List<BucketLifecycleRule>>>
lifecycleRules()
com.pulumi.core.Output<java.lang.String>
location()
com.pulumi.core.Output<java.util.Optional<BucketLogging>>
logging()
com.pulumi.core.Output<java.lang.String>
name()
com.pulumi.core.Output<java.lang.String>
project()
com.pulumi.core.Output<java.lang.String>
publicAccessPrevention()
com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>>
pulumiLabels()
com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>
requesterPays()
com.pulumi.core.Output<java.util.Optional<BucketRetentionPolicy>>
retentionPolicy()
com.pulumi.core.Output<java.lang.String>
selfLink()
com.pulumi.core.Output<java.util.Optional<java.lang.String>>
storageClass()
com.pulumi.core.Output<java.lang.Boolean>
uniformBucketLevelAccess()
com.pulumi.core.Output<java.lang.String>
url()
com.pulumi.core.Output<BucketVersioning>
versioning()
com.pulumi.core.Output<BucketWebsite>
website()
-
-
-
Constructor Detail
-
Bucket
public Bucket(java.lang.String name)
- Parameters:
name
- The _unique_ name of the resulting resource.
-
Bucket
public Bucket(java.lang.String name, BucketArgs args)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.
-
Bucket
public Bucket(java.lang.String name, BucketArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)
- Parameters:
name
- The _unique_ name of the resulting resource.args
- The arguments to use to populate this resource's properties.options
- A bag of options that control this resource's behavior.
-
-
Method Detail
-
autoclass
public com.pulumi.core.Output<java.util.Optional<BucketAutoclass>> autoclass()
- Returns:
- The bucket's [Autoclass](https://cloud.google.com/storage/docs/autoclass) configuration. Structure is documented below.
-
cors
public com.pulumi.core.Output<java.util.Optional<java.util.List<BucketCor>>> cors()
- Returns:
- The bucket's [Cross-Origin Resource Sharing (CORS)](https://www.w3.org/TR/cors/) configuration. Multiple blocks of this type are permitted. Structure is documented below.
-
customPlacementConfig
public com.pulumi.core.Output<java.util.Optional<BucketCustomPlacementConfig>> customPlacementConfig()
- Returns:
- The bucket's custom location configuration, which specifies the individual regions that comprise a dual-region bucket. If the bucket is designated a single or multi-region, the parameters are empty. Structure is documented below.
-
defaultEventBasedHold
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> defaultEventBasedHold()
- Returns:
- Whether or not to automatically apply an eventBasedHold to new objects added to the bucket.
-
effectiveLabels
public com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>> effectiveLabels()
- Returns:
- All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
-
enableObjectRetention
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> enableObjectRetention()
- Returns:
- Enables [object retention](https://cloud.google.com/storage/docs/object-lock) on a storage bucket.
-
encryption
public com.pulumi.core.Output<java.util.Optional<BucketEncryption>> encryption()
- Returns:
- The bucket's encryption configuration. Structure is documented below.
-
forceDestroy
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> forceDestroy()
- Returns:
- When deleting a bucket, this boolean option will delete all contained objects. If you try to delete a bucket that contains objects, the provider will fail that run.
-
labels
public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>> labels()
- Returns:
- A map of key/value label pairs to assign to the bucket.
-
lifecycleRules
public com.pulumi.core.Output<java.util.Optional<java.util.List<BucketLifecycleRule>>> lifecycleRules()
- Returns:
- The bucket's [Lifecycle Rules](https://cloud.google.com/storage/docs/lifecycle#configuration) configuration. Multiple blocks of this type are permitted. Structure is documented below.
-
location
public com.pulumi.core.Output<java.lang.String> location()
- Returns:
- The [GCS location](https://cloud.google.com/storage/docs/bucket-locations). ***
-
logging
public com.pulumi.core.Output<java.util.Optional<BucketLogging>> logging()
- Returns:
- The bucket's [Access & Storage Logs](https://cloud.google.com/storage/docs/access-logs) configuration. Structure is documented below.
-
name
public com.pulumi.core.Output<java.lang.String> name()
- Returns:
- The name of the bucket.
-
project
public com.pulumi.core.Output<java.lang.String> project()
- Returns:
- The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
-
publicAccessPrevention
public com.pulumi.core.Output<java.lang.String> publicAccessPrevention()
- Returns:
- Prevents public access to a bucket. Acceptable values are "inherited" or "enforced". If "inherited", the bucket uses [public access prevention](https://cloud.google.com/storage/docs/public-access-prevention). only if the bucket is subject to the public access prevention organization policy constraint. Defaults to "inherited".
-
pulumiLabels
public com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>> pulumiLabels()
- Returns:
- The combination of labels configured directly on the resource and default labels configured on the provider.
-
requesterPays
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> requesterPays()
- Returns:
- Enables [Requester Pays](https://cloud.google.com/storage/docs/requester-pays) on a storage bucket.
-
retentionPolicy
public com.pulumi.core.Output<java.util.Optional<BucketRetentionPolicy>> retentionPolicy()
- Returns:
- Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. Structure is documented below.
-
selfLink
public com.pulumi.core.Output<java.lang.String> selfLink()
- Returns:
- The URI of the created resource.
-
storageClass
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> storageClass()
- Returns:
- The [Storage Class](https://cloud.google.com/storage/docs/storage-classes) of the new bucket. Supported values include: `STANDARD`, `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`, `COLDLINE`, `ARCHIVE`.
-
uniformBucketLevelAccess
public com.pulumi.core.Output<java.lang.Boolean> uniformBucketLevelAccess()
- Returns:
- Enables [Uniform bucket-level access](https://cloud.google.com/storage/docs/uniform-bucket-level-access) access to a bucket.
-
url
public com.pulumi.core.Output<java.lang.String> url()
- Returns:
- The base URL of the bucket, in the format `gs://<bucket-name>`.
-
versioning
public com.pulumi.core.Output<BucketVersioning> versioning()
- Returns:
- The bucket's [Versioning](https://cloud.google.com/storage/docs/object-versioning) configuration. Structure is documented below.
-
website
public com.pulumi.core.Output<BucketWebsite> website()
- Returns:
- Configuration if the bucket acts as a website. Structure is documented below.
-
get
public static Bucket get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable BucketState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name
- The _unique_ name of the resulting resource.id
- The _unique_ provider ID of the resource to lookup.state
-options
- Optional settings to control the behavior of the CustomResource.
-
-