-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gopidesu
authored and
Gopidesu
committed
Mar 13, 2020
0 parents
commit 0ae42fe
Showing
8 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
172.31.91.248 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
} | ||
|
||
|
||
|
42 changes: 42 additions & 0 deletions
42
terraform-ec2-launch-hhtpd-with-security-group/ec2-with-userdata.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
terraform-ec2-launch-hhtpd-with-security-group/security-group.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|