├── buckets3.yaml ├── clase12 ├── clase12.zip └── main.tf ├── clase3 └── Vagrantfile ├── main.tf ├── parcial ├── parcial_t1.yml └── parcial_t2.yml ├── practica-pipelines ├── Jenkinsfile └── README.md ├── prefinal.tf ├── providers.tf └── variables.tf /buckets3.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: s3 test DH 3 | hosts: localhost 4 | connection: local 5 | 6 | tasks: 7 | - name: Creating a new bucket 8 | aws_s3: 9 | bucket: bucketdorio 10 | mode: create 11 | -------------------------------------------------------------------------------- /clase12/clase12.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/repoinfradh/Infra2/556a2dd8c241dc40f09e9a151972432b90d47eca/clase12/clase12.zip -------------------------------------------------------------------------------- /clase12/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-west-2" 3 | } 4 | 5 | data "aws_ami" "amazon-linux-2" { 6 | most_recent = true 7 | owners = ["amazon"] 8 | 9 | filter { 10 | name = "name" 11 | values = ["amzn2-ami-hvm*"] 12 | } 13 | } 14 | 15 | resource "aws_vpc" "vpc" { 16 | cidr_block = "10.0.0.0/16" 17 | instance_tenancy = "default" 18 | 19 | tags = { 20 | Name = "vpc" 21 | } 22 | } 23 | 24 | resource "aws_subnet" "subnet" { 25 | vpc_id = aws_vpc.vpc.id 26 | cidr_block = "10.0.1.0/24" 27 | 28 | tags = { 29 | Name = "subnet" 30 | } 31 | 32 | } 33 | 34 | resource "aws_instance" "frontend" { 35 | ami = data.aws_ami.amazon-linux-2.id 36 | instance_type = "t2.micro" 37 | subnet_id = aws_subnet.subnet.id 38 | 39 | tags = { 40 | Name = "Frontend" 41 | } 42 | } 43 | 44 | resource "aws_instance" "backend" { 45 | ami = data.aws_ami.amazon-linux-2.id 46 | instance_type = "t2.micro" 47 | subnet_id = aws_subnet.subnet.id 48 | 49 | tags = { 50 | Name = "Backend" 51 | } 52 | } 53 | 54 | resource "aws_db_instance" "db" { 55 | allocated_storage = 20 56 | storage_type = "gp2" 57 | engine = "mysql" 58 | engine_version = "8.0.19" 59 | instance_class = "db.t2.micro" 60 | name = "db" 61 | username = "foo" 62 | password = "foobarbaz" 63 | parameter_group_name = "default.mysql8.0" 64 | skip_final_snapshot = true 65 | } -------------------------------------------------------------------------------- /clase3/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | # All Vagrant configuration is done below. The "2" in Vagrant.configure 4 | # configures the configuration version (we support older styles for 5 | # backwards compatibility). Please don't change it unless you know what 6 | # you're doing. 7 | Vagrant.configure("2") do |config| 8 | config.vm.define "server" do |server| 9 | config.vm.box = "ubuntu/focal64" 10 | config.vm.boot_timeout = 900 11 | config.vm.synced_folder ".", "/vagrant", disabled: true 12 | server.vm.provider "virtualbox" do |vb| 13 | # Display the VirtualBox GUI when booting the machine 14 | vb.gui = false 15 | # Customize the amount of memory and cpus on the VM: 16 | vb.memory = 2048 17 | vb.cpus = 2 18 | end 19 | server.vm.hostname = "server" 20 | server.vm.network "public_network" 21 | server.vm.provision "shell", inline: <<-SHELL 22 | sudo apt-get update 23 | sudo apt-get install -y python3 24 | sudo apt-get install -y unzip 25 | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 26 | unzip awscliv2.zip 27 | sudo ./aws/install 28 | sudo apt install software-properties-common -y 29 | sudo add-apt-repository --yes --update ppa:ansible/ansible 30 | sudo apt install ansible -y 31 | sudo apt-get install python3-pip -y 32 | pip3 install boto3 33 | pip3 install boto 34 | curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - 35 | sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com/ $(lsb_release -cs) main" 36 | sudo apt install terraform 37 | sudo apt install net-tools 38 | SHELL 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | # ================================================================== 2 | # Proposito: crear infraestructura AWS 3 | # Autor: DH 4 | # Fecha: 30.07.21 5 | # Version: 1.0 6 | # ================================================================== 7 | 8 | 9 | # ================================================================== 10 | # Creamos nuestro VPC 11 | resource "aws_vpc" "Main" { # usamos el bloque "resource", el "provider element" y una "etiqueta" 12 | cidr_block = var.main_vpcz_cidr # le pasamos por variable el CIDR block que quiero que use 13 | instance_tenancy = "default" 14 | tags = { 15 | Name = "My_VPC" 16 | } 17 | } 18 | # ================================================================== 19 | 20 | # ================================================================== 21 | # Creamos un Internet Gateway "Y" lo asociamos al VPC que se acaba de crear 22 | resource "aws_internet_gateway" "IGW" { # Internet Gateway 23 | vpc_id = aws_vpc.Main.id # vamos a conocer el vpc_id solo cuando el VPC se haya creado 24 | tags = { 25 | Name = "IGW" 26 | } 27 | } 28 | # ================================================================== 29 | 30 | # ================================================================== 31 | # Creamos la subnet publica 32 | resource "aws_subnet" "public_subnets" { # creamos las subnets publicas 33 | vpc_id = aws_vpc.Main.id 34 | cidr_block = var.public_subnets # CIDR block para mis public subnets 35 | tags = { 36 | Name = "Public Subnet" 37 | } 38 | } 39 | # ================================================================== 40 | 41 | # ================================================================== 42 | # Creamos la subnet privada # creamos nuestras private subnets 43 | resource "aws_subnet" "private_subnets" { 44 | vpc_id = aws_vpc.Main.id 45 | cidr_block = var.private_subnets # CIDR block para mis subnets privadas 46 | tags = { 47 | Name = "Private Subnet" 48 | } 49 | } 50 | # ================================================================== 51 | 52 | # ================================================================== 53 | # Tabla de ruteo para la subnet publica 54 | resource "aws_route_table" "Public_RT" { # Creamos nuestro Route Table para la subnet publica 55 | vpc_id = aws_vpc.Main.id 56 | route { 57 | cidr_block = "0.0.0.0/0" # Declaramos el trafico desde la subnet publica llega a Internet desde el Internet Gateway 58 | gateway_id = aws_internet_gateway.IGW.id 59 | } 60 | tags = { 61 | Name = "Tabla de Ruteo Publica" 62 | } 63 | } 64 | # ================================================================== 65 | 66 | # ================================================================== 67 | # Creacion del NAT Gateway usando subnet_id y allocation_id 68 | resource "aws_nat_gateway" "NAT_GW" { 69 | allocation_id = aws_eip.NAT_EIP.id 70 | subnet_id = aws_subnet.public_subnets.id 71 | tags = { 72 | Name = "NAT Gateway + EIP alocadas a la subnet publica" 73 | } 74 | } 75 | # ================================================================== 76 | 77 | # ================================================================== 78 | # Tabla de ruteo para la subnet privada 79 | resource "aws_route_table" "Private_RT" { # Creating RT for Private Subnet 80 | vpc_id = aws_vpc.Main.id 81 | route { 82 | cidr_block = "0.0.0.0/0" # Trafico proviniendo desde la subnet privadas llegando a Internet via NAT Gateway 83 | nat_gateway_id = aws_nat_gateway.NAT_GW.id 84 | } 85 | tags = { 86 | Name = "Tabla de Ruteo Privada" 87 | } 88 | } 89 | # ================================================================== 90 | 91 | # ================================================================== 92 | # Asociacion de tabla de ruteo con la subnet publica 93 | resource "aws_route_table_association" "Public_RT_Association" { 94 | subnet_id = aws_subnet.public_subnets.id 95 | route_table_id = aws_route_table.Public_RT.id 96 | } 97 | # ================================================================== 98 | 99 | # ================================================================== 100 | # Asociacion de tabla de ruteo con la subnet privada 101 | resource "aws_route_table_association" "Private_RT_Association" { 102 | subnet_id = aws_subnet.private_subnets.id 103 | route_table_id = aws_route_table.Private_RT.id 104 | } 105 | # ================================================================== 106 | 107 | # ================================================================== 108 | resource "aws_eip" "NAT_EIP" { 109 | vpc = false 110 | tags = { 111 | Name = "NAT con elastic IP" 112 | } 113 | } 114 | # ================================================================== -------------------------------------------------------------------------------- /parcial/parcial_t1.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | connection: local 4 | tasks: 5 | - name: Crear grupo de seguridad con HTTPS, HTTP y SSH 6 | ec2_group: 7 | name: sg_profe 8 | vpc_id: vpc-7a117c07 9 | description: sg con las reglas 10 | region: us-west-1 11 | rules: 12 | - proto: tcp 13 | ports: 14 | - 443 15 | - 80 16 | - 23 17 | - 8080 18 | cidr_ip: 0.0.0.0/0 19 | rule_desc: Acepto todo el trafico 20 | - name: Creamos nuestro servidor 21 | ec2: 22 | region: us-east-1 23 | instance_type: t2.micro 24 | image: ami-0c2b8ca1dad447f8a 25 | instance_tags: 26 | Name: Instancia_Profe 27 | wait: yes 28 | wait_timeout: 500 29 | group: grupo_creado 30 | volumes: 31 | - device_name: /dev/xvda 32 | volume_type: gp2 33 | volume_size: 8 34 | vpc_subnet_id: subnet-82bceedd 35 | assign_public_ip: no 36 | key_name: millave 37 | register: info 38 | - name: DNS Publico de nuestro servidor 39 | debug: 40 | msg: "La ip publica es {{ info.instances[0].public_ip }} y su DNS es {{ info.instances[0].public_dns_name }}" -------------------------------------------------------------------------------- /parcial/parcial_t2.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | connection: local 4 | tasks: 5 | - name: Crear grupo de seguridad con HTTPS, HTTP y SSH 6 | ec2_group: 7 | name: sg_profe 8 | vpc_id: vpc-7a117c07 9 | description: sg con las reglas 10 | region: us-east-1 11 | rules: 12 | - proto: tcp 13 | ports: 14 | - 443 15 | - 80 16 | - 22 17 | - 8080 18 | cidr_ip: 0.0.0.0/0 19 | rule_desc: Acepto todo el trafico 20 | - name: Creamos nuestro servidor 21 | ec2: 22 | region: us-east-1 23 | instance_type: t2.micro 24 | image: ami-0c2b8ca1dad447f8a 25 | instance_tags: 26 | Name: Instancia_Profe 27 | wait: yes 28 | wait_timeout: 500 29 | group: grupo_creado 30 | volumes: 31 | - device_name: /dev/xvda 32 | volume_type: gp2 33 | volume_size: 8 34 | vpc_subnet_id: subnet-82bceedd 35 | assign_public_ip: no 36 | 37 | register: info 38 | - name: DNS Publico de nuestro servidor 39 | debug: 40 | msg: "La ip publica es {{ info.instances[0].public_ip }} y su DNS es {{ info.instances[0].public_dns_name }}" -------------------------------------------------------------------------------- /practica-pipelines/Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | 4 | tools { 5 | maven "maven-nodo-principal" 6 | } 7 | 8 | 9 | stages { 10 | stage('Build') { 11 | steps { 12 | echo 'Building..' 13 | } 14 | } 15 | stage('Test') { 16 | steps { 17 | echo 'Testing..' 18 | } 19 | } 20 | stage('Deploy') { 21 | steps { 22 | echo 'Deploying....' 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /practica-pipelines/README.md: -------------------------------------------------------------------------------- 1 | # Práctica con pipelines 2 | En esta carpeta vamos a tener el contenido de la práctica de las clases en vivo. Utilizado a partir de la clase 14. 3 | -------------------------------------------------------------------------------- /prefinal.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | } 4 | 5 | data "aws_ami" "amazon-linux-2" { 6 | most_recent = true 7 | owners = ["amazon"] 8 | 9 | filter { 10 | name = "name" 11 | values = ["amzn2-ami-hvm*"] 12 | } 13 | } 14 | 15 | 16 | resource "tls_private_key" "pk" { 17 | algorithm = "RSA" 18 | rsa_bits = 4096 19 | } 20 | 21 | resource "aws_key_pair" "kp" { 22 | key_name = "myKey" 23 | public_key = tls_private_key.pk.public_key_openssh 24 | 25 | } 26 | 27 | 28 | resource "aws_default_vpc" "default" { 29 | tags = { 30 | Name = "Default VPC" 31 | } 32 | } 33 | 34 | data "aws_subnet_ids" "subnets" { 35 | vpc_id = aws_default_vpc.default.id 36 | } 37 | 38 | 39 | resource "aws_security_group" "sg" { 40 | name = "SecurityGroupDH" 41 | description = "Grupo de seguridad" 42 | vpc_id = aws_default_vpc.default.id 43 | 44 | ingress = [ 45 | { 46 | description = "HTTPS" 47 | from_port = 443 48 | to_port = 443 49 | protocol = "tcp" 50 | cidr_blocks = ["0.0.0.0/0"] 51 | ipv6_cidr_blocks = ["::/0"] 52 | prefix_list_ids = [] 53 | security_groups = [] 54 | self = true 55 | }, 56 | { 57 | description = "HTTP" 58 | from_port = 81 59 | to_port = 81 60 | protocol = "tcp" 61 | cidr_blocks = ["190.222.134.35/32"] 62 | ipv6_cidr_blocks = ["::/0"] 63 | prefix_list_ids = [] 64 | security_groups = [] 65 | self = true 66 | }, 67 | { 68 | description = "SSH" 69 | from_port = 22 70 | to_port = 22 71 | protocol = "tcp" 72 | cidr_blocks = ["0.0.0.0/0"] 73 | ipv6_cidr_blocks = ["::/0"] 74 | prefix_list_ids = [] 75 | security_groups = [] 76 | self = true 77 | } 78 | ] 79 | 80 | tags = { 81 | Name = "Security_Group_DH" 82 | } 83 | } 84 | 85 | resource "aws_instance" "frontend" { 86 | ami = data.aws_ami.amazon-linux-2.id 87 | instance_type = "t2.micro" 88 | subnet_id = tolist(data.aws_subnet_ids.subnets.ids)[0] 89 | vpc_security_group_ids = [aws_security_group.sg.id] 90 | key_name = "millave" 91 | tags = { 92 | Name = "Frontend" 93 | } 94 | } 95 | 96 | resource "aws_instance" "backend" { 97 | ami = data.aws_ami.amazon-linux-2.id 98 | instance_type = "t2.medium" 99 | vpc_security_group_ids = "sg-12345534" 100 | subnet_id = tolist(data.aws_subnet_ids.subnets.ids)[0] 101 | key_name = "myKey" 102 | 103 | tags = { 104 | Name = "Backend" 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /providers.tf: -------------------------------------------------------------------------------- 1 | # ================================================================== 2 | # Proposito: declaramos que proveedor cloud queremos usar 3 | # Autor: DH 4 | # Fecha: 30.07.21 5 | # Version: 1.0 6 | # ================================================================== 7 | 8 | # ================================================================== 9 | # Declaramos el Cloud Provider con el que queremos trabajar 10 | 11 | terraform { 12 | # Le decimos que queremos: 13 | # a. la version del binario de terraform mayor o igual a 0.12 14 | required_version = ">=0.12" 15 | required_providers { 16 | aws = { 17 | # Especificamos desde donde queremos descargar el binario: 18 | source = "hashicorp/aws" 19 | # Le decimos que solo permitira: 20 | # b. la version del binario del provider 3.20.0 (con cierta restriccion) 21 | version = "~> 3.20.0" 22 | } 23 | } 24 | } 25 | # ================================================================== 26 | 27 | # ================================================================== 28 | # Declaramos la region donde queremos levantar nuestra infra 29 | 30 | provider "aws" { 31 | region = "us-east-1" 32 | } 33 | # ================================================================== 34 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | # ================================================================== 2 | # Proposito: declaramos todas las variables que vamos a usar 3 | # Autor: DH 4 | # Fecha: 30.07.21 5 | # Version: 1.0 6 | # ================================================================== 7 | 8 | variable "aws_region_id" { 9 | description = "la region" 10 | type = string 11 | default = "us-east-1" 12 | } 13 | variable "main_vpc_cidr" { 14 | description = "Nuestro Security Group" 15 | type = string 16 | default = "10.0.0.0/24" 17 | } 18 | 19 | variable "public_subnets" { 20 | description = "subnet con acceso a internet" 21 | type = string 22 | default = "10.0.0.128/26" 23 | } 24 | 25 | variable "private_subnets" { 26 | description = "subnet sin acceso a internet" 27 | type = string 28 | default = "10.0.0.192/26" 29 | } 30 | # ================================================================== 31 | --------------------------------------------------------------------------------