Skip to main content

AWS KEY PAIR , vpc, Elastic-key, Security-group

 NOTE:

once we make-instance it doesn't provide elastic IP, security group and key pair.

go to docs 

copy key pair code 

go to the main console

type ssh-keygen 
type key name afreen 
enter twice
ls
vim afreen.pub
copy key 
and paste in code 
  



vim key.tf 

provider "aws" {
  region     = "us-east-1"
  access_key = "AKIARUPJBFN6BKVUGQ"
  secret_key = "KfU0tFpao0bDvc+GG63xN99jTMdfVkt1aurid"
}

resource "aws_instance" "web" {
  ami           = "ami-02e136e904f3da870"
  instance_type = "t2.micro"
  key_name      = "afreen"
  vpc_security_group_ids  = [aws_security_group.apple.id]

  tags = {
    Name = "HelloWorld"
  }
}

resource "aws_key_pair" "moon" {
  key_name   = "afreen"
  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCms+0pf8D2EEtdnVA3v+zc/P7ztVP/DrmdKOB1ZRfy2NYQ7faxKTuvVrNdzKvEdyxmnwK3+/+PrYLpygl3AzASnSKUqe3dO8ey6P49aT6gbPNLyDfppURKj9MrVLBGXhIzPJG01NCvZJFWMEkASYkY2u2L6hvbuP2mqgJACBBJufN0UWCH1PkYh+IHLxCDe2uj5AHdf6/nVuLiNgbRKmQEIfDg57Jgx3U5hjBjtUd5JKCSVgz/quVDnmUOVHG1Iel9RhtWxInlVKnP0bJ7P7ZtzpkNWGgITZEJDIJWijOF0DEDV4WAHg1RR0lS2XAzZdjJFNHAPojcnqPxET4N9WH7 root@ip-172-31-44-43.ap-south-1.compute.internal"

}

resource "aws_eip" "elastic" {
  instance = aws_instance.web.id
  vpc      = true
}


resource "aws_default_vpc" "default" {
  tags = {
    Name = "Default VPC"
  }
}

resource "aws_security_group" "apple" {
  name        = "apple"
  description = "Allow TLS inbound traffic"
  vpc_id      = aws_default_vpc.default.id

 
ingress {
    description      = "TLS from VPC"
    from_port        = 443
    to_port          = 443
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]

  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]

  }

  tags = {
    Name = "allow_tls"
  }
}

Comments

Popular posts from this blog

Packer Environment Variable

Note:  1011  export AWS_ACCESS=AKGQ                         do this on console not on editor  1012  export AWS_SECRET=KfVkt1aurid  1013  echo $AWS_ACCESS  1014  AKVUGQ   vim moon.json {     "variables": {       "aws_access_key": "{{env `AWS_ACCESS`}}",       "aws_secret_key": "{{env `AWS_SECRET`}}"     },        "builders": [            {            "type": "amazon-ebs",            "region": "us-east-1",            "access_key": "{{user `aws_access_key`}}",            "secret_key": "{{user `aws_secret_key`}}",            "instance_type": "t2.micro",            "source_ami": "ami-02e136e904f3da870", ...

copying snap from one REGION to another

 while copying snap from one to another we need to change region provider "aws" {   region     = "us-west-1"   access_key = "AGQ"   secret_key = "Kurid" } resource "aws_ebs_snapshot_copy" "example_copy" {   source_snapshot_id = "snap-08bc5c27dad8e82b3"   source_region      = "us-east-1"   tags = {     Name = "HelloWorld_copy_snap"   } }

ONLY & MULTIPLE PARAMTER IN PACKER

if we have to define 3 builders from different services azure, gcp,aws here we can  provisioner will run on all builders  if we want to run on specific builder then we can use only parameter  "only": ["prod-team","test-team"]  {        "builders": [            {            "name": "test-team",            "type": "amazon-ebs",            "access_key": "AUGQ",            "secret_key": "Kaurid",            "region": "us-east-1",            "instance_type": "t2.micro",            "source_ami": "ami-02e136e904f3da870",            "ssh_username": "ec2-user",            "ami_name": "test-team-{{timestamp}}"            },   ...