DMCA.com Protection Status Trending Topics About Devops: mini project Terraform Resources without variables

Monday, 1 November 2021

mini project Terraform Resources without variables

 







  


  provider "aws" {

  region     = "us-east-1"

  access_key = "AKIARUPJBF7JN6BKVGQ"

  secret_key = "KfU0tFpao0b+BODvc+GG6xN99jTMdfVkt1aurid"

}


resource "aws_vpc" "cloud-vpc" {

  cidr_block       = "10.0.0.0/16"

  instance_tenancy = "default"


  tags = {

    Name = "cloud-vpc"

  }

}


#


resource "aws_subnet" "public-subnet" {

  vpc_id     = aws_vpc.cloud-vpc.id

  cidr_block = "10.0.1.0/24"


  tags = {

    Name = "public-subnet"

  }

}





resource "aws_subnet" "private-subnet" {

  vpc_id     = aws_vpc.cloud-vpc.id

  cidr_block = "10.0.2.0/24"


  tags = {

    Name = "private-subnet"

  }

}



resource "aws_security_group" "moon_security" {

  name        = "moon_security"

  description = "Allow TLS inbound traffic"

  vpc_id      = aws_vpc.cloud-vpc.id

  ingress {

      description      = "TLS from VPC"

      from_port        = 22

      to_port          = 22

      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 = "moon_security"

  }

}





resource "aws_internet_gateway" "cloud-igw" {

  vpc_id = aws_vpc.cloud-vpc.id


  tags = {

    Name = "cloud-igw"

  }

}





resource "aws_route_table" "public-rt" {

  vpc_id = aws_vpc.cloud-vpc.id


  route {

      cidr_block = "0.0.0.0/0"

      gateway_id = aws_internet_gateway.cloud-igw.id

    }




  tags = {

    Name = "public-rt"

  }

}







resource "aws_route_table_association" "route-ass" {

  subnet_id      = aws_subnet.public-subnet.id

  route_table_id = aws_route_table.public-rt.id

}






resource "aws_key_pair" "cloud-key" {

  key_name   = "cloud"

  public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu8tss1HsG448fxpXK/m+MXaZLfeyxDrh5q/9kuJqA1d2QEehw99Jdfq3ZNs1NTVrlPH8DBdtk1U2+oG1tejWzviWGZ8ksmXZmv6RIoJYy/UBtz72fA8w9YMYpXBIYRMUtymtzGEAf95GZ2IOfTq2gPo6cGYXzd0isj4Ld9QJrtqS0aTp8XU2mMrhzKdQKBMDoCvpzUX1rH1K+00HKDn2S6iiuWv+8zJLnr1+H0mUFmJCT+udkKchpHIo/OUJwB5XviNsAdHq2kme/dEvrqRhhCgnHWq1afqbfTYnKuwwGmPQXlh97NQCgxOCB4wUTCennb6DlZ6ZZkZPXVI+qxfgZ root@ip-172-31-46-6.ap-south-1.compute.internal"

}



resource "aws_instance" "cloud-instance" {

  ami           = "ami-02e136e904f3da870"

  instance_type = "t2.micro"

  subnet_id     = aws_subnet.public-subnet.id

  vpc_security_group_ids = [aws_security_group.moon_security.id]

  key_name      = "cloud"

  tags = {

    Name = "HelloWorld"

  }

}





resource "aws_instance" "db-instance" {

  ami           = "ami-02e136e904f3da870"

  instance_type = "t2.micro"

  subnet_id     = aws_subnet.private-subnet.id

  vpc_security_group_ids = [aws_security_group.moon_security.id]

  key_name      = "cloud"

  tags = {

    Name = "database"

  }

}







resource "aws_eip" "public-ip" {

  instance = aws_instance.cloud-instance.id

  vpc      = true

}



resource "aws_eip" "cloud-natip" {

  vpc      = true

}






resource "aws_nat_gateway" "cloud-nat" {

  allocation_id = aws_eip.cloud-natip.id

  subnet_id     = aws_subnet.public-subnet.id



}



resource "aws_route_table" "private-rt" {

  vpc_id = aws_vpc.cloud-vpc.id


  route {

      cidr_block = "0.0.0.0/0"

      gateway_id = "aws_nat_gateway.cloud-nat"

    }




  tags = {

    Name = "cloud-nat"

  }

}



resource "aws_route_table_association" "nat-ass" {

  subnet_id      = aws_subnet.private-subnet.id

  route_table_id = aws_route_table.private-rt.id

}


No comments: