Automating GCP projects creation with Terraform

Let’s get it started

gcloud projects create “seed-project “ — set-as-defaultgcloud beta billing projects link ${SEED_PROJECT_ID} — billing-account <billing_account_id>
gcloud iam service-accounts create terraform — display-name “Terraform admin account”gcloud iam service-accounts keys create ~/.config/gcloud/terraform.json — iam-account terraform@${SEED_PROJECT_ID}.iam.gserviceaccount.comgcloud projects add-iam-policy-binding ${SEED_PROJECT_ID} — member serviceAccount:terraform@${SEED_PROJECT_ID}.iam.gserviceaccount.com — role roles/viewergcloud projects add-iam-policy-binding ${SEED_PROJECT_ID} — member serviceAccount:terraform@${SEED_PROJECT_ID}.iam.gserviceaccount.com — role roles/storage.admingcloud projects add-iam-policy-binding ${SEED_PROJECT_ID} — member serviceAccount:terraform@${SEED_PROJECT_ID}.iam.gserviceaccount.com — role roles/editor
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable cloudbilling.googleapis.com
gcloud services enable iam.googleapis.com
gcloud services enable compute.googleapis.com

Terraform Files

provider "google" {  
version = "~> 2.18.1"
}
resource "google_project" "my_project" {
name = "My Project"
project_id = "your-project-id"
org_id = "1234567"
}
terraform init
terraform plan
terraform apply # if you agree with the plan above :)

--

--

--

Brazilian Software Engineer living in London. Java addicted. Clean Code and Software craftsmanship Enthusiast. Cloud. https://www.linkedin.com/in/femrtnz/

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Felipe Martinez

Felipe Martinez

Brazilian Software Engineer living in London. Java addicted. Clean Code and Software craftsmanship Enthusiast. Cloud. https://www.linkedin.com/in/femrtnz/

More from Medium

AWS EKS and Google Cloud Functions

Cloud spanner with Terraform

How to drop multiple tables using shell script in BigQuery.

Using Terraform to manage multiple GCP resources