In this hands-on lab, you’ll create a Git repository for Terraform for your Terraform infrastructure and configure continuous delivery (CD) using GitHub Actions and Terraform Cloud.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Set Up Your Environment
- Set up your development environment by connecting to the Virtual Machine using remote desktop and the credentials provided.
- Within the Virtual Machine, using Microsoft Edge, log in to the Azure Portal using the credentials provided. Then log in to your GitHub account and your Terraform Cloud account.
- Create a GitHub Repository
Create a GitHub repository for your Terraform infrastructure.
- Create a Workspace in Terraform Cloud
- Go to
https://app.terraform.io/
and create a Terraform Cloud workspace. - Create four environment variables to authorize access to Azure, with the following details:
ARM_SUBSCRIPTION_ID
– Use the subscription ID from the Azure portal.ARM_CLIENT_ID
– Use the Client ID from the lab details.ARM_CLIENT_SECRET
– Marked as sensitive, use the client secret from the lab details.ARM_TENANT_ID
– Use the Azure AD Tenant ID from the Azure portal.
- Go to
- Configure Continuous Delivery
- Create a GitHub Actions workflow using the following YAML file.
- Create a GitHub Actions repository secret with the name
TF_API_TOKEN
and use the value of a Terraform Cloud API User Token.
- Configure Branch Protection Rules
Create a branch protection rule to protect the
main
branch by requiring approvals and preventing bypassing of the configured protection rules.- Author the Configuration
- Clone the Git repository to the virtual machine.
- Create a branch for your work.
- Use the terraform file named
main.tf
in theC:Terraform
folder on the workstation. - Add the Terraform Cloud configuration from your Terraform Cloud workspace.
- Import the existing resource group for the hands-on-lab into your state.
- Commit your changes and publish your branch.
- Create and Complete a Pull Request
Create and complete a pull request to push your changes to the main branch.
To complete the pull request without a second reviewer, you will need to Allow bypassing branch protection rules by deselecting Do not allow bypassing the above settings in the branch protection policy.
- Review Results
- Review the results in GitHub Actions.
- Review the results in the Azure portal.