AWS, EC2

Deploy AWS EC2 Instance with Terraform

Summary

Automate deployment of Ubuntu EC2 instance in AWS using Terraform.

Prerequisite

  1. VSCode
  2. Chocolatey
  3. Terraform
  4. AWS CLI
  5. Create AWS Keypair with AWS CLI
  6. Create AWS IAM Admin User and Group
  7. Install Putty

Build

mkdir learn-terraform-aws-instance
cd learn-terraform-aws-instance
New-Item -Path . -Name example.tf -ItemType file
code .\example.tf

Copy, save, and close below code into opened example.tf file

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 2.70"
    }
  }
}

provider "aws" {
  profile = "default"
  region  = "us-west-2"
}

resource "aws_instance" "example" {
  ami           = "ami-830c94e3"
  instance_type = "t2.micro"
  key_name = "aws-keypair-test"
}
terraform init
terraform validate
terraform plan

Validate

Connect

Putty

  • Session: Host Name (or IP address)
  • Connection/Data: Auto-login username
  • Connection/SSH/Auth: Private key file for authentication

Source: https://learn.hashicorp.com/tutorials/terraform/aws-build?in=terraform/aws-get-started

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner
Bitnami