Skip to content

Commit 52e7e1b

Browse files
committed
Se agrega el proyecto ec2-web-eip-with-keypair-rsa-public-output
1 parent f918b97 commit 52e7e1b

File tree

9 files changed

+126
-0
lines changed

9 files changed

+126
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
resource "aws_eip" "web_eip" {
3+
instance = "${aws_instance.web.id}"
4+
5+
tags = {
6+
Name = "${var.project_name}-eip"
7+
}
8+
9+
}
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource "aws_instance" "web" {
2+
3+
ami = "${var.ami_id}"
4+
instance_type = "${var.instance_type}"
5+
key_name = "${aws_key_pair.keypair.key_name}"
6+
user_data = "${ file("user-data.txt") }"
7+
8+
vpc_security_group_ids = [
9+
"${aws_security_group.allow_ssh_anywhere.id}" ,
10+
"${aws_security_group.allow_http_anywhere.id}"]
11+
12+
tags = {
13+
Name = "${var.project_name}-instance"
14+
}
15+
}
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Se declara el keypair para la conexión a la instancia.
2+
3+
resource "aws_key_pair" "keypair" {
4+
key_name = "terrafor-test-keypair"
5+
6+
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyy3ZmliPL87q47i9/Gjp1QXYt6NaeumfZOG5N0yKm7vmLM1rfR6V5c6vGX16kpf6bk7DgD6BY4yoMitJuMI3caLtG9ETH1RtLxpr9hsq8GtmcVihBVc6mMScC+e0eSC0544ZT/fCnRc9zGoYQV1qyhwoiljStBX4EziAc2k1POHVe7hGQZocCeA8nqdy3QJb6R7qcEMwLgyWvCPJV3pHNHP61OTOu0I6jiHII1buhFNcbzCJzWN5CHknF+QtoDIONmlIFvKQVKDLX5IhUX6Q3F+HnosrLpS6laRaKcMqgkqB3C+jdeJpobkVCwZfrVcXp3lSlhaUK2bLGABardtwv gilbarsan@HP-Pavilion-17-Notebook"
7+
}
8+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
output "instance_public_eip"{
4+
value = "${aws_eip.web_eip.public_ip}"
5+
}
6+
7+
output "instance_public_ip"{
8+
value = "${aws_instance.web.public_ip}"
9+
}
10+
11+
12+
output "security_group_id"{
13+
value = "${aws_security_group.allow_ssh_anywhere.id}"
14+
}
15+
16+
output "security_group_name"{
17+
value = "${aws_security_group.allow_ssh_anywhere.name}"
18+
}
19+
20+
output "security_group_description"{
21+
value = "${aws_security_group.allow_ssh_anywhere.description}"
22+
}
23+
24+
output "ssh_connection_eip_public"{
25+
value = "ssh -l ec2-user ${aws_eip.web_eip.public_ip}"
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#Generar security group en VPC por default.
2+
# el valor vpc_id = "vpc-f8ba509c" - Es el ID de la VPC por default.
3+
4+
resource "aws_security_group" "allow_ssh_anywhere" {
5+
name = "${var.project_name}-allow_ssh_anywhere"
6+
description = "Allow all inbound traffic ssh"
7+
vpc_id = "${var.vpc_id}"
8+
9+
ingress {
10+
# TLS (change to whatever ports you need)
11+
from_port = 22
12+
to_port = 22
13+
protocol = "tcp"
14+
cidr_blocks = [ "0.0.0.0/0" ]
15+
}
16+
17+
egress {
18+
from_port = 0
19+
to_port = 0
20+
protocol = "-1"
21+
cidr_blocks = ["0.0.0.0/0"]
22+
}
23+
}
24+
25+
26+
resource "aws_security_group" "allow_http_anywhere" {
27+
name = "${var.project_name}-allow_http_anywhere"
28+
description = "Allow all inbound traffic http"
29+
vpc_id = "${var.vpc_id}"
30+
31+
ingress {
32+
# TLS (change to whatever ports you need)
33+
from_port = 80
34+
to_port = 80
35+
protocol = "tcp"
36+
cidr_blocks = [ "0.0.0.0/0" ]
37+
}
38+
39+
egress {
40+
from_port = 0
41+
to_port = 0
42+
protocol = "-1"
43+
cidr_blocks = ["0.0.0.0/0"]
44+
}
45+
}
46+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project_name = "terraform-test01"
2+
vpc_id = "vpc-f8ba509c"
3+
ami_id = "ami-082b5a644766e0e6f"
4+
instance_type = "t2.micro"
5+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
yum update
3+
yum -y install httpd
4+
5+
echo 'Hola mundo' | sudo tee /var/www/html/index.html
6+
sudo service httpd start
7+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "project_name" {}
2+
variable "vpc_id" {}
3+
variable "ami_id" {}
4+
variable "instance_type" {}
5+

0 commit comments

Comments
 (0)