This article explains how to set up Terraform from scratch to provision AWS resources. In this tutorial we will set up Terraform with all of the required prerequisites and will spin up an EC2 instance using Terraform.
Before provisioning any resource in AWS using Terraform following steps needs to be completed, we will cover each of these in detail.
terraform
and place
terraform executable
in it.
terraform
folder location to your PATH variable, eg:
Control Panel -> System -> System settings ->
Environment Variables
.
terraform --version
msiexec
command in command prompt with admin privileges to run the MSI
installer.
This will launch the AWS CLI Setup wizard.
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
aws --version
For setting up Credentials first we need to create AWS IAM User along with AWS Access Key ID and AWS Secret Access Key.
aws-tf-user
and select Access key - Programmatic access.
aws configure
and provide required
information from downloaded csv.
aws sts get-caller-identity
mkdir tf-with-gcptutorials
cd tf-with-gcptutorials
main.tf
main.tf
with any text editormain.tf
.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default"
region = "us-east-1"
}
resource "aws_instance" "test_instance" {
ami = "ami-033b95fb8079dc481"
instance_type = "t2.micro"
tags = {
Name = "test instance"
}
}
terraform init
command.
terraform init
terraform fmt
terraform validate
terraform plan
terraform plan
terraform apply
. Type "yes"
in
"Do
you
want to perform these actions"
prompt, in some time you should see EC2 instance created.
terraform apply
Category: AWS