-
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
1 parent
e3caf13
commit 21f9f9d
Showing
112 changed files
with
1,903 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,9 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log |
11 changes: 11 additions & 0 deletions
11
ejemplo_modulos_terraform_aws/ejemplo1/entornos/produccion/ec2.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,11 @@ | ||
|
||
module "ec2" { | ||
source = "../../../modulos/ec2-with-eip/" | ||
vpc_id = "vpc-f8ba509c" | ||
project_name = "web" | ||
environment = "produccion" | ||
ami = "ami-06f2f779464715dc5" | ||
instance_type = "t2.micro" | ||
key_name = "ec2-amazon01" | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
ejemplo_modulos_terraform_aws/ejemplo1/entornos/produccion/outputs.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,4 @@ | ||
|
||
output "connection_string" { | ||
value = "ssh -l ubuntu ${module.ec2.eip} -i ec2-amazon01.pem" | ||
} |
5 changes: 5 additions & 0 deletions
5
ejemplo_modulos_terraform_aws/ejemplo1/entornos/produccion/provider.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,5 @@ | ||
#Provider | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
ejemplo_modulos_terraform_aws/ejemplo1/entornos/testing/ec2.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,11 @@ | ||
|
||
module "ec2" { | ||
source = "../../../modulos/ec2-with-eip/" | ||
vpc_id = "vpc-f8ba509c" | ||
project_name = "web" | ||
environment = "testing" | ||
ami = "ami-06f2f779464715dc5" | ||
instance_type = "t2.micro" | ||
key_name = "ec2-amazon01" | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
ejemplo_modulos_terraform_aws/ejemplo1/entornos/testing/ouputs.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,4 @@ | ||
|
||
output "connection_string" { | ||
value = "ssh -l ubuntu ${module.ec2.eip} -i ec2-amazon01.pem" | ||
} |
5 changes: 5 additions & 0 deletions
5
ejemplo_modulos_terraform_aws/ejemplo1/entornos/testing/provider.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,5 @@ | ||
#Provider | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
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,14 @@ | ||
|
||
resource "aws_instance" "web" { | ||
ami = "${var.ami}" | ||
instance_type = "${var.instance_type}" | ||
key_name = "${var.key_name}" | ||
|
||
vpc_security_group_ids = [ | ||
"${aws_security_group.sg.id}", | ||
] | ||
|
||
tags = { | ||
Name = "${var.project_name}-${var.environment}" | ||
} | ||
} |
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,10 @@ | ||
|
||
resource "aws_eip" "eip" { | ||
vpc = true | ||
instance = "${aws_instance.web.id}" | ||
|
||
|
||
tags = { | ||
Name = "${var.project_name}-${var.environment}" | ||
} | ||
} |
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,7 @@ | ||
variable "vpc_id" {} | ||
variable "project_name" {} | ||
variable "environment" {} | ||
variable "ami" {} | ||
variable "instance_type" {} | ||
variable "key_name" {} | ||
|
11 changes: 11 additions & 0 deletions
11
ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/outputs.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,11 @@ | ||
|
||
|
||
|
||
output "sg_id" { | ||
value = "${aws_security_group.sg.id}" | ||
} | ||
|
||
|
||
output "eip" { | ||
value = "${aws_eip.eip.public_ip}" | ||
} |
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 @@ | ||
resource "aws_security_group" "sg" { | ||
# Se coloca el name_prefix para que se genere un prefijo con un time stamp | ||
name_prefix = "${var.project_name}-${var.environment}-" | ||
description = "Security Group for ${var.project_name}-${var.environment}" | ||
vpc_id = "${var.vpc_id}" | ||
|
||
ingress { | ||
# TLS (change to whatever ports you need) | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
# Please restrict your ingress to only necessary IPs and ports. | ||
# Opening to 0.0.0.0/0 can lead to security vulnerabilities. | ||
cidr_blocks = ["0.0.0.0/0"] # add a CIDR block here | ||
} | ||
|
||
egress { | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
|
||
# Se crea recurso Security Group y despues se destroye. | ||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
|
||
} |
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,9 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log |
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,19 @@ | ||
data "aws_ami" "ubuntu" { | ||
filter { | ||
name = "state" | ||
values = ["available"] | ||
} | ||
|
||
filter { | ||
name = "name" | ||
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] | ||
} | ||
|
||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
|
||
owners = ["099720109477"] | ||
most_recent = true | ||
} |
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,10 @@ | ||
|
||
|
||
resource "aws_eip" "web_eip" { | ||
instance = "${aws_instance.web.id}" | ||
|
||
tags = { | ||
Name = "${var.project_name}-eip" | ||
} | ||
|
||
} |
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 @@ | ||
resource "aws_instance" "web" { | ||
|
||
ami = "${data.aws_ami.ubuntu.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" | ||
} | ||
} |
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,8 @@ | ||
#Se declara el keypair para la conexion a la instancia. | ||
|
||
resource "aws_key_pair" "keypair" { | ||
key_name = "${var.project_name}-keypair" | ||
|
||
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYfpZnDbr7EuqhGMR4OMtgfzykKw/43IMmp+3rGiTNePthUmavcapqtJbuNsrh8MysdpxWE+ru16zTX4PVxIVrp5mMSaHMp1HNitPuluOrBsRrG9EA9tlANlGVsGJjGzq8Kd3kDa7HvFPDXP3hztGjawD3dVY+UOZmRJc5WXWs1oRl3JggNQwpaQKC6JcCW2a2UUBhQo+lsp3w1/5otA+QQkRQZTXe5RdRcViyMLnN4Fn7O7HZKHwhXtV3Oi0xr3t9BlF6NkH4DlvmcjGI5YzqZxWnfsfpBkugWZc/1exx0Su4nYO2VIg+8wn4hjPKRTQmvgRnvRbBj9QzIv6W8WgJ gilbarsan@gilbarsan-VirtualBox" | ||
} | ||
|
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,22 @@ | ||
|
||
|
||
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}" | ||
} |
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,4 @@ | ||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
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,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"] | ||
} | ||
} | ||
|
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,4 @@ | ||
project_name = "terraform-test01" | ||
vpc_id = "vpc-f8ba509c" | ||
#ami_id = "ami-082b5a644766e0e6f" | ||
instance_type = "t2.micro" |
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,6 @@ | ||
#!/bin/bash | ||
apt-get update | ||
apt-get install -y apache2 | ||
|
||
echo 'Hola mundo' | sudo tee /var/www/html/index.html | ||
systemctl start apache2.service |
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,4 @@ | ||
variable "project_name" {} | ||
variable "vpc_id" {} | ||
#variable "ami_id" {} | ||
variable "instance_type" {} |
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,9 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log |
Oops, something went wrong.