Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

'604800' violates constraint 'constraints/storage.softDeletePolicySeconds'

While creating a GCS bucket using python code I am getting below error

cmd = "gcloud auth application-default login >$null 2>&1"
returned_value = subprocess.call(cmd, shell=True)
# Initialize the client
storage_client = storage.Client(project="03114")
# Bucket name and region
bucket_name = "automationbuckettesting-name"
region_name = "us-west1"
bucket = storage_client.create_bucket(bucket_name,location=region_name)
 
 
Error:
'604800' violates constraint 'constraints/storage.softDeletePolicySeconds'
0 1 279
1 REPLY 1

Hi @KunalSapkal,

Welcome to Google Cloud Community!

The reason for the issue is because the soft delete policy constraint (constraints/storage.softDeletePolicySeconds) is enforced by your business. The minimum retention time for soft deletion is specified by this restriction. This restriction is broken by the default value of 7 days (604800 seconds).

Solution:
To resolve the issue:

  1. Identify the minimum retention duration enforced by your organization.
  2. Modify the GCS bucket creation code to comply with this policy by explicitly setting a retention period greater than or equal to the enforced duration.
  3. Update or Insert this code snippet(based on this reference) :
    bucket.retention_period = <minimum_policy_duration>
  4. Validate the constraint using the following command:
    gcloud resource-manager org-policies describe constraints/storage.softDeletePolicySeconds \
      --organization=ORGANIZATION_ID

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.