Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.
Let’s start with an example.
First example: Terraform Cloud with Google Cloud
In this example, we will show how to use Terraform Cloud to generate a small instance of example in Google Cloud.
For this example we will use this GitHub repository (you can fork it)
(Here a link to the original repo https://github.com/alfonsof/terraform-google-cloud-examples . Thanks to Alfonsof for share it on GitHub)
Now we can start!
1.- Sign-up in Terraform and Google Cloud … of course
2.- Create a fork of the GitHub repo
3.- Connect Terraform with GitHub (it’s very easy… just follow the wizard)
4.- Go to Google Cloud and create a new service account (and save the json file in a secure place in your computer, we will use the file in Terraform Cloud)
5.- Assign 2 permissions to the new service account in Google Cloud ( Computer Engine Admin and Service Account user roles)
6.- Now we are ready to go to the Terraform Cloud platform and create a new Workspace (in our Organization). Remember to select the GitHub repo and we will use the relative path /code/01-hello-world . Like in the picture below
7.- We need to configure now the Google Cloud variables in the interface of Terraform Cloud (variables section of the Workspace).
Just add the variables and values of “region” , “zone“, “project” , “service_account_key” (with the Json content of the file extracted from Google Cloud). About the project variable, is the project name in Google Cloud.
8.- We are ready to plan the deployment and the execution!
9.- Once the plan is finished, we are ready to execute and deploy!
10.- There is a version control of the deploys and this is awesome!
11.- As a result, you will see a new “example” micro instance in your Google Cloud project up and running!