gcp-project-enable-api

command module
v0.0.0-...-989612d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 7 Imported by: 0

README

Script to enable API for GCP projects

What is it about ?

If you are working on Google Cloud Platform, you may want to enable an API for all projects you maintain for a particular reason (security, governance, etc.), this script does it for you.

What does it do ?

The script uses the application default credentials to list all projects that has access to, then it will enable the API you define in the var bloc for each project. The script will skip projects in which the API is already enabled.

How to run the script ?

  1. Provide credentials for Application Default Credentials.
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/sa-json.key"

More information here.
Make sure the service account has at least the following permissions on the organization level:

  • resourcemanager.projects.list
  • serviceusage.services.enable
  1. Define the API you want to enable:
...
var (
    API = "recommender.googleapis.com"
)
...
  1. Initialize the module and install dependencies
go mod init
go mod tidy
  1. Run the script:
go run enable_api_v1.go

Notice : In this script, I tried to skip some projects using the following condition :

if project.Parent != nil && strings.Contains(project.ProjectId,"some-prefix")

project.Parent != nil means make sure to consider only projects within the organization. the other condition is to consider only project ids which starts with "some-prefix".

This is optional, if you want to enable the API for all projects, comment line 45 and 60 before running the script.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL