Skip to content

Commit

Permalink
Se ha modificado la estrucutura
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbarsan01 committed Oct 13, 2019
1 parent e3caf13 commit 21f9f9d
Show file tree
Hide file tree
Showing 112 changed files with 1,903 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ejemplo_modulos_terraform_aws/.gitignore
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 ejemplo_modulos_terraform_aws/ejemplo1/entornos/produccion/ec2.tf
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"

}
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"
}
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 ejemplo_modulos_terraform_aws/ejemplo1/entornos/testing/ec2.tf
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"

}
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Provider
provider "aws" {
region = "us-west-2"
}

14 changes: 14 additions & 0 deletions ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/ec2.tf
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}"
}
}
10 changes: 10 additions & 0 deletions ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/eip.tf
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}"
}
}
7 changes: 7 additions & 0 deletions ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/inputs.tf
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 ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/outputs.tf
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}"
}
29 changes: 29 additions & 0 deletions ejemplo_modulos_terraform_aws/modulos/ec2-with-eip/sg.tf
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
}

}
9 changes: 9 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/.gitignore
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
19 changes: 19 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/data.tf
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
}
10 changes: 10 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/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"
}

}
15 changes: 15 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/instancia.tf
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"
}
}
8 changes: 8 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/keypair-public.tf
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"
}

22 changes: 22 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/output.tf
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}"
}
4 changes: 4 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = "us-west-2"
}

46 changes: 46 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/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"]
}
}

4 changes: 4 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/terraform.tfvars
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"
6 changes: 6 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/user-data.txt
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
4 changes: 4 additions & 0 deletions instanceweb-terrafor-aws-with-datasources/variables.tf
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" {}
9 changes: 9 additions & 0 deletions instancia_web_aws/.gitignore
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
Loading

0 comments on commit 21f9f9d

Please sign in to comment.