SlideShare a Scribd company logo
Infrastructure As
Code
by Mario Inga
Quién soy?
• Mario Inga Cahuana

• Software Developer

• Miembro de: DevOps Perú, Docker Lima y Cloud Native
Perú

• Trabajo en BlazingSQL

• Metal m/

• @mario21ic
Agenda
• Infrastructure as code

• Intro a Terraform

• Providers

• Provisioners

• State

• Modules

• Workshop
The problem
• Environment like Prod
• Replication
• Fragile
• Versioning
• Documentation
• Testing
VPC Basica
Infrastructure as Code
• Es una buena práctica donde se describa y maneja
Infraestructura desde código.

• Normalmente se usa un lenguaje de alto nivel.

• También se aplican buenas prácticas de desarrollo de
software como:

• Versionado mediante SCM. 

• Testing.
Infrastructure as Code
• Garantía en homogeneidad

• Tiempo para recuperación

• Productividad

• Asegurarse estándares

• Replicación

• Versionado

• Testing
IaC Tools
Google
Deployment Manager
Terraform
• Execution plans
• Resource graph
• Agnostic
• HCL is the HashiCorp configuration language.
• Development with Go and Open source

https://github.com/hashicorp/terraform
Simple & Powerful
• Write
• Collaborate & share
• Evolve your infrastructure
• Automation friendly
• Plan
• Map resource dependencies
• Separation plan & apply
• One safe workflow
• Create
• Environment parity
• Shareable modules
• Combine multiples providers consistenly
Example EC2
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "web" {
ami = "ami-06f2f779464715dc5"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
Example VPC
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true
}
Providers
• IaaS (e.g. AWS, GCP, Azure, OpenStack)
• PaaS (e.g. Heroku)
• SaaS (e.g. Atlas, DNSimple, Cloudflare).
• https://www.terraform.io/docs/providers/
Provisioners
• Used to execute scripts on a local or remote
machine as part of resource creation or
destruction.
• Can be used to bootstrap a resource, cleanup
before destroy, run configuration management, etc.
• There are: chef, connection, file, local-exec,
remote-exec, null_resource
Provisioners
resource "aws_instance" "web" {
connection {
user = "ubuntu"
type = "ssh"
private_key = "${file("agiles2019.pem")}"
timeout = "2m"
}
provisioner "remote-exec" {
inline = [
"export PATH=$PATH:/usr/bin",
"sudo apt-get update",
"sudo apt-get -y install nginx"
]
}
HCL - Provider
HCL - Resource
Workshop
Workshop
• Instalar Terraform: https://www.terraform.io/downloads.html 

• Configurar aws credenciales: $ aws configure

• Clonar repositorio: https://github.com/mario21ic/
agilesperu2019-iac

• Acceder e iniciar:

$ cd agilesperu2019-iac/ && terraform init

• Aplicar:

$ terraform apply
Stacks
• Plan:
$ terraform plan
$ terraform plan -destroy
• Create / Modify:
$ terraform apply
• Delete:
$ terraform destroy
Targets
• Plan:
• $ terraform plan -target=aws_instance.web
• terraform plan -destroy -target=aws_instance.web
• Destroy
• terraform destroy -target=aws_instance.web
• Show
• $ terraform show -target=aws_instance.web
State
• Files:
• terraform.tfstate
• terraform.tfstate.backup
• State en S3:
terraform {
backend "s3" {
bucket = "mybucket.terraform"
key = "infrav1/terraform.tfstate"
region = "us-west-2"
}
required_version = ">0.9.4"
}
State
• List:
$ terraform state list
• Show:
$ terraform state show aws_instance.web
• Remove
$ terraform state rm aws_instance.web
Variables
• String
• List
• Map
• Boolean
• Integer
variable "region" {
type = "string"
description = "aws region"
default = "us-west-2"
}
variable "mylist" {
type = "list"
default = [80,8080,8089]
}
variable "mymap" {
type = "map"
default = {
nombre = "myvar"
puerto = 80
}
}
Variables input file
• Default: terraform.tfvars
• Alternative: -var-file="dev.tfvars"
region = "eu-west-1"
name = "dev"
# VPC
vpc_cidr = "10.0.0.0/16"
Output
• No more aws cli
• No more tricks
• $ terraform output
• Use:
output "ec2_ip" {
value = “${aws_instance.web.id}"
}
“${module.web.ec2_id}"
Environments
• List:
$ terraform workspace list
• Create
$ terraform workspace new dev
• Select
$ terraform workspace select dev
Filters data
• No more aws cli
• No more tags
• No more tricks
• Use:
data "aws_ami" "ami" {
most_recent = true

owners = ["self"]
filter {
name = "name"
values = ["mynginx"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
"${data.aws_ami.ami.id}"
Module
• DRY, Don't Repeat Yourself https://registry.terraform.io
• Tip: siempre probar que el recetario funcione solo y luego usarlo como
modulo, no olvidar exportar valores como ids mediante output.
• Supports:
• Local file paths
• Github
• Bitbucket
• Http urls
• S3
Module
• Iniciar: $ terraform init
• Download: terraform get -update=true
module "vpc" {
source = "github.com/mario21ic/terraform-aws-vpc"
region = "${var.region}"
name = "${var.name}"
…
}
All files in one
• main.tf -> recetario principal
• data.tf -> filtros para reutilizar recursos
• provider.tf -> configuración de providers
• variables.tf -> declaración de variables
• terraform.tfvars -> valor de variables por default
• outputs.tf -> valores a exportar
• consul.tf -> consul_keys de lectura y escritura
Recomendaciones
• Pensar en modulos reutilisables.
• Separar en recetarios: la red (vpc, subnets, security group, etc) de los
componentes (rds, elasticache, etc) y roles/usuarios (iam).
• Almacenar los valores (ids) de cada recetario en un storage como Consul o
Vault.
• Automatizar solo lo que genere valor.
• Usar un storage para los states como consul o s3.
• La nube no la controlamos al 100%, ejem: la caída de Aws S3
• Es mejor tener un plan a no tener ninguno
• No existe la bala de plata
Material
• https://github.com/mario21ic/infrastructure-as-code-
terraform-aws
• https://www.terraform.io/docs/
• Ebooks:
• The Terraform Book - James Turnbull

https://terraformbook.com
• Terraform up & running - Yevgeniy Brikman

http://shop.oreilly.com/product/0636920061939.do
Preguntas?
twitter: @mario21ic
email: mario21ic@gmail.com

More Related Content

What's hot

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Software, Inc.
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
Alan Parkinson
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
Jeff Hung
 
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build SystemIntroduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
HubSpot Product Team
 
Ansible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps MatchAnsible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps Match
Jeff Geerling
 
EC2 Container Service
EC2 Container ServiceEC2 Container Service
EC2 Container Service
WhiteHedge Technologies Inc.
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
George Miranda
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
ICF CIRCUIT
 
Provisioning iOS CI Server with Ansible
Provisioning iOS CI Server with AnsibleProvisioning iOS CI Server with Ansible
Provisioning iOS CI Server with Ansible
Shashikant Jagtap
 
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and AnsibleService Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Isaac Christoffersen
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerMarc Cluet
 
Intro to CloudStack API
Intro to CloudStack APIIntro to CloudStack API
Intro to CloudStack API
Sebastien Goasguen
 
Terraform in action
Terraform in actionTerraform in action
Terraform in action
Damien Pacaud
 
以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用
Shengyou Fan
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Software, Inc.
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
Anton Babenko
 
Mitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorpMitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorp
Ontico
 
Deploying PHP Applications with Ansible
Deploying PHP Applications with AnsibleDeploying PHP Applications with Ansible
Deploying PHP Applications with Ansible
Orestes Carracedo
 
Hashicorp: Delivering the Tao of DevOps
Hashicorp: Delivering the Tao of DevOpsHashicorp: Delivering the Tao of DevOps
Hashicorp: Delivering the Tao of DevOps
Ramit Surana
 

What's hot (20)

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
 
Baking in the cloud with packer and puppet
Baking in the cloud with packer and puppetBaking in the cloud with packer and puppet
Baking in the cloud with packer and puppet
 
Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
 
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build SystemIntroduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
 
Ansible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps MatchAnsible + Drupal: A Fortuitous DevOps Match
Ansible + Drupal: A Fortuitous DevOps Match
 
EC2 Container Service
EC2 Container ServiceEC2 Container Service
EC2 Container Service
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
 
Provisioning iOS CI Server with Ansible
Provisioning iOS CI Server with AnsibleProvisioning iOS CI Server with Ansible
Provisioning iOS CI Server with Ansible
 
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and AnsibleService Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
 
Rackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & PackerRackspace Hack Night - Vagrant & Packer
Rackspace Hack Night - Vagrant & Packer
 
Intro to CloudStack API
Intro to CloudStack APIIntro to CloudStack API
Intro to CloudStack API
 
Terraform in action
Terraform in actionTerraform in action
Terraform in action
 
以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
Mitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorpMitchell Hashimoto, HashiCorp
Mitchell Hashimoto, HashiCorp
 
Deploying PHP Applications with Ansible
Deploying PHP Applications with AnsibleDeploying PHP Applications with Ansible
Deploying PHP Applications with Ansible
 
Hashicorp: Delivering the Tao of DevOps
Hashicorp: Delivering the Tao of DevOpsHashicorp: Delivering the Tao of DevOps
Hashicorp: Delivering the Tao of DevOps
 

Similar to Agiles Peru 2019 - Infrastructure As Code

Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
Pradeep Bhadani
 
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Miguel Zuniga
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
Alberto Molina Coballes
 
Workshop Infrastructure as Code - Suestra
Workshop Infrastructure as Code - SuestraWorkshop Infrastructure as Code - Suestra
Workshop Infrastructure as Code - Suestra
Mario IC
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker bud
Mandi Walls
 
Achieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefAchieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with Chef
Matt Ray
 
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Docker, Inc.
 
OpenStack Deployments with Chef
OpenStack Deployments with ChefOpenStack Deployments with Chef
OpenStack Deployments with Chef
Matt Ray
 
TechBeats #2
TechBeats #2TechBeats #2
TechBeats #2
applausepoland
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Software, Inc.
 
TIAD : Automating the modern datacenter
TIAD : Automating the modern datacenterTIAD : Automating the modern datacenter
TIAD : Automating the modern datacenter
The Incredible Automation Day
 
Chef for OpenStack - OpenStack Fall 2012 Summit
Chef for OpenStack  - OpenStack Fall 2012 SummitChef for OpenStack  - OpenStack Fall 2012 Summit
Chef for OpenStack - OpenStack Fall 2012 Summit
Matt Ray
 
Chef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdfChef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdf
OpenStack Foundation
 
OSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsOSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy Hawkins
NETWAYS
 
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
Mandi Walls
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
Matt Ray
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
Krishna Srikanth Manda
 
Deploying to Ubuntu on Linode
Deploying to Ubuntu on LinodeDeploying to Ubuntu on Linode
Deploying to Ubuntu on Linode
WO Community
 
OCI Oracle Functions Deployment
OCI Oracle Functions Deployment OCI Oracle Functions Deployment
OCI Oracle Functions Deployment
Toni Epple
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 

Similar to Agiles Peru 2019 - Infrastructure As Code (20)

Terraform: Infrastructure as Code
Terraform: Infrastructure as CodeTerraform: Infrastructure as Code
Terraform: Infrastructure as Code
 
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
 
Automated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. AnsibleAutomated Deployment and Configuration Engines. Ansible
Automated Deployment and Configuration Engines. Ansible
 
Workshop Infrastructure as Code - Suestra
Workshop Infrastructure as Code - SuestraWorkshop Infrastructure as Code - Suestra
Workshop Infrastructure as Code - Suestra
 
habitat at docker bud
habitat at docker budhabitat at docker bud
habitat at docker bud
 
Achieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with ChefAchieving Infrastructure Portability with Chef
Achieving Infrastructure Portability with Chef
 
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
 
OpenStack Deployments with Chef
OpenStack Deployments with ChefOpenStack Deployments with Chef
OpenStack Deployments with Chef
 
TechBeats #2
TechBeats #2TechBeats #2
TechBeats #2
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
TIAD : Automating the modern datacenter
TIAD : Automating the modern datacenterTIAD : Automating the modern datacenter
TIAD : Automating the modern datacenter
 
Chef for OpenStack - OpenStack Fall 2012 Summit
Chef for OpenStack  - OpenStack Fall 2012 SummitChef for OpenStack  - OpenStack Fall 2012 Summit
Chef for OpenStack - OpenStack Fall 2012 Summit
 
Chef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdfChef for OpenStack- Fall 2012.pdf
Chef for OpenStack- Fall 2012.pdf
 
OSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy HawkinsOSDC 2013 | Introduction into Chef by Andy Hawkins
OSDC 2013 | Introduction into Chef by Andy Hawkins
 
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
Habitat talk at CodeMonsters Sofia, Bulgaria Nov 27 2018
 
Australian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStackAustralian OpenStack User Group August 2012: Chef for OpenStack
Australian OpenStack User Group August 2012: Chef for OpenStack
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
Deploying to Ubuntu on Linode
Deploying to Ubuntu on LinodeDeploying to Ubuntu on Linode
Deploying to Ubuntu on Linode
 
OCI Oracle Functions Deployment
OCI Oracle Functions Deployment OCI Oracle Functions Deployment
OCI Oracle Functions Deployment
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 

More from Mario IC

Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
Mario IC
 
Aws Security Latam - Criptografia con KMS
Aws Security Latam - Criptografia con KMSAws Security Latam - Criptografia con KMS
Aws Security Latam - Criptografia con KMS
Mario IC
 
Aws Community Day Guatemala Criptografia con AWS KMS
Aws Community Day Guatemala Criptografia con AWS KMSAws Community Day Guatemala Criptografia con AWS KMS
Aws Community Day Guatemala Criptografia con AWS KMS
Mario IC
 
Testing Ansible Playbook con Molecule + TestInfra
Testing Ansible Playbook con Molecule + TestInfraTesting Ansible Playbook con Molecule + TestInfra
Testing Ansible Playbook con Molecule + TestInfra
Mario IC
 
Automatización de tareas con Ansible
Automatización de tareas con AnsibleAutomatización de tareas con Ansible
Automatización de tareas con Ansible
Mario IC
 
Earthly, Dockerfile con esteroides
Earthly, Dockerfile con esteroidesEarthly, Dockerfile con esteroides
Earthly, Dockerfile con esteroides
Mario IC
 
Infraestructura como Codigo para Developers
Infraestructura como Codigo para DevelopersInfraestructura como Codigo para Developers
Infraestructura como Codigo para Developers
Mario IC
 
Terraspace, the definitive terraform framework
Terraspace, the definitive terraform frameworkTerraspace, the definitive terraform framework
Terraspace, the definitive terraform framework
Mario IC
 
Manejo de packages en Kubernetes con Helm
Manejo de packages en Kubernetes con HelmManejo de packages en Kubernetes con Helm
Manejo de packages en Kubernetes con Helm
Mario IC
 
Cloud native Computing Perú Octubre
Cloud native Computing Perú OctubreCloud native Computing Perú Octubre
Cloud native Computing Perú Octubre
Mario IC
 
Docker Compose to Production with Docker Swarm
Docker Compose to Production with Docker SwarmDocker Compose to Production with Docker Swarm
Docker Compose to Production with Docker Swarm
Mario IC
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
Mario IC
 
Docker Lima meetup - 22 de junio
Docker Lima meetup - 22 de junioDocker Lima meetup - 22 de junio
Docker Lima meetup - 22 de junio
Mario IC
 
Docker Compose para el Docker Lima Meetup Mayo
Docker Compose para el Docker Lima Meetup MayoDocker Compose para el Docker Lima Meetup Mayo
Docker Compose para el Docker Lima Meetup Mayo
Mario IC
 
Testing en BDD con Python y Behave
Testing en BDD con Python y BehaveTesting en BDD con Python y Behave
Testing en BDD con Python y Behave
Mario IC
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
Mario IC
 
Docker Birthday Peru #dockerbday
Docker Birthday Peru #dockerbdayDocker Birthday Peru #dockerbday
Docker Birthday Peru #dockerbday
Mario IC
 
Modelado de API con RAML
Modelado de API con RAMLModelado de API con RAML
Modelado de API con RAML
Mario IC
 
Docker Ecosystem: Part V - Docker Registry
Docker Ecosystem: Part V - Docker RegistryDocker Ecosystem: Part V - Docker Registry
Docker Ecosystem: Part V - Docker Registry
Mario IC
 
Docker Ecosystem: Part IV - Swarm
Docker Ecosystem: Part IV - SwarmDocker Ecosystem: Part IV - Swarm
Docker Ecosystem: Part IV - Swarm
Mario IC
 

More from Mario IC (20)

Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
Dominando AWS KMS desde cifrado básico hasta firma avanzada - aws community d...
 
Aws Security Latam - Criptografia con KMS
Aws Security Latam - Criptografia con KMSAws Security Latam - Criptografia con KMS
Aws Security Latam - Criptografia con KMS
 
Aws Community Day Guatemala Criptografia con AWS KMS
Aws Community Day Guatemala Criptografia con AWS KMSAws Community Day Guatemala Criptografia con AWS KMS
Aws Community Day Guatemala Criptografia con AWS KMS
 
Testing Ansible Playbook con Molecule + TestInfra
Testing Ansible Playbook con Molecule + TestInfraTesting Ansible Playbook con Molecule + TestInfra
Testing Ansible Playbook con Molecule + TestInfra
 
Automatización de tareas con Ansible
Automatización de tareas con AnsibleAutomatización de tareas con Ansible
Automatización de tareas con Ansible
 
Earthly, Dockerfile con esteroides
Earthly, Dockerfile con esteroidesEarthly, Dockerfile con esteroides
Earthly, Dockerfile con esteroides
 
Infraestructura como Codigo para Developers
Infraestructura como Codigo para DevelopersInfraestructura como Codigo para Developers
Infraestructura como Codigo para Developers
 
Terraspace, the definitive terraform framework
Terraspace, the definitive terraform frameworkTerraspace, the definitive terraform framework
Terraspace, the definitive terraform framework
 
Manejo de packages en Kubernetes con Helm
Manejo de packages en Kubernetes con HelmManejo de packages en Kubernetes con Helm
Manejo de packages en Kubernetes con Helm
 
Cloud native Computing Perú Octubre
Cloud native Computing Perú OctubreCloud native Computing Perú Octubre
Cloud native Computing Perú Octubre
 
Docker Compose to Production with Docker Swarm
Docker Compose to Production with Docker SwarmDocker Compose to Production with Docker Swarm
Docker Compose to Production with Docker Swarm
 
GDG Lima - Docker Compose
GDG Lima - Docker ComposeGDG Lima - Docker Compose
GDG Lima - Docker Compose
 
Docker Lima meetup - 22 de junio
Docker Lima meetup - 22 de junioDocker Lima meetup - 22 de junio
Docker Lima meetup - 22 de junio
 
Docker Compose para el Docker Lima Meetup Mayo
Docker Compose para el Docker Lima Meetup MayoDocker Compose para el Docker Lima Meetup Mayo
Docker Compose para el Docker Lima Meetup Mayo
 
Testing en BDD con Python y Behave
Testing en BDD con Python y BehaveTesting en BDD con Python y Behave
Testing en BDD con Python y Behave
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
 
Docker Birthday Peru #dockerbday
Docker Birthday Peru #dockerbdayDocker Birthday Peru #dockerbday
Docker Birthday Peru #dockerbday
 
Modelado de API con RAML
Modelado de API con RAMLModelado de API con RAML
Modelado de API con RAML
 
Docker Ecosystem: Part V - Docker Registry
Docker Ecosystem: Part V - Docker RegistryDocker Ecosystem: Part V - Docker Registry
Docker Ecosystem: Part V - Docker Registry
 
Docker Ecosystem: Part IV - Swarm
Docker Ecosystem: Part IV - SwarmDocker Ecosystem: Part IV - Swarm
Docker Ecosystem: Part IV - Swarm
 

Recently uploaded

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
Nettur Technical Training Foundation
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 

Recently uploaded (20)

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdfThe Role of Electrical and Electronics Engineers in IOT Technology.pdf
The Role of Electrical and Electronics Engineers in IOT Technology.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 

Agiles Peru 2019 - Infrastructure As Code

  • 2. Quién soy? • Mario Inga Cahuana • Software Developer • Miembro de: DevOps Perú, Docker Lima y Cloud Native Perú • Trabajo en BlazingSQL • Metal m/ • @mario21ic
  • 3. Agenda • Infrastructure as code • Intro a Terraform • Providers • Provisioners • State • Modules • Workshop
  • 4. The problem • Environment like Prod • Replication • Fragile • Versioning • Documentation • Testing
  • 6. Infrastructure as Code • Es una buena práctica donde se describa y maneja Infraestructura desde código. • Normalmente se usa un lenguaje de alto nivel. • También se aplican buenas prácticas de desarrollo de software como: • Versionado mediante SCM. • Testing.
  • 7. Infrastructure as Code • Garantía en homogeneidad • Tiempo para recuperación • Productividad • Asegurarse estándares • Replicación • Versionado • Testing
  • 9. Terraform • Execution plans • Resource graph • Agnostic • HCL is the HashiCorp configuration language. • Development with Go and Open source
 https://github.com/hashicorp/terraform
  • 10. Simple & Powerful • Write • Collaborate & share • Evolve your infrastructure • Automation friendly • Plan • Map resource dependencies • Separation plan & apply • One safe workflow • Create • Environment parity • Shareable modules • Combine multiples providers consistenly
  • 11. Example EC2 provider "aws" { region = "us-west-2" } resource "aws_instance" "web" { ami = "ami-06f2f779464715dc5" instance_type = "t2.micro" tags = { Name = "HelloWorld" } }
  • 12. Example VPC provider "aws" { region = "us-west-2" } resource "aws_vpc" "vpc" { cidr_block = "10.0.0.0/16" instance_tenancy = "default" enable_dns_support = true enable_dns_hostnames = true }
  • 13. Providers • IaaS (e.g. AWS, GCP, Azure, OpenStack) • PaaS (e.g. Heroku) • SaaS (e.g. Atlas, DNSimple, Cloudflare). • https://www.terraform.io/docs/providers/
  • 14. Provisioners • Used to execute scripts on a local or remote machine as part of resource creation or destruction. • Can be used to bootstrap a resource, cleanup before destroy, run configuration management, etc. • There are: chef, connection, file, local-exec, remote-exec, null_resource
  • 15. Provisioners resource "aws_instance" "web" { connection { user = "ubuntu" type = "ssh" private_key = "${file("agiles2019.pem")}" timeout = "2m" } provisioner "remote-exec" { inline = [ "export PATH=$PATH:/usr/bin", "sudo apt-get update", "sudo apt-get -y install nginx" ] }
  • 18.
  • 20. Workshop • Instalar Terraform: https://www.terraform.io/downloads.html • Configurar aws credenciales: $ aws configure • Clonar repositorio: https://github.com/mario21ic/ agilesperu2019-iac • Acceder e iniciar:
 $ cd agilesperu2019-iac/ && terraform init • Aplicar:
 $ terraform apply
  • 21. Stacks • Plan: $ terraform plan $ terraform plan -destroy • Create / Modify: $ terraform apply • Delete: $ terraform destroy
  • 22. Targets • Plan: • $ terraform plan -target=aws_instance.web • terraform plan -destroy -target=aws_instance.web • Destroy • terraform destroy -target=aws_instance.web • Show • $ terraform show -target=aws_instance.web
  • 23. State • Files: • terraform.tfstate • terraform.tfstate.backup • State en S3: terraform { backend "s3" { bucket = "mybucket.terraform" key = "infrav1/terraform.tfstate" region = "us-west-2" } required_version = ">0.9.4" }
  • 24. State • List: $ terraform state list • Show: $ terraform state show aws_instance.web • Remove $ terraform state rm aws_instance.web
  • 25. Variables • String • List • Map • Boolean • Integer variable "region" { type = "string" description = "aws region" default = "us-west-2" } variable "mylist" { type = "list" default = [80,8080,8089] } variable "mymap" { type = "map" default = { nombre = "myvar" puerto = 80 } }
  • 26. Variables input file • Default: terraform.tfvars • Alternative: -var-file="dev.tfvars" region = "eu-west-1" name = "dev" # VPC vpc_cidr = "10.0.0.0/16"
  • 27. Output • No more aws cli • No more tricks • $ terraform output • Use: output "ec2_ip" { value = “${aws_instance.web.id}" } “${module.web.ec2_id}"
  • 28. Environments • List: $ terraform workspace list • Create $ terraform workspace new dev • Select $ terraform workspace select dev
  • 29. Filters data • No more aws cli • No more tags • No more tricks • Use: data "aws_ami" "ami" { most_recent = true
 owners = ["self"] filter { name = "name" values = ["mynginx"] } filter { name = "virtualization-type" values = ["hvm"] } } "${data.aws_ami.ami.id}"
  • 30. Module • DRY, Don't Repeat Yourself https://registry.terraform.io • Tip: siempre probar que el recetario funcione solo y luego usarlo como modulo, no olvidar exportar valores como ids mediante output. • Supports: • Local file paths • Github • Bitbucket • Http urls • S3
  • 31. Module • Iniciar: $ terraform init • Download: terraform get -update=true module "vpc" { source = "github.com/mario21ic/terraform-aws-vpc" region = "${var.region}" name = "${var.name}" … }
  • 32. All files in one • main.tf -> recetario principal • data.tf -> filtros para reutilizar recursos • provider.tf -> configuración de providers • variables.tf -> declaración de variables • terraform.tfvars -> valor de variables por default • outputs.tf -> valores a exportar • consul.tf -> consul_keys de lectura y escritura
  • 33. Recomendaciones • Pensar en modulos reutilisables. • Separar en recetarios: la red (vpc, subnets, security group, etc) de los componentes (rds, elasticache, etc) y roles/usuarios (iam). • Almacenar los valores (ids) de cada recetario en un storage como Consul o Vault. • Automatizar solo lo que genere valor. • Usar un storage para los states como consul o s3. • La nube no la controlamos al 100%, ejem: la caída de Aws S3 • Es mejor tener un plan a no tener ninguno • No existe la bala de plata
  • 34. Material • https://github.com/mario21ic/infrastructure-as-code- terraform-aws • https://www.terraform.io/docs/ • Ebooks: • The Terraform Book - James Turnbull
 https://terraformbook.com • Terraform up & running - Yevgeniy Brikman
 http://shop.oreilly.com/product/0636920061939.do