SlideShare a Scribd company logo
Infrastructure as Code
with
2022.11.11
Dr. Pedro J. Molina
@pmolinam
Agenda
▪ Infrastructure as Code
▪ Immutable Infrastructure
▪ Cloud Providers and AWS
▪ Terraform
▪ Installation & Software Prerequisites
▪ Resources & Dependencies
▪ Execution Plans
▪ Industrial examples
▪ Best practices
▪ Exercises on AWS + Terraform
Get the material
1. Go to: https://github.com/metadevpro/terraform-aws-training
2. Clone the code examples:
git clone git@github.com:metadevpro/terraform-aws-training.git
3. Get credentials for an AWS account
Infrastructure as Code
Engineering Practice to define Infrastructure as code and configuration.
Main Properties:
▪ Repeatable
▪ Can be Versioned (with standard source code tools like git or hg)
▪ Robust
▪ Can be Automated
Immutable Infrastructure
Traditional Approach: PatchingServers
▪ Few items
▪ Named as pets
▪ Manual patching
▪ State unknown over time
▪ Improved by Ansible or Chef for automation
New Approachon scale: Immutable Infrastructure
▪ No patching. Managed as bacteria
▪ Destroy and recreate
▪ Well know-state
▪ Apply all security patches for better safety
Cloud Providers
Main Players
Amazon Web Services
Microsoft Azure
Google Cloud
Amazon Web Services
The first provider: inventors of the cloud (EC2, S3)
Leading innovationon cloud: AWS Lambda,Fargate, etc.
Very complete offeringof services.
Many Data-Centersaround the world.
Price competitive. Leaders and growingyear by year.
Terraform
https://www.terraform.io
Leading tool for manage Infrastructure as Code.
▪ Open Source
▪ Created by Hashi Corporation https://www.hashicorp.com
▪ Custom language to define infrastructure: HCL
Installation & Prereqs
Download & Install:
▪ Terraform from: https://www.terraform.io/downloads.html
▪ Copy local & include it in PATH
▪ AWS-CLI: https://aws.amazon.com/en/cli
▪ Visual Studio Code (editor) https://code.visualstudio.com
▪ Install Extension for Terraform
▪ Bash Shell (git shell, Cmder, or Conemu in Windows)
▪ PuTTY (ssh client for Windows) https://www.putty.org
Installation Cross-check
$ terraform -version
Terraform v0.14.7
$ aws --version
aws-cli/1.16.193 Python/3.6.0 Windows/10 botocore/1.12.183
Hashi Configuration Language (HCL)
Terraform uses *.tf files.
Simple Configuration DSL to describeResources and Desired State.
Similar to JSON syntax, but rich in expressiveness.
Samples:
resource "aws_instance" "web" {
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
}
resource "heroku_app" "app1" {
name = "my-cool-app"
region = "us"
config_vars = {
FOOBAR = "baz"
}
buildpacks = [
"heroku/go", "heroku/node"
]
}
Terraform: Resources
A Resource represent aconcrete (vendor-specific) Cloud Service we can
manipulate.
Resources has a well-knowtype with properties we must configure.
Resources are exposed and managed byProviders.
Examples:
aws-instance Represents a machine in AWS EC2 Service.
azurerm_virtual_machine Represents a virtual machine in Azure.
google_compute_instance Represents a virtual machine in Google Cloud.
Terraform: Providers
A Provider is a driver implementing the communication and automation
for an specific Cloud Provider.
Each provider expose more or less Resource types dependingon the offeringof
the CloudVendor, and the supportof the current Provider version.
Examples: Google,Github or Digital Ocean
See list of providers here: https://registry.terraform.io/browse/providers
Terraform: Configure Provider
provider.tf
# Configure the AWS Provider
provider "aws" {
region = "eu-west-3" # Paris
}
$ terraform init
Terraform: Input Variables
variables.tf
variable "author" {
description = "Operator’s name. Used as prefix."
type = string
default = "jessica"
}
$ terraform apply -var author=alice
Types:
▪ string
▪ number
▪ bool
▪ list
▪ map
▪ null
Terraform: Variables Interpolation
Variables can beinterpolated
Name = "${var.author}_machine1"
https://www.terraform.io/docs/configuration/expressions.html
https://www.terraform.io/docs/configuration/functions.html
Terraform: Output Variables
output.tf
output "instance_public_ip" {
value = aws_instance.machine01.public_ip
}
Sample one
Exercise 01
Create afirst Virtual Machine
▪ Setup credentials access to AWS
▪ Deploy on AWS in Paris Data Center
▪ Prefix with your name to avoid collisions
▪ Retrieve output public IP
▪ Use SSH Key to connect to the machine
$ ssh –i paris-keys.pem ec2-user@<ip>
ec-instance security-group
Terraform: Dependences
▪ Resources has dependences
▪ Forming a directed graph of resources
▪ Provision should follow a given order
▪ Deprovisining the reverse order
ec-instance
public-ip
esb-storage
vpc
dns
security group
load-balancing-group
rds-aurora-db
$ terraform graph http://www.webgraphviz.com/
Terraform: Desired State
Desired State: The ideal state described by the configuration (immutable).
Current State: The actual state in the infrastructure. Changes over time.
Services can be down. Provisioning can fail or lack or permissions.
Differences: The plan to add/remove/changes resources to achieve the
Desired State based in the Current State.
Terraform: State Management
Terraform uses:
▪ terraform.tfstate file to store last state know of a given infrastructure and
▪ terraform.tfstate.backup file to store the previous version.
There is service provide by Terraform athttps://app.terraform.io
to store the state in a shared central repository to be shared in a team.
For example: to prevent two provisionoperations at the same time.
Terraform: Basic Commands
terraforminit
terraformfmt
terraformvalidate
terraformplan
terraformapply
terraformdestroy
Terraform: Execution Plans
Sample:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_instance.machine01 will be created
+ resource "aws_instance" "machine01" {
+ ami = "ami-007fae589fdf6e955"
+ arn = (known after apply)
+ associate_public_ip_address = true
+ get_password_data = false
+ instance_type = "t2.micro"
+ ipv6_addresses = (known after apply)
+ key_name = "paris-keys"
+ security_groups = (known after apply)
+ source_dest_check = true
+ subnet_id = (known after apply)
…
Create a static Web-site
Exercise 02
Create astatic web-site withS3
▪ Create a public bucket
▪ Upload html files and make it public
▪ Use the provided URL to access the web-site
S3-bucket iam-policy
Remote provisioners
Exercise 03
Provision aMachine
▪ Apply software updates: sudo yum update -y
▪ Install Docker
▪ Launch a container for a web app
aws-instance security-group
provision 1
provision 2
Terraform: Modules
Modules
▪ allows to create reusable
assets to be share between
projects
▪ Hides complexity(VPC creation
example)
▪ Registry for publicModules
https://registry.terraform.io/modules
/terraform-aws-
modules/vpc/aws/2.21.0
module "vpc" {
source = "git@github.com:terraform-
aws-modules/terraform-aws-vpc.git"
name = "${var.vpc_name}"
cidr = "172.29.208.0/20"
private_subnets = [
"172.29.208.0/24",
"172.29.209.0/24",
"172.29.210.0/24" ]
enable_nat_gateway = true
}
Terraform: Industrial Examples
Samples
1. E2E Tests scenarios for an Online University using Azure
in Spain
2. Dev/Staging/Prod environments for a mobile fintech app
in UK using AWS
3. Setup a private CI server in the cloud with Teamcity
Example
SQL Server
DBS
DB0 Security
AuditLog
MasterData
Environment QA
$ terraform apply
$ terraform destroy
Immutable Infrastructure
AWS
VPC 10.10.0.0/16
Subnet no-internet
10.10.51.0/24
Subnet db
10.10.21.0/24
Subnet private
10.10.1.0/24
Subnet public
10.10.11.0/24
Avaliability Zone 1 eu-west-2a Avaliability Zone 2 eu-west-2b
Router VPN Gateway
Customer
Gateway
VPN
Connection
Subnet no-internet
10.10.52.0/24
Subnet db
10.10.22.0/24
Subnet private
10.10.2.0/24
Subnet public
10.10.12.0/24
db
rabbitmq
services
nginx
services
db
rabbitmq
nginx
batch batch
3rd-party
Avaliability Zone 3 eu-west-2c
Subnet no-internet
10.10.53.0/24
Subnet db
10.10.23.0/24
Subnet private
10.10.3.0/24
Subnet public
10.10.13.0/24
services
db
rabbitmq
nginx
batch
Private CI Server
Exercise 04
Provision aPrivateTeamcityforContinuous Integration
▪ On the Cloud
▪ Usable for free for private projects till 100 projects
aws-instance
docker-compose
teamcity
security-group
Best Practices
▪Build your Terraform Scripts incrementally
▪Test them frequently
▪Encapsulate repeated blocks as modules
▪Incorporate existing infrastructure with terraformimport
▪Use variables to parametrize regions, AMIs, environment
prefix, etc.
▪Do notstore sensible credentials in repositories (inject later
as ENV vars)
▪Use provisioners (non declarative) as a last resort (prefer
packed images AMI) See Packer https://packer.io
Alternatives
Pulumi
https://www.pulumi.com
Infrastructure as Code. Imperative(uses JS), not declarative.
Compatible with (reuse) Terraformprovisioners.
AWSCloud Formation
https://aws.amazon.com/es/cloudformation
Provides templates(JSON/YAML based) to create resourcesin AWS. AWS only.
Azure Resource Manager
https://docs.microsoft.com/es-es/azure/azure-resource-manager/templates/overview
Similartemplate approach to Cloud Formation for Azure only (JSON based).
https://metadev.pro
@metad3v

More Related Content

Similar to Infrastructure as Code with Terraform

Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?
Katherine Golovinova
 
Building the TribefireOperator
Building the TribefireOperatorBuilding the TribefireOperator
Building the TribefireOperator
Oliver Moser
 
Moving a Windows environment to the cloud - DevOps Galway Meetup
Moving a Windows environment to the cloud - DevOps Galway MeetupMoving a Windows environment to the cloud - DevOps Galway Meetup
Moving a Windows environment to the cloud - DevOps Galway Meetup
Giulio Vian
 
HotLink DR Express
HotLink DR ExpressHotLink DR Express
HotLink DR Expressdean1609
 
Higher order infrastructure: from Docker basics to cluster management - Nicol...
Higher order infrastructure: from Docker basics to cluster management - Nicol...Higher order infrastructure: from Docker basics to cluster management - Nicol...
Higher order infrastructure: from Docker basics to cluster management - Nicol...
Codemotion
 
DevOps Braga #9: Introdução ao Terraform
DevOps Braga #9:  Introdução ao TerraformDevOps Braga #9:  Introdução ao Terraform
DevOps Braga #9: Introdução ao Terraform
DevOps Braga
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
Mathieu Herbert
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
Docker, Inc.
 
Managing Infrastructure as Code
Managing Infrastructure as CodeManaging Infrastructure as Code
Managing Infrastructure as Code
Allan Shone
 
DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
GR8Conf
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAkshaya Mahapatra
 
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
LogeekNightUkraine
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...
Michele Leroux Bustamante
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting Techniques
Sreenivas Makam
 
Multi Tenancy With Python and Django
Multi Tenancy With Python and DjangoMulti Tenancy With Python and Django
Multi Tenancy With Python and Django
scottcrespo
 
Cloud Native Computing - Part III - Containers
Cloud Native Computing - Part III - ContainersCloud Native Computing - Part III - Containers
Cloud Native Computing - Part III - Containers
Linjith Kunnon
 
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
Tom Cappetta
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalk
Julien SIMON
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Nebulaworks
 
Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112
Nirmal Mehta
 

Similar to Infrastructure as Code with Terraform (20)

Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?
 
Building the TribefireOperator
Building the TribefireOperatorBuilding the TribefireOperator
Building the TribefireOperator
 
Moving a Windows environment to the cloud - DevOps Galway Meetup
Moving a Windows environment to the cloud - DevOps Galway MeetupMoving a Windows environment to the cloud - DevOps Galway Meetup
Moving a Windows environment to the cloud - DevOps Galway Meetup
 
HotLink DR Express
HotLink DR ExpressHotLink DR Express
HotLink DR Express
 
Higher order infrastructure: from Docker basics to cluster management - Nicol...
Higher order infrastructure: from Docker basics to cluster management - Nicol...Higher order infrastructure: from Docker basics to cluster management - Nicol...
Higher order infrastructure: from Docker basics to cluster management - Nicol...
 
DevOps Braga #9: Introdução ao Terraform
DevOps Braga #9:  Introdução ao TerraformDevOps Braga #9:  Introdução ao Terraform
DevOps Braga #9: Introdução ao Terraform
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Managing Infrastructure as Code
Managing Infrastructure as CodeManaging Infrastructure as Code
Managing Infrastructure as Code
 
DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
 
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
 
.NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time....NET Developer Days - So many Docker platforms, so little time...
.NET Developer Days - So many Docker platforms, so little time...
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting Techniques
 
Multi Tenancy With Python and Django
Multi Tenancy With Python and DjangoMulti Tenancy With Python and Django
Multi Tenancy With Python and Django
 
Cloud Native Computing - Part III - Containers
Cloud Native Computing - Part III - ContainersCloud Native Computing - Part III - Containers
Cloud Native Computing - Part III - Containers
 
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
Cyber Range - An Open-Source Offensive / Defensive Learning Environment on AWS
 
Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalk
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112
 

More from Pedro J. Molina

MDE en la industria
MDE en la industriaMDE en la industria
MDE en la industria
Pedro J. Molina
 
Terraform
TerraformTerraform
Terraform
Pedro J. Molina
 
dotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
dotnetMalaga-2020 Gestión de la configuración en aplicaciones WebdotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
dotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
Pedro J. Molina
 
LangDev 2022 Metamodeling on the Web with Essential
LangDev 2022 Metamodeling on the Web with EssentialLangDev 2022 Metamodeling on the Web with Essential
LangDev 2022 Metamodeling on the Web with Essential
Pedro J. Molina
 
Are Startups for me?
Are Startups for me?Are Startups for me?
Are Startups for me?
Pedro J. Molina
 
Meow Demo
Meow DemoMeow Demo
Meow Demo
Pedro J. Molina
 
Essential as the base for Web DSLs
Essential as the base for Web DSLsEssential as the base for Web DSLs
Essential as the base for Web DSLs
Pedro J. Molina
 
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. MolinaACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
Pedro J. Molina
 
Esencia de Web Components
Esencia de Web ComponentsEsencia de Web Components
Esencia de Web Components
Pedro J. Molina
 
Esencia de web components
Esencia de web componentsEsencia de web components
Esencia de web components
Pedro J. Molina
 
OpenAPI 3.0.2
OpenAPI 3.0.2OpenAPI 3.0.2
OpenAPI 3.0.2
Pedro J. Molina
 
Quid
QuidQuid
Securizando por construcción mediante MDE
Securizando por construcción mediante MDESecurizando por construcción mediante MDE
Securizando por construcción mediante MDE
Pedro J. Molina
 
Building APIs with the OpenApi Spec
Building APIs with the OpenApi SpecBuilding APIs with the OpenApi Spec
Building APIs with the OpenApi Spec
Pedro J. Molina
 
Micro vs Nano (servicios)
Micro vs Nano (servicios)Micro vs Nano (servicios)
Micro vs Nano (servicios)
Pedro J. Molina
 
Diseño de APIs con OpenAPI
Diseño de APIs con OpenAPIDiseño de APIs con OpenAPI
Diseño de APIs con OpenAPI
Pedro J. Molina
 
SVQDC 2017 Tecnologías para Microservicios
SVQDC 2017 Tecnologías para MicroserviciosSVQDC 2017 Tecnologías para Microservicios
SVQDC 2017 Tecnologías para Microservicios
Pedro J. Molina
 
Introducción a Angular
Introducción a AngularIntroducción a Angular
Introducción a Angular
Pedro J. Molina
 
Tecnologías para microservicios
Tecnologías para microserviciosTecnologías para microservicios
Tecnologías para microservicios
Pedro J. Molina
 
Opensouthcode: Microservicios sobre MEAN Stack
Opensouthcode: Microservicios sobre MEAN StackOpensouthcode: Microservicios sobre MEAN Stack
Opensouthcode: Microservicios sobre MEAN Stack
Pedro J. Molina
 

More from Pedro J. Molina (20)

MDE en la industria
MDE en la industriaMDE en la industria
MDE en la industria
 
Terraform
TerraformTerraform
Terraform
 
dotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
dotnetMalaga-2020 Gestión de la configuración en aplicaciones WebdotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
dotnetMalaga-2020 Gestión de la configuración en aplicaciones Web
 
LangDev 2022 Metamodeling on the Web with Essential
LangDev 2022 Metamodeling on the Web with EssentialLangDev 2022 Metamodeling on the Web with Essential
LangDev 2022 Metamodeling on the Web with Essential
 
Are Startups for me?
Are Startups for me?Are Startups for me?
Are Startups for me?
 
Meow Demo
Meow DemoMeow Demo
Meow Demo
 
Essential as the base for Web DSLs
Essential as the base for Web DSLsEssential as the base for Web DSLs
Essential as the base for Web DSLs
 
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. MolinaACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
ACM SIGCHI EICS-2019 Keynote. Quid, Pedro J. Molina
 
Esencia de Web Components
Esencia de Web ComponentsEsencia de Web Components
Esencia de Web Components
 
Esencia de web components
Esencia de web componentsEsencia de web components
Esencia de web components
 
OpenAPI 3.0.2
OpenAPI 3.0.2OpenAPI 3.0.2
OpenAPI 3.0.2
 
Quid
QuidQuid
Quid
 
Securizando por construcción mediante MDE
Securizando por construcción mediante MDESecurizando por construcción mediante MDE
Securizando por construcción mediante MDE
 
Building APIs with the OpenApi Spec
Building APIs with the OpenApi SpecBuilding APIs with the OpenApi Spec
Building APIs with the OpenApi Spec
 
Micro vs Nano (servicios)
Micro vs Nano (servicios)Micro vs Nano (servicios)
Micro vs Nano (servicios)
 
Diseño de APIs con OpenAPI
Diseño de APIs con OpenAPIDiseño de APIs con OpenAPI
Diseño de APIs con OpenAPI
 
SVQDC 2017 Tecnologías para Microservicios
SVQDC 2017 Tecnologías para MicroserviciosSVQDC 2017 Tecnologías para Microservicios
SVQDC 2017 Tecnologías para Microservicios
 
Introducción a Angular
Introducción a AngularIntroducción a Angular
Introducción a Angular
 
Tecnologías para microservicios
Tecnologías para microserviciosTecnologías para microservicios
Tecnologías para microservicios
 
Opensouthcode: Microservicios sobre MEAN Stack
Opensouthcode: Microservicios sobre MEAN StackOpensouthcode: Microservicios sobre MEAN Stack
Opensouthcode: Microservicios sobre MEAN Stack
 

Recently uploaded

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 

Recently uploaded (20)

Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 

Infrastructure as Code with Terraform

  • 2. Dr. Pedro J. Molina @pmolinam
  • 3. Agenda ▪ Infrastructure as Code ▪ Immutable Infrastructure ▪ Cloud Providers and AWS ▪ Terraform ▪ Installation & Software Prerequisites ▪ Resources & Dependencies ▪ Execution Plans ▪ Industrial examples ▪ Best practices ▪ Exercises on AWS + Terraform
  • 4. Get the material 1. Go to: https://github.com/metadevpro/terraform-aws-training 2. Clone the code examples: git clone git@github.com:metadevpro/terraform-aws-training.git 3. Get credentials for an AWS account
  • 5. Infrastructure as Code Engineering Practice to define Infrastructure as code and configuration. Main Properties: ▪ Repeatable ▪ Can be Versioned (with standard source code tools like git or hg) ▪ Robust ▪ Can be Automated
  • 6. Immutable Infrastructure Traditional Approach: PatchingServers ▪ Few items ▪ Named as pets ▪ Manual patching ▪ State unknown over time ▪ Improved by Ansible or Chef for automation New Approachon scale: Immutable Infrastructure ▪ No patching. Managed as bacteria ▪ Destroy and recreate ▪ Well know-state ▪ Apply all security patches for better safety
  • 7. Cloud Providers Main Players Amazon Web Services Microsoft Azure Google Cloud
  • 8. Amazon Web Services The first provider: inventors of the cloud (EC2, S3) Leading innovationon cloud: AWS Lambda,Fargate, etc. Very complete offeringof services. Many Data-Centersaround the world. Price competitive. Leaders and growingyear by year.
  • 9. Terraform https://www.terraform.io Leading tool for manage Infrastructure as Code. ▪ Open Source ▪ Created by Hashi Corporation https://www.hashicorp.com ▪ Custom language to define infrastructure: HCL
  • 10. Installation & Prereqs Download & Install: ▪ Terraform from: https://www.terraform.io/downloads.html ▪ Copy local & include it in PATH ▪ AWS-CLI: https://aws.amazon.com/en/cli ▪ Visual Studio Code (editor) https://code.visualstudio.com ▪ Install Extension for Terraform ▪ Bash Shell (git shell, Cmder, or Conemu in Windows) ▪ PuTTY (ssh client for Windows) https://www.putty.org
  • 11. Installation Cross-check $ terraform -version Terraform v0.14.7 $ aws --version aws-cli/1.16.193 Python/3.6.0 Windows/10 botocore/1.12.183
  • 12. Hashi Configuration Language (HCL) Terraform uses *.tf files. Simple Configuration DSL to describeResources and Desired State. Similar to JSON syntax, but rich in expressiveness. Samples: resource "aws_instance" "web" { ami = "ami-a1b2c3d4" instance_type = "t2.micro" } resource "heroku_app" "app1" { name = "my-cool-app" region = "us" config_vars = { FOOBAR = "baz" } buildpacks = [ "heroku/go", "heroku/node" ] }
  • 13. Terraform: Resources A Resource represent aconcrete (vendor-specific) Cloud Service we can manipulate. Resources has a well-knowtype with properties we must configure. Resources are exposed and managed byProviders. Examples: aws-instance Represents a machine in AWS EC2 Service. azurerm_virtual_machine Represents a virtual machine in Azure. google_compute_instance Represents a virtual machine in Google Cloud.
  • 14. Terraform: Providers A Provider is a driver implementing the communication and automation for an specific Cloud Provider. Each provider expose more or less Resource types dependingon the offeringof the CloudVendor, and the supportof the current Provider version. Examples: Google,Github or Digital Ocean See list of providers here: https://registry.terraform.io/browse/providers
  • 15. Terraform: Configure Provider provider.tf # Configure the AWS Provider provider "aws" { region = "eu-west-3" # Paris } $ terraform init
  • 16. Terraform: Input Variables variables.tf variable "author" { description = "Operator’s name. Used as prefix." type = string default = "jessica" } $ terraform apply -var author=alice Types: ▪ string ▪ number ▪ bool ▪ list ▪ map ▪ null
  • 17. Terraform: Variables Interpolation Variables can beinterpolated Name = "${var.author}_machine1" https://www.terraform.io/docs/configuration/expressions.html https://www.terraform.io/docs/configuration/functions.html
  • 18. Terraform: Output Variables output.tf output "instance_public_ip" { value = aws_instance.machine01.public_ip }
  • 19. Sample one Exercise 01 Create afirst Virtual Machine ▪ Setup credentials access to AWS ▪ Deploy on AWS in Paris Data Center ▪ Prefix with your name to avoid collisions ▪ Retrieve output public IP ▪ Use SSH Key to connect to the machine $ ssh –i paris-keys.pem ec2-user@<ip> ec-instance security-group
  • 20. Terraform: Dependences ▪ Resources has dependences ▪ Forming a directed graph of resources ▪ Provision should follow a given order ▪ Deprovisining the reverse order ec-instance public-ip esb-storage vpc dns security group load-balancing-group rds-aurora-db $ terraform graph http://www.webgraphviz.com/
  • 21. Terraform: Desired State Desired State: The ideal state described by the configuration (immutable). Current State: The actual state in the infrastructure. Changes over time. Services can be down. Provisioning can fail or lack or permissions. Differences: The plan to add/remove/changes resources to achieve the Desired State based in the Current State.
  • 22. Terraform: State Management Terraform uses: ▪ terraform.tfstate file to store last state know of a given infrastructure and ▪ terraform.tfstate.backup file to store the previous version. There is service provide by Terraform athttps://app.terraform.io to store the state in a shared central repository to be shared in a team. For example: to prevent two provisionoperations at the same time.
  • 24. Terraform: Execution Plans Sample: An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_instance.machine01 will be created + resource "aws_instance" "machine01" { + ami = "ami-007fae589fdf6e955" + arn = (known after apply) + associate_public_ip_address = true + get_password_data = false + instance_type = "t2.micro" + ipv6_addresses = (known after apply) + key_name = "paris-keys" + security_groups = (known after apply) + source_dest_check = true + subnet_id = (known after apply) …
  • 25. Create a static Web-site Exercise 02 Create astatic web-site withS3 ▪ Create a public bucket ▪ Upload html files and make it public ▪ Use the provided URL to access the web-site S3-bucket iam-policy
  • 26. Remote provisioners Exercise 03 Provision aMachine ▪ Apply software updates: sudo yum update -y ▪ Install Docker ▪ Launch a container for a web app aws-instance security-group provision 1 provision 2
  • 27. Terraform: Modules Modules ▪ allows to create reusable assets to be share between projects ▪ Hides complexity(VPC creation example) ▪ Registry for publicModules https://registry.terraform.io/modules /terraform-aws- modules/vpc/aws/2.21.0 module "vpc" { source = "git@github.com:terraform- aws-modules/terraform-aws-vpc.git" name = "${var.vpc_name}" cidr = "172.29.208.0/20" private_subnets = [ "172.29.208.0/24", "172.29.209.0/24", "172.29.210.0/24" ] enable_nat_gateway = true }
  • 28. Terraform: Industrial Examples Samples 1. E2E Tests scenarios for an Online University using Azure in Spain 2. Dev/Staging/Prod environments for a mobile fintech app in UK using AWS 3. Setup a private CI server in the cloud with Teamcity
  • 30. Immutable Infrastructure AWS VPC 10.10.0.0/16 Subnet no-internet 10.10.51.0/24 Subnet db 10.10.21.0/24 Subnet private 10.10.1.0/24 Subnet public 10.10.11.0/24 Avaliability Zone 1 eu-west-2a Avaliability Zone 2 eu-west-2b Router VPN Gateway Customer Gateway VPN Connection Subnet no-internet 10.10.52.0/24 Subnet db 10.10.22.0/24 Subnet private 10.10.2.0/24 Subnet public 10.10.12.0/24 db rabbitmq services nginx services db rabbitmq nginx batch batch 3rd-party Avaliability Zone 3 eu-west-2c Subnet no-internet 10.10.53.0/24 Subnet db 10.10.23.0/24 Subnet private 10.10.3.0/24 Subnet public 10.10.13.0/24 services db rabbitmq nginx batch
  • 31. Private CI Server Exercise 04 Provision aPrivateTeamcityforContinuous Integration ▪ On the Cloud ▪ Usable for free for private projects till 100 projects aws-instance docker-compose teamcity security-group
  • 32. Best Practices ▪Build your Terraform Scripts incrementally ▪Test them frequently ▪Encapsulate repeated blocks as modules ▪Incorporate existing infrastructure with terraformimport ▪Use variables to parametrize regions, AMIs, environment prefix, etc. ▪Do notstore sensible credentials in repositories (inject later as ENV vars) ▪Use provisioners (non declarative) as a last resort (prefer packed images AMI) See Packer https://packer.io
  • 33. Alternatives Pulumi https://www.pulumi.com Infrastructure as Code. Imperative(uses JS), not declarative. Compatible with (reuse) Terraformprovisioners. AWSCloud Formation https://aws.amazon.com/es/cloudformation Provides templates(JSON/YAML based) to create resourcesin AWS. AWS only. Azure Resource Manager https://docs.microsoft.com/es-es/azure/azure-resource-manager/templates/overview Similartemplate approach to Cloud Formation for Azure only (JSON based).