GCP Cloud Storage Event

This guide will help you set up GCP Cloud Storage event notifications using Terraform Infrastructure as Code.

Prerequisites

  • GCP Project with billing enabled

  • gcloud CLI installed

  • Terminal/Command Line access

  • Owner or Editor role in the GCP project


Step 1: Install Required Tools

1.1 Install gcloud CLI

Check if already installed:

gcloud --version

For macOS:

curl https://sdk.cloud.google.com | bash
exec -l $SHELL

For Linux:

curl https://sdk.cloud.google.com | bash
exec -l $SHELL

For Windows: Download from: https://cloud.google.com/sdk/docs/install


1.2 Install Terraform

For macOS:

For Linux:

For Windows: Download from: https://www.terraform.io/downloads

Verify installation:


Step 2: Authenticate with GCP

2.1 Initialize gcloud

This will guide you through:

  • Logging in to your Google account

  • Selecting your GCP project

  • Setting default compute region/zone


2.2 Login to GCP

This will open your browser for authentication.


2.3 Set Application Default Credentials

This allows Terraform to authenticate with GCP.


2.4 Set Your Project

List available projects:

Set the project you want to use:


2.5 Verify Current Project


Step 3: Create Terraform Configuration Files

3.1 Create Project Directory


3.2 Create Main Terraform Configuration

Create a file named main.tf with the following content:


3.3 Create Variables File

Create a file named terraform.tfvars with your values:

Option A: Default Configuration (Recommended)

Option B: Custom Configuration

Replace your-project-id with your actual GCP project ID.


Step 4: Deploy Infrastructure

4.1 Initialize Terraform

Expected output:


4.2 Preview Changes

This shows what will be created. Review carefully.

You should see:

  • 6 APIs to be enabled

  • 1 custom IAM role to be created

  • 1 service account to be created

  • 1 service account key to be generated

  • 1 IAM role binding to be created

  • 2 Secret Manager resources to be created

  • 1 local file to be created


4.3 Apply Configuration

Type yes when prompted.

Deployment takes 2-3 minutes.


4.4 View Outputs

After successful deployment, you'll see outputs like:


Step 5: Retrieve and Use Credentials

5.1 Get Credentials from Local File

The credentials are automatically saved to a local file:


5.2 Get Credentials from Secret Manager

Retrieve from Secret Manager (recommended for production):


5.3 Verify Service Account

Check the service account was created:

You should see:


5.4 Verify Custom Role

Check the custom role:


5.5 Verify Role Binding

Check IAM policy:


Step 6: Verify Deployment

6.1 View All Resources Created

Expected output:


6.2 Verify Service Account

Check the service account was created:

You should see:


6.3 Verify Custom Role

Check the custom role:


6.4 Verify IAM Policy Binding

Check the role assignment:


6.5 Verify Enabled APIs


Step 7: Retrieve Service Account Credentials

7.1 Option 1: From Local File

The credentials are automatically saved to a local file:


7.2 Option 2: From Secret Manager

Retrieve from Secret Manager (recommended for production):


7.3 Option 3: From Terraform Output

View the Terraform output that shows where credentials are stored:

Last Updated: November 2025 Version: 1.0 Author: GCP Event Notification Setup Team

Last updated

Was this helpful?