DEV Community

Cover image for Step-by-Step Guide to Setting Up Terraform, AWS CLI, and VS Code
frankfolabi
frankfolabi

Posted on

Step-by-Step Guide to Setting Up Terraform, AWS CLI, and VS Code

You have heard of the benefit of Infrastructure as Code (IaC). You have seen the power, speed, and other beautiful features as well as the benefits of automation in provisioning your resources. You may now wonder, how can I setup my local machine to use this newfound tool and start deploying servers, databases, networking components, storage and the likes. This step-by-step guide would assist you in setting up Terraform, AWS CLI - which is the Command Line Interface to access your Amazon Web Services resource and VS Code - Visual Studio Code, a popular code editor. These tools can be installed on various operating system such as Linux, Mac, and Windows. Let us start with Terraform installation on Windows.

Terraform

  • Go to terraform.io

Address bar to show terraform.io

  • Click on Download Terraform

IDownload Terraform

  • Go to the section for Windows

Window section on Terraform page

  • Click on the Download. Check if your computer is AMD64 or 386

  • A terraform.exe file would be downloaded in a zip file format that you have to unzip.

ZIpped Terraform

  • Go to your downloaded unzipped file

Unzipped Terraform

  • Copy the .exe file to the C drive and place it in a new folder named terraform.
  • Search for the Advanced System Settings.

Advanced System Settings

  • Click on the Environment Variables

Environment Variables

  • In the bottom section named System variables, scroll down to click on Path

Path variable

  • Click on Edit

  • The click on New

  • Type in the path ex., C:\terraform

  • Click on OK

To check your installation, you can open your command line and type terraform version. You should see a version installed on the machine.

AWS CLI

To efficiently use the AWS CLI to communicate with AWS resources, you will need to sign up for an AWS account. You can sign up for a free account with your credit card on aws.amazon.com
After registering the account, you will have access to all resources on the AWS console. Best practice requires that you create an IAM user with administrative permissions that can be used subsequently to create other users.
Here are the steps to create an IAM admin user on the AWS Console.

  • Seach for IAM in the search bar of the console Search result for IAM
  • Click on IAM
  • In the left pane under Access management, click on Users

Users icon under Access Management

  • Click on Create user

Create user

  • Type the user name

user name details

Note: Since we will be using the CLI, we left the box unchecked.

  • Click on next to set permissions. Best practice is to create a group and attach policies to that group. However, since we are dealing with a user, we will click Attach policies directly. Then click on AdministratorAccess

Admin access policy

  • Review the details and click on Create user

Create user button

  • To generate the Access Keys needed for CLI access, click on the newly created terraform-user

Newly created user

  • Click on the Security credentials tab

Security credentials

  • Scroll down to the Access keys section and click on create access key

create access key

  • Select Command Line Interface for your use case

CLI use case

  • Click on the confirmation then click Next

Confirmation

  • You may wish to add tags, thereafter, click on Create access key

create access keys

  • Keep your access key safe. You may choose to download the .csv file then click Done

Next let us install the AWS CLI version 2 on our machine.

aws cli version

  • You can configure the CLI with the Access key credentials we generated. Run the command aws configure and enter the access key, secret access key, region and the default output format

aws configure credentials

VS Code

Now that we have configured our CLI, let us install VS Code.

  • Download Visual Studio Code at https://code.visualstudio.com/download

  • Follow the installer wizard instructions.

  • After installation and launching VS Code, click on Extensions in the left side pane and search for AWS Toolkit

Install AWS Toolkit

  • Click on the Install button under the AWS Toolkit

Install Toolkit

You are now ready to use all these tools in your learning of Terraform. In the next post, we will start deploying infrastructure with Terraform.

Top comments (0)