The Bucket name of the GCS must be globally unique. While we are creating the bucket in the UI (Cloud Console), we have the option to verify if the bucket name is already taken. However, if we go the IaC route it’s not possible to check this and that causes the code to be broken in the middle.
The method exists() can determine if the bucket is exist, but it fails if we do not have the storage.buckets.get access, which make sense.
So, as the UI was able to fetch if the name is already taken, are there any way to check the same via google cloud SDK or programmatically?
Hi Sonchoy,
You can either use "Buckets: insert" JSON API and if it returns 409 response status code, it can indicate there is a conflict; or you can alternatively examine the existence of the bucket via using "Buckets: list" JSON API to see if it returns 2xx. You noted IaC, Do you mean IaC in Terraform?
>>Thank you for your feedback Sima.
You noted IaC, Do you mean IaC in Terraform?
>> Yes, I mean Terraform.
>> Do i need to have permission to list/insert into the bucket?
>> As you can see, in UI without having any permission to existing bucket(which is not mine), we can figure out if the bucket name is already taken. So IMO there should be a way to check if the bucket name is taken.
>> please let me know if you have any question/concern/remark about this.
Hi, can i have a response please.