Like most jobs today, mine requires me to automate as much of it as possible. One of the things that seemed like an easy goal was to auto the creation of a GCP Project using a tool. We used to use Google Deployment Manager, but soon found it was more of a pain than we wanted to keep up to date.
Project Layout
When creating this I laid out the files in easy to use sections. I also made sure to use the depends_on line a lot so I could ensue that everything was working in the order I wanted
- project.tf - Used to create the basic project
- services.tf - Used to turn on APIs
- iam.tf _ Used to create all IAM policies
- network.tf - Used to create basic networking
- storage.tf - Used to create standard buckets
- serviceaccounts.tf - Used to make any service accounts needed
Project Files
Below I will break down each file and what iot is used for as well as the code inside of it
project.tf
In this file I look for a few variables that help me create the project including the name, what folder it should live in, and a simple label to be applied to it. I also setup google as the provider since I will be using GCP. To make life easy I setup a service account ahead of time that has the ability to create projects and modify IAM throughout my environment. I then took the JSON key from it and I insert the path so the script knows what to use.
Read More