Step by Step Guide to Install Terraform In Ubuntu OS AWS EC2 Instance using terraform File
Balaji Bharath Mandava
Lead Engineer DevOps @ Eaton | DevOps, Azure, AWS,CI/CD, Jenkins, Groovy, Python, SRE|1.7k+ Followers| 33k + impressions| Eager to learn new skills daily
3. Install the AWS CLI and then using "aws configure" to integrate the local machine with the AWS using secret key and access key
4. Terraform script to launch amazon EC2 Linux instance and then install the terraform.
provider "aws" {
region = "us-east-1" # Choose your desired region
}
resource "aws_instance" "ubuntu" {
ami = "ami-04b70fa74e45c3917" # This is an example AMI ID; use a valid Ubuntu AMI for your region
instance_type = "t2.micro" # Choose an appropriate instance type
key_name = "AWSwindowsinstance" # Replace with your key pair name
user_data = <<-EOF
#!/bin/bash
# Update the package repository
sudo apt update -y
# Install wget (used for downloading Terraform)
sudo apt install -y wget
# Download Terraform
wget https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip
# Unzip Terraform
unzip terraform_1.0.0_linux_amd64.zip
# Move Terraform binary to /usr/local/bin directory
sudo mv terraform /usr/local/bin/
# Verify Terraform version
terraform -version > terraform_version.txt
EOF
tags = {
Name = "Terraform-ubuntu-Instance"
}
}
5. Execute terraform init and terraform apply to create windows instance and then install terraform
领英推荐
6. To verify the terraform is installed now login into EC2 Instance and then ssh into linux instance and check terraform is installed using below command
Login into the EC2 Instance using the putty.