This repository creates architecture which add automatically lifecycle delete of rules of Google Cloud Storage (GCS)'s bucket when it is created.
The architecture is created by Cloud Deployment Manager (CDM).
gcloud services enable compute.googleapis.com \
deploymentmanager.googleapis.com \
cloudbuild.googleapis.com \
cloudresourcemanager.googleapis.com \
cloudfunctions.googleapis.com \
iam.googleapis.com
PROJECT_ID=$(gcloud config get-value project)
PROJECT_NUMBER=$(gcloud projects list --filter="${PROJECT_ID}" --format="value(PROJECT_NUMBER)")
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:${PROJECT_NUMBER}@cloudservices.gserviceaccount.com \
--role roles/editor
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:${PROJECT_NUMBER}@cloudservices.gserviceaccount.com \
--role roles/logging.configWriter
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member serviceAccount:${PROJECT_NUMBER}@cloudservices.gserviceaccount.com \
--role roles/resourcemanager.organizationAdmin
# copy
cp deployment.yml.example deployment.yml
properties:
location: us-east1
bucketLocation: US
lifecycleExpire: 365
ignorePatterns:
- ".*.appspot.com" # Container Registry, App Engine etc
- "gcf-sources*" # Cloud Functions
Location where Cloud Functions are deployed. Default is us-east1
.
GCS bucket location required for Cloud Functions to deploy. Default is US
(Multi regions).
The number of days a GCS object is held. It will be automatically deleted after this number of days.
Default is 365
days.
Bucket name patterns that do not apply lifecycle policies. The default is a pattern for buckets created by Google Container Registry (GCR), Google App Engine (GAE), etc.
DEPLOY_NAME='setting-gcs-bucket'
gcloud deployment-manager deployments create $DEPLOY_NAME --config deployment.yml --preview
gcloud deployment-manager deployments update $DEPLOY_NAME
If you failed, you can retry it.
# must be preview
gcloud deployment-manager deployments update $DEPLOY_NAME --config deployment.yml --preview
gcloud deployment-manager deployments update $DEPLOY_NAME
gsutil rm -r gs://${DEPLOY_NAME}-for-cfn-deploying-${PROJECT_NUMBER}
gcloud deployment-manager deployments delete $DEPLOY_NAME