rtm
rtm

Reputation: 194

Can one adjust GCS bucket lifecycle policies via Terraform AFTER bucket creation?

I'm trying to set GCS bucket lifecycle policies via Terraform. As far as I can tell, the google_storage_bucket resource only allows me to CREATE buckets; and not update existing ones. Trying to run a google_storage_bucket on an existing bucket raises a 409.

The other storage-related resources do not seem to affect lifecycle policies.

So is it possible to adjust policies on existing buckets via Terraform, or should I switch to gsutil or something else?

Upvotes: 1

Views: 1894

Answers (3)

Andor
Andor

Reputation: 326

You have to import your bucket to the terraform state before you can change the lifecycle.

  1. Specify your bucket in something like my-bucket.tf
  2. Import your bucket: terraform import google_storage_bucket.my-bucket my-project/my-bucket
  3. If you have specified lifecycle rules then you can just apply it: terraform apply -target=google_storage_bucket.my-bucket

Upvotes: 4

Christopher
Christopher

Reputation: 941

It seems that Terraform does not have a Google Storage resource to update GCS bucket lifecycle enter image description here

You can update it via the UI, gsutil or REST API.

Upvotes: 2

guillermo rojas
guillermo rojas

Reputation: 153

In Terraform once a bucket has been created, its location can't be changed, use the GCP Console to edit, I add the documentation for buckets.

https://cloud.google.com/storage/docs/access-control/using-iam-permissions

Upvotes: -1

Related Questions