Skip to content

Commit

Permalink
Se agrega el proyecto ec2-web-eip-with-keypair-rsa-public-output
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarsan01 committed Oct 15, 2019
1 parent f918b97 commit 52e7e1b
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/eip.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

resource "aws_eip" "web_eip" {
instance = "${aws_instance.web.id}"

tags = {
Name = "${var.project_name}-eip"
}

}

16 changes: 16 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/instancia.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "aws_instance" "web" {

ami = "${var.ami_id}"
instance_type = "${var.instance_type}"
key_name = "${aws_key_pair.keypair.key_name}"
user_data = "${ file("user-data.txt") }"

vpc_security_group_ids = [
"${aws_security_group.allow_ssh_anywhere.id}" ,
"${aws_security_group.allow_http_anywhere.id}"]

tags = {
Name = "${var.project_name}-instance"
}
}

8 changes: 8 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/keypair-public.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Se declara el keypair para la conexión a la instancia.

resource "aws_key_pair" "keypair" {
key_name = "terrafor-test-keypair"

public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyy3ZmliPL87q47i9/Gjp1QXYt6NaeumfZOG5N0yKm7vmLM1rfR6V5c6vGX16kpf6bk7DgD6BY4yoMitJuMI3caLtG9ETH1RtLxpr9hsq8GtmcVihBVc6mMScC+e0eSC0544ZT/fCnRc9zGoYQV1qyhwoiljStBX4EziAc2k1POHVe7hGQZocCeA8nqdy3QJb6R7qcEMwLgyWvCPJV3pHNHP61OTOu0I6jiHII1buhFNcbzCJzWN5CHknF+QtoDIONmlIFvKQVKDLX5IhUX6Q3F+HnosrLpS6laRaKcMqgkqB3C+jdeJpobkVCwZfrVcXp3lSlhaUK2bLGABardtwv gilbarsan@HP-Pavilion-17-Notebook"
}

26 changes: 26 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


output "instance_public_eip"{
value = "${aws_eip.web_eip.public_ip}"
}

output "instance_public_ip"{
value = "${aws_instance.web.public_ip}"
}


output "security_group_id"{
value = "${aws_security_group.allow_ssh_anywhere.id}"
}

output "security_group_name"{
value = "${aws_security_group.allow_ssh_anywhere.name}"
}

output "security_group_description"{
value = "${aws_security_group.allow_ssh_anywhere.description}"
}

output "ssh_connection_eip_public"{
value = "ssh -l ec2-user ${aws_eip.web_eip.public_ip}"
}
3 changes: 3 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "us-west-2"
}
46 changes: 46 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/sg.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Generar security group en VPC por default.
# el valor vpc_id = "vpc-f8ba509c" - Es el ID de la VPC por default.

resource "aws_security_group" "allow_ssh_anywhere" {
name = "${var.project_name}-allow_ssh_anywhere"
description = "Allow all inbound traffic ssh"
vpc_id = "${var.vpc_id}"

ingress {
# TLS (change to whatever ports you need)
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"]
}
}


resource "aws_security_group" "allow_http_anywhere" {
name = "${var.project_name}-allow_http_anywhere"
description = "Allow all inbound traffic http"
vpc_id = "${var.vpc_id}"

ingress {
# TLS (change to whatever ports you need)
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"]
}
}

5 changes: 5 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project_name = "terraform-test01"
vpc_id = "vpc-f8ba509c"
ami_id = "ami-082b5a644766e0e6f"
instance_type = "t2.micro"

7 changes: 7 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/user-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
yum update
yum -y install httpd

echo 'Hola mundo' | sudo tee /var/www/html/index.html
sudo service httpd start

5 changes: 5 additions & 0 deletions ec2-web-eip-with-keypair-rsa-public-output/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "project_name" {}
variable "vpc_id" {}
variable "ami_id" {}
variable "instance_type" {}

0 comments on commit 52e7e1b

Please sign in to comment.