Terraform is an open-source infrastructure as code software tool created by HashiCorp.
Throughout this course, you will learn how to use Terraform to automate the deployment and management of your AWS infrastructure.
Before we begin, we’ll need to setup our environment to make development possible and easier. So in this lesson, we’ll talk about:
- Computer requirements to run everything
- AWS account requirements and CLI installation
- Terraform installation process
- Setting up VS Code and recommended extensions
Let’s get started.
Computer Requirements
- A computer running Windows, MacOS, or Linux will be needed.
- 8GB of RAM minimum is recommended.
- Apple Silicon Macs (e.g., M1) and other ARM-based systems will work without issue.
AWS Account
You will be provided with AWS credentials to use throughout this course via Cybr’s Hands-On Labs.
However, everything shown in this course can be done in your own AWS account but be aware that you may incur charges if you use your own account.
Everything we’ll deploy will be low cost, especially if you don’t let it running and destroy after every lesson. But I still recommend setting up billing alerts if you are going to be using your own AWS environment, and I’ll show you how to do that in the next lesson.
If you are going to use your own account, please do not use a production account. Use a sandbox account that is completely separate from any type of production resource or data. Only once you complete the course and are more familiar with Terraform, and have conducted thorough testing, would I recommend applying what you’ve learned in production.
So feel free to use our labs or your own account, it’s entirely up to you! Use whatever you prefer.
Terraform Installation
- We’re going to show you examples of how to install Terraform on popular operating systems, but refer to HashiCorp’s documentation for the latest installation instructions.
Installation: macOS via brew package manager
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
Note: An issue I sometimes see here is if your Xcode is out of date. If you run into issue, try updating it (which will take a while) and then try installing Terraform again
Installation: Windows via winget package manager
winget install -e --id=Hashicorp.Terraform
(Or you can use one of the provided binaries)
Installation: Ubuntu via apt package manager
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Code language: PHP (php)
(They also provide options for other distributions like CentOS, etc…)
AWS CLI
- This course will leverage version 2 of the AWS CLI. If you choose to use version 1, you may need to adjust some commands accordingly. (Check which version you’re running with
aws --version
– version 1 will start with1.
and version 2 will start with2.
) - We’ll provide examples of how to install version 2 of the AWS CLI on popular operating systems, but refer to the AWS CLI documentation for the latest installation instructions.
Installation: macOS via brew package manager
brew install awscli
Installation: Windows via winget package manager
winget install -e --id=Amazon.AWSCLI
Installation: Ubuntu via curl
- As of the time of this writing, the
awscli
package available withapt
is outdated. It installs version 1 of the AWS CLI instead of version 2. - It is recommended to use the following method instead as found in the AWS documentation.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Code language: JavaScript (javascript)
Validating AWS Access
Note: if you plan on using Cybr’s Hands-On Labs, you can’t complete this step yet. We’ll let you know when it’s time to configure your CLI. If you plan on using your own account, you can go ahead and do this now, just keep in mind you will need to generate access keys for your IAM user or use Identity Center users. If you’re not sure how to do this, let us know and we can help.
aws configure
AWS Access Key ID [None]: <accessKeyId>
AWS Secret Access Key [None]: <secretAccessKeyId>
Default region name [None]: us-east-1
Default output format [None]: json
Code language: CSS (css)
Then run the command aws sts get-caller-identity
to validate that the AWS CLI is configured correctly. You should see output similar to the following:
{
"UserId": "AIDA7DH3JSLDF0NDND35RB",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/<userName>"
}
Code language: JSON / JSON with Comments (json)
AWS CLI credentials are stored locally in this file: ~/.aws/credentials
.
Visual Studio Code
- Visual Studio Code is a popular code editor and is recommended to use for this course, but you can use any code editor you prefer.
- We’ll provide examples of how to install Visual Studio Code on popular operating systems, but refer to the Visual Studio Code website for the latest installation instructions.
Installation: macOS via brew package manager
brew install visual-studio-code
Installation: Windows via winget package manager
winget install -e --id Microsoft.VisualStudioCode
Code language: CSS (css)
Installation: Ubuntu via apt package manager
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" |sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null
rm -f packages.microsoft.gpg
Code language: PHP (php)
sudo apt install apt-transport-https
sudo apt update
sudo apt install code # or code-insiders
Code language: PHP (php)
Visual Studio Code Extensions
- The HashiCorp Terraform extension for Visual Studio Code is a recommended quality of life improvement.
It provides syntax highlighting, IntelliSense, code navigation, code formatting, module explorer and more.
Conclusion
That’s it! Now that you’ve got everything installed, you’re ready to get started.
If you encountered any issues installing any of the above, let us know in the comments below so we can help you troubleshoot.
Responses