O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Terraform infraestructura como código

530 visualizações

Publicada em

Presentación empleada en el primer MeetUp AWS del grupo de usuarios de Valencia.
Infraestructura como código empleando Terraform. Se muestra las principales características de esta tecnología que nos permite ser más ágiles y rápidos desplegando nuestras plataformas en AWS.

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Terraform infraestructura como código

  1. 1. Infraestructura como código Terraform
  2. 2. Victor Adsuar - Arquitecto Cloud victor@victorasuar.com https://victoradsuar.com twitter: @victoradsuar Me presento
  3. 3. Bienvenidos a la gestión de infraestructura como código ¿Qué es Terraform?
  4. 4. Producto Open Source de Hashicorp
  5. 5. - Open Source (Mozilla Public License 2.0) - Sencillo de usar. (HCL) - Compatible con plataformas de virtualización y nube - Planes de ejecución para su versionado - Gráfico dependencias Características de Terraform:
  6. 6. - Linux 32 y 64 bits, and ARM. - Mac Os X, 32 y 64 bits. - FreeBSD 32 y 64 bits. - OpenBSD 32 y 64 bits. - Illumos Distributions 64 bits - Windows 32 y 64 bits. ¿Dónde podemos instalar Terraform?
  7. 7. - Linux 32 y 64 bits, and ARM. - Mac Os X, 32 y 64 bits. - FreeBSD 32 y 64 bits. - OpenBSD 32 y 64 bits. - Illumos Distributions 64 bits - Windows 32 y 64 bits. ¿Dónde podemos instalar Terraform?
  8. 8. Instalación Linux $ wget https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_amd64.zip $ unzip https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_amd64.zip $ sudo mv terraform /usr/local/bin $ chown -R root:root /usr/local/bin/terraform Instalación Windows C:> MKDIR terraform C:> CD terraform https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_windows_amd64.zip Add Path $env:Path += ";C:terraform" Instalación Mac $ brew install terraform
  9. 9. Comprobar instalación $ terraform version Terraform v0.10.0 $ terraform help terraform help Usage: terraform [--version] [--help] <command> [args] Common commands: apply Builds or changes infrastructure console Interactive console for Terraform interpolations destroy Destroy Terraform-managed infrastructure env Workspace management fmt Rewrites config files to canonical format get Download and install modules for the configuration graph Create a visual graph of Terraform resources import Import existing infrastructure into Terraform init Initialize a Terraform working directory output Read an output from a state file plan Generate and show an execution plan providers Prints a tree of the providers used in the configuration push Upload this Terraform module to Atlas to run refresh Update local state file against real resources show Inspect Terraform state or plan taint Manually mark a resource for recreation untaint Manually unmark a resource as tainted validate Validates the Terraform files version Prints the Terraform version workspace Workspace management All other commands: debug Debug output management (experimental) force-unlock Manually unlock the terraform state state Advanced state management
  10. 10. Variables Modules Resources Output state Terraform State
  11. 11. /* This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. */ provider "aws" { region = "eu-west-1" } # This is a single-line comment. resource "aws_instance" "base" { ami = "ami-ebd02392" instance_type = "t2.micro" } Ejemplo de ec2.tf Los parámetros no especificados cogerá los que AWS tenga definidos por defecto.
  12. 12. Crear infraestructura Iniciar Terraform $ terraform init Plan $ terraform plan $ terraform plan -out base-`date +'%s'`.plan Crear $ terraform apply $ terraform apply base-1503252130.plan Comprobar $ terraform show $ terraform state list
  13. 13. /* This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. */ provider "aws" { region = "eu-west-1" } # This is a single-line comment. resource "aws_instance" "base" { ami = "ami-ebd02392" instance_type = "t2.micro" } resource "aws_eip" "base" { instance = "${aws_instance.base.id}" } Las variables, funciones y atributos de recursos se referencian por $ { }
  14. 14. Modificar y Destruir Infraestructura Modificación $terraform apply + Recurso será añadido - Recurso será eliminado -/+ Recurso será eliminado y creado de nuevo ~ Recurso será modificado Destrucción $ terraform destroy
  15. 15. Tipo de variables Strings “variable "region" { description = "The AWS region." default = "us-east-1" }” Maps “variable "ami" { type = "map" default = { us-east-1 = "ami-0d729a60" us-west-1 = "ami-7c4b331c" } description = "The AMIs to use." }” Lists “variable "security_group_ids" { type = "list" description = "List of security group IDs." default = ["sg-4f713c35", "sg-4f713c35", "sg-4f713c35"] }”
  16. 16. Carga de variables Linea de Comando “terraform plan -var 'access_key=12345 -var 'secret_key=12345” Desde un fichero (terraform.tfvars) “access_key = "xyz245" secret_key = "xyz245" ami = { us-east-1 = "ami-0d729a60" us-west-1 = "ami-7c4b331c" }” Variables de Entorno “TF_VAR_comodin” $TF_VAR_aws_code = zxy245 Por defecto “variable "region" { description = "The AWS region." default = "eu-west-1" }”
  17. 17. Módulos Llamada módulo fichero module "vpc" { source = "./modules" name = "WTFVPC" cidr = "10.0.0.0/16" } Llamada módulo internet module "vpc" { source = "github.com/wtf/wtf_vpc . . . } Definición módulo resource "aws_vpc" "vpc_wtf" { cidr_block = "${var.cidr}" enable_dns_hostnames = "${var.enable_dns_hostnames}" enable_dns_support = "${var.enable_dns_support}" tags { Name = "${var.name}" } }
  18. 18. Aprovisionamiento de Stack Infraestructura Imágen User-Data Ansible, Puppet, Chef, etc...
  19. 19. Vamos a desplegar!
  20. 20. Muchas gracias

×