2015-05-21 17:28:27 +00:00
---
layout: "google"
page_title: "Google: google_storage_bucket"
2017-08-07 17:13:55 +00:00
sidebar_current: "docs-google-storage-bucket-x"
2015-05-21 17:28:27 +00:00
description: |-
Creates a new bucket in Google Cloud Storage.
---
# google\_storage\_bucket
2018-03-12 20:59:47 +00:00
Creates a new bucket in Google cloud storage service (GCS).
2017-06-06 23:08:45 +00:00
Once a bucket has been created, its location can't be changed.
[ACLs ](https://cloud.google.com/storage/docs/access-control/lists ) can be applied using the `google_storage_bucket_acl` resource.
2018-03-12 20:59:47 +00:00
For more information see
[the official documentation ](https://cloud.google.com/storage/docs/overview )
and
2017-06-06 23:08:45 +00:00
[API ](https://cloud.google.com/storage/docs/json_api/v1/buckets ).
2015-05-21 17:28:27 +00:00
## Example Usage
2016-03-31 10:37:17 +00:00
Example creating a private bucket in standard storage, in the EU region.
2015-05-21 17:28:27 +00:00
2017-04-17 10:17:54 +00:00
```hcl
2015-05-21 17:28:27 +00:00
resource "google_storage_bucket" "image-store" {
2016-04-10 21:34:15 +00:00
name = "image-store-bucket"
location = "EU"
2015-05-21 17:28:27 +00:00
2016-04-10 21:34:15 +00:00
website {
main_page_suffix = "index.html"
2017-02-18 22:48:50 +00:00
not_found_page = "404.html"
2016-04-10 21:34:15 +00:00
}
}
2015-05-21 17:28:27 +00:00
```
## Argument Reference
2015-09-15 14:54:16 +00:00
The following arguments are supported:
2015-05-21 17:28:27 +00:00
* `name` - (Required) The name of the bucket.
2016-04-10 21:34:15 +00:00
- - -
* `force_destroy` - (Optional, Default: false) When deleting a bucket, this
boolean option will delete all contained objects. If you try to delete a
bucket that contains objects, Terraform will fail that run.
* `location` - (Optional, Default: 'US') The [GCS location ](https://cloud.google.com/storage/docs/bucket-locations )
2018-03-12 20:59:47 +00:00
* `project` - (Optional) The ID of the project in which the resource belongs. If it
2016-04-10 21:34:15 +00:00
is not provided, the provider project is used.
2017-02-17 14:59:25 +00:00
* `storage_class` - (Optional) The [Storage Class ](https://cloud.google.com/storage/docs/storage-classes ) of the new bucket. Supported values include: `MULTI_REGIONAL` , `REGIONAL` , `NEARLINE` , `COLDLINE` .
2016-09-21 19:46:35 +00:00
2017-06-13 10:32:02 +00:00
* `lifecycle_rule` - (Optional) 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.
2017-09-15 15:36:01 +00:00
* `versioning` - (Optional) The bucket's [Versioning ](https://cloud.google.com/storage/docs/object-versioning ) configuration.
2017-05-31 19:44:25 +00:00
* `website` - (Optional) Configuration if the bucket acts as a website. Structure is documented below.
2015-09-15 14:54:16 +00:00
2017-05-31 19:44:25 +00:00
* `cors` - (Optional) 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.
2017-10-30 22:48:26 +00:00
* `labels` - (Optional) A set of key/value label pairs to assign to the bucket.
2018-01-25 19:02:08 +00:00
* `logging` - (Optional) The bucket's [Access & Storage Logs ](https://cloud.google.com/storage/docs/access-logs ) configuration.
2017-06-13 10:32:02 +00:00
The `lifecycle_rule` block supports:
2017-06-20 18:12:30 +00:00
* `action` - (Required) The Lifecycle Rule's action configuration. A single block of this type is supported. Structure is documented below.
2017-06-13 10:32:02 +00:00
2017-06-20 18:12:30 +00:00
* `condition` - (Required) The Lifecycle Rule's condition configuration. A single block of this type is supported. Structure is documented below.
2017-06-13 10:32:02 +00:00
The `action` block supports:
* `type` - The type of the action of this Lifecycle Rule. Supported values include: `Delete` and `SetStorageClass` .
* `storage_class` - (Required if action type is `SetStorageClass` ) The target [Storage Class ](https://cloud.google.com/storage/docs/storage-classes ) of objects affected by this Lifecycle Rule. Supported values include: `MULTI_REGIONAL` , `REGIONAL` , `NEARLINE` , `COLDLINE` .
2017-06-20 18:12:30 +00:00
The `condition` block supports the following elements, and requires at least one to be defined:
2017-06-13 10:32:02 +00:00
* `age` - (Optional) Minimum age of an object in days to satisfy this condition.
* `created_before` - (Optional) Creation date of an object in RFC 3339 (e.g. `2017-06-13` ) to satisfy this condition.
* `is_live` - (Optional) Relevant only for versioned objects. If `true` , this condition matches live objects, archived objects otherwise.
* `matches_storage_class` - (Optional) [Storage Class ](https://cloud.google.com/storage/docs/storage-classes ) of objects to satisfy this condition. Supported values include: `MULTI_REGIONAL` , `REGIONAL` , `NEARLINE` , `COLDLINE` , `STANDARD` , `DURABLE_REDUCED_AVAILABILITY` .
2017-06-20 17:47:58 +00:00
* `num_newer_versions` - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.
2017-06-13 10:32:02 +00:00
2017-09-15 15:36:01 +00:00
The `versioning` block supports:
* `enabled` - (Optional) While set to `true` , versioning is fully enabled for this bucket.
2017-05-31 19:44:25 +00:00
The `website` block supports:
2015-09-15 14:54:16 +00:00
2016-04-10 21:34:15 +00:00
* `main_page_suffix` - (Optional) Behaves as the bucket's directory index where
missing objects are treated as potential directories.
* `not_found_page` - (Optional) The custom object to return when a requested
resource is not found.
2018-03-12 20:59:47 +00:00
2017-05-31 19:44:25 +00:00
The `cors` block supports:
* `origin` - (Optional) The list of [Origins ](https://tools.ietf.org/html/rfc6454 ) eligible to receive CORS response headers. Note: "*" is permitted in the list of origins, and means "any Origin".
2018-03-12 20:59:47 +00:00
2017-05-31 19:44:25 +00:00
* `method` - (Optional) The list of HTTP methods on which to include CORS response headers, (GET, OPTIONS, POST, etc) Note: "*" is permitted in the list of methods, and means "any method".
2018-03-12 20:59:47 +00:00
2017-05-31 19:44:25 +00:00
* `response_header` - (Optional) The list of HTTP headers other than the [simple response headers ](https://www.w3.org/TR/cors/#simple-response-header ) to give permission for the user-agent to share across domains.
2018-03-12 20:59:47 +00:00
2017-05-31 19:44:25 +00:00
* `max_age_seconds` - (Optional) The value, in seconds, to return in the [Access-Control-Max-Age header ](https://www.w3.org/TR/cors/#access-control-max-age-response-header ) used in preflight responses.
2015-09-15 14:54:16 +00:00
2018-01-25 19:02:08 +00:00
The `logging` block supports:
* `log_bucket` - (Required) The bucket that will receive log objects.
* `log_object_prefix` - (Optional, Computed) The object prefix for log objects. If it's not provided,
by default GCS sets this to the log_bucket's name.
2015-09-15 14:54:16 +00:00
## Attributes Reference
2016-04-10 21:34:15 +00:00
In addition to the arguments listed above, the following computed attributes are
exported:
2015-09-15 14:54:16 +00:00
* `self_link` - The URI of the created resource.
2017-05-11 12:30:06 +00:00
* `url` - The base URL of the bucket, in the format `gs://<bucket-name>` .
2017-06-27 14:07:47 +00:00
## Import
Storage buckets can be imported using the `name` , e.g.
```
$ terraform import google_storage_bucket.image-store image-store-bucket
```