Create a Bucket to store Terraform state

This sample creates a Bucket with Object Versioning enabled in the US multi-region to store Terraform state.

Code sample

Terraform

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands . For more information, see the Terraform provider reference documentation .

  resource 
  
 "random_id" 
  
 "bucket_prefix" 
  
 { 
  
 byte_length 
  
 = 
  
 8 
 } 
 resource 
  
 "google_storage_bucket" 
  
 "default" 
  
 { 
  
 name 
  
 = 
  
 "${random_id.bucket_prefix.hex}-bucket-tfstate" 
  
 force_destroy 
  
 = 
  
 false 
  
 location 
  
 = 
  
 "US" 
  
 storage_class 
  
 = 
  
 "STANDARD" 
  
 versioning 
  
 { 
  
 enabled 
  
 = 
  
 true 
  
 } 
  
 encryption 
  
 { 
  
 default_kms_key_name 
  
 = 
  
 google_kms_crypto_key.terraform_state_bucket.id 
  
 } 
  
 depends_on 
  
 = 
  
 [ 
  
 google_project_iam_member.default 
  
 ] 
 } 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: