Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Project Creation

This script will assist with the creation of a GCP Project. Please review all steps that are taken to ensure that when the script is executed you are aware of all actions that will be taken place.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Prerequisites
  4. Usage
  5. Contributing

Getting Started

There are a few steps that need to be taken to ensure that you have the appropriate permissions, configurations, and libraries prior to executing the script.

Requirements:

  1. Download, Install, and Sign into CloudSDK

  2. Create a virtualenv using pip

    • virtualenv is a tool to create isolated Python environments. Be sure to use Python 3.11
  3. Install python dependencies

  4. Verify code and execute

  5. Have the permissions to create projects within GCP

(back to top)

Prerequisites

This is an example of how to sign into Cloud SDK and create a virtualenv.

IAM Roles

Project Creator role is required at the Org or Folder level. The Billing User role is required on the billing account itself.

roles/resourcemanager.projectCreator
roles/billing.user

Using Shared VPC

If you are needing to create a project that needs to have access to a Shared VPC, the account running this script will need to have the following IAM Role here

roles/compute.xpnAdmin

Required APIs

APIs must be enabled on the project you are using to authenticate to when executing this script.

cloudbilling.googleapis.com

Cloud SDK Installation

  1. Download one of the following:

  2. Initialize gcloud

    it is recommended that you already have a project created within GCP which you use to test and use as a playground since this will help with authentication if you are running this script locally

    gcloud init
  3. Create local authentication credentials for your Google Account

    gcloud auth application-default login

    A login screen is displayed. After you log in, your credentials are stored in the local credential file used by ADC. For more information about working with ADC in a local environment, see Local development environment.

Virtualenv Installation

Mac/Linux

pip3 install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-api-python-client

Windows

pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-api-python-client

Populate the ENV file

Within the working directory there is a .env which contains the following that need to be filled out prior to execution.

# Specify if you are creating a new project or not
CREATE_PROJECT=<True/False>
# Attach project to shared VPC
SHARED_VPC_ACCESS=<True/False>
# GCP Folder ID
GCP_FOLDER_ID=<folder-id>
# GCP Project Name not unique
GCP_PROJECT_NAME=<project-name>
# GCP Project ID please leave blank if you do not have this yet! Used if you are not creating a new project
GCP_PROJECT_ID=<project-id>
# GCP Billing ID
GCP_BILLING_ID=<billing-id>
# List of Principals e.g. "user:user@examples.com,roles/storage.admin;group:group@examples.com,roles/viewer"
IAM_PRINCIPALS_AND_ROLES="user:user@example.com,roles/editor;serviceAccount:svc@example.com,roles/appengine.appAdmin;group:group@example.com,roles/viewer"
# List of APIs to enable e.g. "compute.googleapis.com,run.googleapis.com"
ENABLE_API="compute.googleapis.com,run.googleapis.com"
# List of users to be able to access the Shared VPC e.g. "user:user@examples.com,roles/storage.admin;group:group@examples.com,roles/viewer"
SHARED_VPC_USERS="user:user@example.com,roles/editor;serviceAccount:svc@example.com,roles/appengine.appAdmin;group:group@example.com,roles/viewer"
# The Region of the Shared VPC Subnet
SHARED_VPC_REGION=<region>
# The Subnet of the Shared VPC
SHARED_VPC_SUBNET=<subnet-name>

Intall Dependencies

pip install -r requirements.txt

(back to top)

Usage

After all the Prerequities have been completed, execute the script:

python3 create_project.py

(back to top)

Contributing

For now the script will be passed around but it is highly recommended to place it within its own repository.

(back to top)

About

This repository will consist of various actions that you will be able to take using Python

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages