Step by Step Guide to Install Terraform In Ubuntu OS AWS EC2 Instance using terraform File

Step by Step Guide to Install Terraform In Ubuntu OS AWS EC2 Instance using terraform File



  1. Please make sure you have installed the terraform in the windows local machine.
  2. Use the below command "terraform" to check whether the terraform is installed in the local machine


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.







要查看或添加评论,请登录

Balaji Bharath Mandava的更多文章

社区洞察

其他会员也浏览了