Now that we have our variables all set up, let’s deal with the prerequisites before we start running terraform.
Even though the goal is to set up terraform for all infrastructure related tasks, we still need a few things that are specific to Google Cloud to be more precise.
<aside>
💡 I assume you already have terraform installed and have ran tfenv install
and set tfenv use <version>
.
</aside>
Let’s make sure you have all the tools you need install and are registered in GCP.
In your terminal run:
curl <https://sdk.cloud.google.com> | bash
Follow the terminal instructions.
After that is complete (it’ll take a few) you’ll need to restart your shell:
exec -l $SHELL
Now initialize gcloud:
gcloud init
Head over to https://console.cloud.google.com, make sure you have an account, if not create one now.
<aside>
💡 In terminal run gcloud cheat-sheet
to see a roster of go-to gcloud
commands.
</aside>
Next we need to authenticate into our gcloud account by running this command in our terminal:
gcloud auth login
Follow the on screen instructions until you are authenticated.
We’ll need to create a project and a service account with sufficient permissions. Everything in Google Cloud is managed by “projects”. Time to Create a new project. Run the following command:
export PROJECT_ID=doc-drew-$(date +%Y%m%d%H%M%S)
export TF_VAR_project_id=$PROJECT_ID
gcloud projects create $PROJECT_ID