- Published on
Install Terraform for Windows and configure it for AWS
- Authors
- Name
- Srinath Musham
Download the Terraform binary
- Visit the official Terraform Download page
- Select the latest Windows AMD64-bit version and click on Download
- Terraform file will be downloaded as a Zip file
- Unzip the downloaded file to a directory of your choice (e.g., C:\terraform).
- Unzip the downloaded file to a directory of your choice (e.g., C:\terraform).
Add Terraform to your system path:
- Right-click on This PC or My Computer and select Properties.
- Click on Advanced system settings.
- Click on Environment Variables.
- Under System variables, find the Path variable and click Edit.
- Click New and add the path to the Terraform executable (e.g., C:\terraform).
- Click OK on all open windows to save the changes.
Install the AWS CLI
Download the AWS CLI MSI installer for Windows (64-bit):
Visit the AWS CLI website Scroll down and click on "Download the AWS CLI (Windows)" button. Choose the 64-bit installer unless you have a specific reason for needing the 32-bit version.
Run the installer: Follow the on-screen instructions to complete the installation.
Configure the AWS CLI:
Open a command prompt or terminal window.
#To check aws cli version
aws --version
Next step is to configure aws cli with your aws account. To do that you need to have aws access key and secret key. To get that follow the below steps.
#To configure aws cli run command
aws configure
Run the command aws configure
and enter your AWS access key ID, secret access key, default region, and output format when prompted as shown below:
Configure Terraform for AWS
Create a Terraform configuration file named main.tf in a new directory for your Terraform project.
Add the below snippet to the main.tf file for AWS provider.
provider "aws" {
region = "your-aws-region"
}
As for the region, you can use any of the AWS regions. For example, us-east-1, us-west-2, etc. Replace "your-aws-region" with the region of your choice.
Initialize Terraform
Open a command prompt or terminal window and navigate to the directory containing your Terraform configuration files. Run terraform init
. This command downloads and installs any required plugins mentioned in your configuration files such as the AWS provider plugin.
terraform init
You are now able to start writing your Terraform configuration files to create AWS resources.
Apply Terraform configuration
terraform apply
This command creates the required AWS resources specified in your configuration file. Terraform will display a plan of the changes it will make and prompt you to confirm before applying them.
Additional notes
- Version control: It's recommended to use a version control system like Git to track changes in your Terraform configuration files.
- Best practices: Follow Terraform best practices for organizing your configuration files and managing state like using multiple environments, remote state, etc.
- Documentation: Refer to the official Terraform documentation for more details and examples: https://www.terraform.io/docs/