github.com/crossplane/upjet@v1.3.0/pkg/registry/testdata/gcp/r/storage_bucket.html.markdown (about) 1 <!-- 2 SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io> 3 4 SPDX-License-Identifier: Apache-2.0 5 --> 6 7 --- 8 subcategory: "Cloud Storage" 9 layout: "google" 10 page_title: "Google: google_storage_bucket" 11 sidebar_current: "docs-google-storage-bucket-x" 12 description: |- 13 Creates a new bucket in Google Cloud Storage. 14 --- 15 16 # google\_storage\_bucket 17 18 Creates a new bucket in Google cloud storage service (GCS). 19 Once a bucket has been created, its location can't be changed. 20 21 For more information see 22 [the official documentation](https://cloud.google.com/storage/docs/overview) 23 and 24 [API](https://cloud.google.com/storage/docs/json_api/v1/buckets). 25 26 **Note**: If the project id is not set on the resource or in the provider block it will be dynamically 27 determined which will require enabling the compute api. 28 29 30 ## Example Usage - creating a private bucket in standard storage, in the EU region. Bucket configured as static website and CORS configurations 31 32 ```hcl 33 resource "google_storage_bucket" "static-site" { 34 name = "image-store.com" 35 location = "EU" 36 force_destroy = true 37 38 uniform_bucket_level_access = true 39 40 website { 41 main_page_suffix = "index.html" 42 not_found_page = "404.html" 43 } 44 cors { 45 origin = ["http://image-store.com"] 46 method = ["GET", "HEAD", "PUT", "POST", "DELETE"] 47 response_header = ["*"] 48 max_age_seconds = 3600 49 } 50 } 51 ``` 52 53 ## Example Usage - Life cycle settings for storage bucket objects 54 55 ```hcl 56 resource "google_storage_bucket" "auto-expire" { 57 name = "auto-expiring-bucket" 58 location = "US" 59 force_destroy = true 60 61 lifecycle_rule { 62 condition { 63 age = 3 64 } 65 action { 66 type = "Delete" 67 } 68 } 69 } 70 ``` 71 ## Argument Reference 72 73 The following arguments are supported: 74 75 * `name` - (Required) The name of the bucket. 76 77 - - - 78 79 * `force_destroy` - (Optional, Default: false) When deleting a bucket, this 80 boolean option will delete all contained objects. If you try to delete a 81 bucket that contains objects, Terraform will fail that run. 82 83 * `location` - (Required) The [GCS location](https://cloud.google.com/storage/docs/bucket-locations) 84 85 * `project` - (Optional) The ID of the project in which the resource belongs. If it 86 is not provided, the provider project is used. 87 88 * `storage_class` - (Optional, Default: 'STANDARD') 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`. 89 90 * `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](#nested_lifecycle_rule). 91 92 * `versioning` - (Optional) The bucket's [Versioning](https://cloud.google.com/storage/docs/object-versioning) configuration. Structure is [documented below](#nested_versioning). 93 94 * `website` - (Optional) Configuration if the bucket acts as a website. Structure is [documented below](#nested_website). 95 96 * `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](#nested_cors). 97 98 * `default_event_based_hold` - (Optional) Whether or not to automatically apply an eventBasedHold to new objects added to the bucket. 99 100 * `retention_policy` - (Optional) Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. Structure is [documented below](#nested_retention_policy). 101 102 * `labels` - (Optional) A map of key/value label pairs to assign to the bucket. 103 104 * `logging` - (Optional) The bucket's [Access & Storage Logs](https://cloud.google.com/storage/docs/access-logs) configuration. Structure is [documented below](#nested_logging). 105 106 * `encryption` - (Optional) The bucket's encryption configuration. Structure is [documented below](#nested_encryption). 107 108 * `requester_pays` - (Optional, Default: false) Enables [Requester Pays](https://cloud.google.com/storage/docs/requester-pays) on a storage bucket. 109 110 * `uniform_bucket_level_access` - (Optional, Default: false) Enables [Uniform bucket-level access](https://cloud.google.com/storage/docs/uniform-bucket-level-access) access to a bucket. 111 112 <a name="nested_lifecycle_rule"></a>The `lifecycle_rule` block supports: 113 114 * `action` - (Required) The Lifecycle Rule's action configuration. A single block of this type is supported. Structure is [documented below](#nested_action). 115 116 * `condition` - (Required) The Lifecycle Rule's condition configuration. A single block of this type is supported. Structure is [documented below](#nested_condition). 117 118 <a name="nested_action"></a>The `action` block supports: 119 120 * `type` - The type of the action of this Lifecycle Rule. Supported values include: `Delete` and `SetStorageClass`. 121 122 * `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: `STANDARD`, `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`, `COLDLINE`, `ARCHIVE`. 123 124 <a name="nested_condition"></a>The `condition` block supports the following elements, and requires at least one to be defined. If you specify multiple conditions in a rule, an object has to match all of the conditions for the action to be taken: 125 126 * `age` - (Optional) Minimum age of an object in days to satisfy this condition. 127 128 * `created_before` - (Optional) A date in the RFC 3339 format YYYY-MM-DD. This condition is satisfied when an object is created before midnight of the specified date in UTC. 129 130 * `with_state` - (Optional) Match to live and/or archived objects. Unversioned buckets have only live objects. Supported values include: `"LIVE"`, `"ARCHIVED"`, `"ANY"`. 131 132 * `matches_storage_class` - (Optional) [Storage Class](https://cloud.google.com/storage/docs/storage-classes) of objects to satisfy this condition. Supported values include: `STANDARD`, `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`, `COLDLINE`, `ARCHIVE`, `DURABLE_REDUCED_AVAILABILITY`. 133 134 * `num_newer_versions` - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition. 135 136 * `custom_time_before` - (Optional) A date in the RFC 3339 format YYYY-MM-DD. This condition is satisfied when the customTime metadata for the object is set to an earlier date than the date used in this lifecycle condition. 137 138 * `days_since_custom_time` - (Optional) Days since the date set in the `customTime` metadata for the object. This condition is satisfied when the current date and time is at least the specified number of days after the `customTime`. 139 140 * `days_since_noncurrent_time` - (Optional) Relevant only for versioned objects. Number of days elapsed since the noncurrent timestamp of an object. 141 142 * `noncurrent_time_before` - (Optional) Relevant only for versioned objects. The date in RFC 3339 (e.g. `2017-06-13`) when the object became nonconcurrent. 143 144 <a name="nested_versioning"></a>The `versioning` block supports: 145 146 * `enabled` - (Required) While set to `true`, versioning is fully enabled for this bucket. 147 148 <a name="nested_website"></a>The `website` block supports the following elements, and requires at least one to be defined: 149 150 * `main_page_suffix` - (Optional) Behaves as the bucket's directory index where 151 missing objects are treated as potential directories. 152 153 * `not_found_page` - (Optional) The custom object to return when a requested 154 resource is not found. 155 156 <a name="nested_cors"></a>The `cors` block supports: 157 158 * `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". 159 160 * `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". 161 162 * `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. 163 164 * `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. 165 166 <a name="nested_retention_policy"></a>The `retention_policy` block supports: 167 168 * `is_locked` - (Optional) If set to `true`, the bucket will be [locked](https://cloud.google.com/storage/docs/using-bucket-lock#lock-bucket) and permanently restrict edits to the bucket's retention policy. Caution: Locking a bucket is an irreversible action. 169 170 * `retention_period` - (Required) The period of time, in seconds, that objects in the bucket must be retained and cannot be deleted, overwritten, or archived. The value must be less than 2,147,483,647 seconds. 171 172 <a name="nested_logging"></a>The `logging` block supports: 173 174 * `log_bucket` - (Required) The bucket that will receive log objects. 175 176 * `log_object_prefix` - (Optional, Computed) The object prefix for log objects. If it's not provided, 177 by default GCS sets this to this bucket's name. 178 179 <a name="nested_encryption"></a>The `encryption` block supports: 180 181 * `default_kms_key_name`: The `id` of a Cloud KMS key that will be used to encrypt objects inserted into this bucket, if no encryption method is specified. 182 You must pay attention to whether the crypto key is available in the location that this bucket is created in. 183 See [the docs](https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys) for more details. 184 185 -> As per [the docs](https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys) for customer-managed encryption keys, the IAM policy for the 186 specified key must permit the [automatic Google Cloud Storage service account](https://cloud.google.com/storage/docs/projects#service-accounts) for the bucket's 187 project to use the specified key for encryption and decryption operations. 188 Although the service account email address follows a well-known format, the service account is created on-demand and may not necessarily exist for your project 189 until a relevant action has occurred which triggers its creation. 190 You should use the [`google_storage_project_service_account`](/docs/providers/google/d/storage_project_service_account.html) data source to obtain the email 191 address for the service account when configuring IAM policy on the Cloud KMS key. 192 This data source calls an API which creates the account if required, ensuring your Terraform applies cleanly and repeatedly irrespective of the 193 state of the project. 194 You should take care for race conditions when the same Terraform manages IAM policy on the Cloud KMS crypto key. See the data source page for more details. 195 196 ## Attributes Reference 197 198 In addition to the arguments listed above, the following computed attributes are 199 exported: 200 201 * `self_link` - The URI of the created resource. 202 203 * `url` - The base URL of the bucket, in the format `gs://<bucket-name>`. 204 205 ## Timeouts 206 207 This resource provides the following 208 [Timeouts](/docs/configuration/resources.html#timeouts) configuration options: 209 210 - `create` - Default is 4 minutes. 211 - `update` - Default is 4 minutes. 212 - `read` - Default is 4 minutes. 213 214 ## Import 215 216 Storage buckets can be imported using the `name` or `project/name`. If the project is not 217 passed to the import command it will be inferred from the provider block or environment variables. 218 If it cannot be inferred it will be queried from the Compute API (this will fail if the API is 219 not enabled). 220 221 e.g. 222 223 ``` 224 $ terraform import google_storage_bucket.image-store image-store-bucket 225 $ terraform import google_storage_bucket.image-store tf-test-project/image-store-bucket 226 ``` 227 228 ~> **Note:** Terraform will import this resource with `force_destroy` set to 229 `false` in state. If you've set it to `true` in config, run `terraform apply` to 230 update the value set in state. If you delete this resource before updating the 231 value, objects in the bucket will not be destroyed.