28 June 2023

What came before the beginning

The beginning of the beginning

Siba FaddaDeliberate Alumni

We’ve all been there. We’re starting a new project and we want to do it right. We have our basic building blocks defined in terraform, all that is left to do is run it and our new environment will be spun up! But wait… How do we create that initial project in an automatic & repeatable way? Before we get into all of this, let’s start with a brief description on how we’ve been structuring our projects.

How do we Structure our Work?

We’ve used this GCP structure on multiple projects and it’s worked really well for us as it helps us separate environments and simplify configurations.

We start with a starter GCP project, we tend to call it Basecamp. Basecamp, as the name suggests, is the starting place for our environments. It will contain our code repositories, CloudBuild instance to build and deploy our services, Container Registry to hold docker images and every other building block we would need to build and deploy our services to our environments.

We will have a GCP project per environment to separate concerns. Basecamp will use a terraform repository to create, configure & update each of those projects as work progresses. This ensures that our environments are exact replicas barring required configuration differences.

How do we create our Basecamp GCP project?

In short, we script it!

We wanted to stick to the ethos of Infrastructure as Code but needing a project to create a project is a bit of a chicken and egg situation. Instead, we wrote a bash script to create that first project and then let our tech principles take over our ways of working from there.

It took us a while to put the script together and we wanted to share it with the wider tech community to save you all some time.

We start off by defining the different variables we’d need for our project:

Then we create the project and setup billing

After that, we create the service account needed to run our pipelines and generate creds

Now that most of the basics are in place, we need to enable the GCP services we will be using.


Then we need to assign the project and organisational roles needed to be able to perform the required operations

We’re almost there! We now need to create the repos we will use and the cloudbuild triggers to build and deploy on commits to master. In addition to the artefact registry we will use to keep our docker images

Lastly, configure the buckets to hold the terraform state for each of our environments.

Working in a consultancy means we need to spin up new projects often. This script has been really useful to get us started quickly and effectively. Some of the permissions, roles and other details need to be tailored to the specific project needs but the script has certainly been an excellent place to start. It has made our lives easier and we hope it will make yours easier too.


Here is the whole script: