Skip to content

Commit

Permalink
adding terraform scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gopidesu authored and Gopidesu committed Mar 13, 2020
0 parents commit 0ae42fe
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 0 deletions.
51 changes: 51 additions & 0 deletions terraform-ec2-creation-storing-ip-local/ec2-creation.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
provider "aws"{

profile="aws-devops"
region="us-east-1"

}

resource "aws_instance" "democreation" {

ami=var.AMIS[var.REGION]

instance_type=var.instance_type

provisioner "local-exec" {

command="echo ${aws_instance.democreation.private_ip} >> private_ip.txt"
}

#key_name=var.ec2_key_name

/*
vpc_security_group_ids=[aws_security_group.my-sg.id]
user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Launched via terraform Terraform</h1>" | sudo tee /var/www/html/index.html
EOF
*/


}














1 change: 1 addition & 0 deletions terraform-ec2-creation-storing-ip-local/private_ip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
172.31.91.248
35 changes: 35 additions & 0 deletions terraform-ec2-creation-storing-ip-local/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "AMIS" {

type=map(string)

default={

us-east-1="ami-035b3c7efe6d061d5"
}

}

variable "ec2_key_name" {
default="Ec2codedeploy"

}

variable "instance_type" {

default="t2.micro"
}



variable "INSTANCE_USERNAME" {
default="ec2-user"

}

variable "REGION" {

default="us-east-1"

}


29 changes: 29 additions & 0 deletions terraform-ec2-creation/ec2creation.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
provider "aws"{

profile="aws-devops"
region="us-east-1"

}

resource "aws_instance" "example" {

ami="ami-2757f631"
instance_type="t2.micro"

depends_on=[aws_s3_bucket.example]

}
resource "aws_eip" "ip" {
vpc = true
instance = aws_instance.example.id
}

resource "aws_s3_bucket" "example" {

bucket="teraform-getting-started-guide"
acl="private"

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
provider "aws"{

profile="aws-devops"
region="us-east-1"

}

resource "aws_instance" "example" {

ami="ami-035b3c7efe6d061d5"
instance_type="t2.micro"

key_name="Ec2codedeploy"

vpc_security_group_ids=[aws_security_group.my-sg.id]

user_data = <<EOF
#! /bin/bash
sudo yum update -y
sudo yum install -y httpd.x86_64
sudo service httpd start
sudo service httpd enable
echo "<h1>Launched via terraform Terraform</h1>" | sudo tee /var/www/html/index.html
EOF



}














31 changes: 31 additions & 0 deletions terraform-ec2-launch-hhtpd-with-security-group/security-group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

resource "aws_security_group" "my-sg" {
name="allowing ssh"

description="allowing ssh inbound traffic from 22"

ingress{

from_port=22
to_port=22
protocol="tcp"
cidr_blocks=["0.0.0.0/0"]
}

ingress{

from_port=80
to_port=80
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"]
}

}

31 changes: 31 additions & 0 deletions terraform-security-group/security-group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

resource "aws_security_group" "my-sg" {
name="allowing ssh"

description="allowing ssh inbound traffic from 22"

ingress{

from_port=22
to_port=22
protocol="tcp"
cidr_blocks=["0.0.0.0/0"]
}

ingress{

from_port=80
to_port=80
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"]
}

}

15 changes: 15 additions & 0 deletions terraformcmds.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This template is used to create ec2 instance with s3 bucket
#install the awscli
configure the awscli profile useing below comands
#aws configure
then enter the access key and screate key
then enter the region and profile
#change your profile name

use below commands


terraform init

terraform apply

0 comments on commit 0ae42fe

Please sign in to comment.