This repository contains the necessary infrastructure to run the labs in the LFS258 course.
- GCP account
- Terraform Cloud account
- GCP project (manually set as not organization will be created)
Set up a new GCP project for the course, in this case I will be calling it LFS258
.
- Click on the projects list in the upper menu bar
- Click on new project
- Fill in the name as shown in the image below
Create a service account for Terraform, which will have admin permissions in order to be able to provision the various resources we will be using.
- Go to IAM & Admin.
- Click on Service Accounts.
- Click con Create Service Account.
- Fill in the name and description as shown in the image below.
Set up the permissions, give it permission to only those APIs that will be needed, in this case:
- Compute Engine Administrator: To create VMs, admin VPCs, subnets, etc.
- Service Usage Admin: To enable GCP APIs.
Finally click Done.
Create a new Access Key for the service account.
- Go to IAM & Admin
- Click on Service Accounts
- Click on the three dots on the far right of the service account you created in the last section.
- Click on Create Account
- Choose JSON and click Create.
This script will attempt to enable the Cloud Resource Manager API, but it may need some manual help.
- Go to API & Services.
- Click con Enable APIs and Services.
- Search for Cloud Resource Manager API.
- Enable it.
Once manually enabled, you can import it with the following command.
terraform import google_project_service.cloud_resource_manager_api <project-id>/cloudresourcemanager.googleapis.com
This assumes you have created a Terraform Cloud (TC) account and organization.
Create a workspace as specified in this Terraform documentation.
Configure the json key you generated in the last section:
- Open it with your favorite editor.
- Replace the new line characters for an empty string: You can do this in Visual Studio Code by searching the new line character (Ctrl+Enter) and replace it by nothing (empty string).
- Copy the file content.
- Create the
GOOGLE_CREDENTIALS
variable in you TC workspace as described in this article, mark the Sensitive checkbox.
Configure the SSH public key as variable, generate an SSH key with the following command:
ssh-keygen -C student
Set ./id_rsa
as the destination location, this should pick up your pub key with the default ./id_rsa.pub
file, if you want to change this, modify the gce_ssh_pub_key_file
variable.
You can connect to the machines once they are provisioned with the following command.
ssh -i id_rsa student@<public-up>
Queue a plan in terraform with the resources available in this repository.
Queue a destroy plan inside Terraform Cloud's Settings > Destruction and Deletion, this won't disable the enable APIs for faster provisioning the second time you run this, which will help you save by not having to run everything 24/7 until you complete the course.
- Add sudo configuration.
- Add extra configurations based on course content.