SlideShare une entreprise Scribd logo
1  sur  85
Télécharger pour lire hors ligne
Demystifying Terraform to manage AWS
@lbcde
2018-10-26
Xavier Krantz
- Site Reliability Engineer @Leboncoin
Previously:
● Criteo
● Viadeo
● Smile (OSS integrator)
https://github.com/xakraz
https://speakerdeck.com/xakraz
https://fr.linkedin.com/in/xavierkrantz/en
About Me
Introduction
● Terraform 101 - Bases
● Terraform 102 - Working together
● Terraform 103 - Easier, Better, Stronger
● Terraform 104 - Automation & Tooling
Conclusion
Agenda
Introduction
AWS “management” today @lbcde
● Web console
● Python boto scripts (some)
Introduction
Needs
● A way to work as a team
● A way to document our work
● History
Introduction
Existing tools
● Code libraries
● Config management
● AWS Service / Other SaaS
https://www.terraform.io/intro/vs/index.html
Introduction
Existing tools
● Code libraries
● Config management
● AWS Service / Other SaaS
https://www.terraform.io/intro/vs/index.html
Introduction
Existing tools
● Code libraries
● Config management
● AWS Service / Other SaaS
https://www.terraform.io/intro/vs/index.html
Terraform 101
Bases
Terraform 101
Bases
Overview
Concepts
Basics
Terraform 101
Overview
Terraform is a tool for building, changing and
versioning infrastructure safely and efficiently.
Terraform can manage existing and popular service
providers as well as custom in-house solutions.
terraform.io/intro
Terraform 101
Overview
What is Terraform
● Infrastructure as code
● Execution plan
● Resource graph
● Change automation tool
https://www.terraform.io/intro/index.html
Terraform 101
Concepts
Terraform 101
Concepts:
● Providers
Terraform 101
Concepts:
● Providers
● Resources
A TANGIBLE component of you infrastructures
● Provider specific
● What you want to manage
resource "aws_db_instance" "timeout_example" {
allocated_storage = 10
engine = "mysql"
engine_version = "5.6.17"
instance_class = "db.t1.micro"
name = "mydb"
# ...
timeouts {
create = "60m"
delete = "2h"
}
}
Terraform 101
Concepts:
● Providers
● Resources
● Data sources
A specific “dynamic” data you want
● External source
● Like dynamic variables
# Find the latest available AMI that is tagged with Component = web
data "aws_ami" "web" {
filter {
name = "state"
values = ["available"]
}
filter {
name = "tag:Component"
values = ["web"]
}
most_recent = true
}
Terraform 101
Concepts:
● Providers
● Resources
● Data sources
● Variables
Parameters of our code
● Have to be declared specifically
● Different types (String, boolean, maps, list, …)
● Can have defaults
variable "key" { type = "string" }
variable "images" {
type = "map"
default = {
us-east-1 = "image-1234"
us-west-2 = "image-4567"
}
}
variable "zones" {
default = ["us-east-1a", "us-east-1b"]
}
Terraform 101
Concepts:
● Providers
● Resources
● Data sources
● Variables
● Outputs
Outputs = Informations we want to get after Terraform has run
● Can be queried via CLI
● Will be shared across modules and resources
output "address" {
value = "${aws_instance.db.public_dns}"
}
Terraform 101
Basics
Terraform 101 Files
● *.tf
● *.tfvars
*.auto.tfvars
terraform.tfvars
● terraform.tfstate
https://www.terraform.io/intro/getting-started/install.html
Basics:
● Files
Terraform 101 4 Main commands
● terraform init
● terraform plan
● terraform apply
● terraform destroy
https://www.terraform.io/intro/getting-started/install.html
Basics:
● Files
● Commands
Terraform 101 Other capabilities
● Templates / Files
● Provisioner
● Built-in “functions”
● Basic conditionals
https://www.terraform.io/intro/getting-started/provision.html
https://www.terraform.io/docs/configuration/interpolation.html
Basics:
● Files
● Commands
● Others
Terraform 102
Working together
Terraform 102
Working together
TF internals
Remote state
State locking
Terraform 102
Internals
Terraform 102
Internals
1 - Pre-Compiles
Check syntax, types …
Validate resources
5 - Applies
Makes the API call to apply the
changes described in the plan
2 - Refresh the state
Call the providers APIs to
get an updated view
4 - Plan
Computes the plan to
match the desired state
3 - Compiles 2
Runs DataSources
Instantiates the resources
-> Gets desired state
Terraform
internals
6 - Applies
Updates the final state file
Terraform 102
Internals
1 - Pre-Compiles
Check syntax, types …
Validate resources
5 - Applies
Makes the API call to apply the
changes described in the plan
2 - Refresh the state
Call the providers APIs to
get an updated view
4 - Plan
Computes the plan to
match the desired state
3 - Compiles 2
Runs DataSources
Instantiates the resources
-> Gets desired state
Terraform
internals
6 - Applies
Updates the final state file
Terraform 102 - Internals
Terraform 102 - Internals
?
?
Terraform 102
Remote State
Terraform Remote state “Backend”: principles
Terraform 102
Remote state
Terraform Remote state “Backend”: types
Terraform 102
Remote state
Terraform Remote state “Backend”: example
Terraform 102
Remote state
backend.tf
terraform {
backend "s3" {
bucket = "mybucket_name"
key = "path/to/my/key"
}
}
Terraform 102
State locking
Terraform 102 - State locking
Terraform 102 - State locking
Terraform 102 - State locking
?
Terraform Remote state “Backend”:
● S3
● + DynamoDB
Terraform 102
State locking
backend.tf
terraform {
backend "s3" {
bucket = "my_bucket_name"
encrypt = "true"
dynamodb_table = "my_ddb_table)name"
region = "eu-west-1"
role_arn = "arn:aws:iam::xxxxxxxxxxxx:role/AssumeRole"
}
}
Terraform 102 - State locking
Terraform 102 - State locking
Terraform 103
Better, easier, stronger
Terraform 103
Better, easier, stronger
Modules
Remote state access
Workspaces
Terraform 103
Modules
Terraform 103
Modules
Terraform Modules
● Reusable set of “pre” defined / packaged resources
● Helps to model the architecture
Features:
● Versioned
● Various sources:
○ HTTP
○ SCM (git, svn, hg, …)
○ Local file system
https://registry.terraform.io/
https://www.terraform.io/docs/modules/index.html
Terraform 103
Modules
Terraform Modules
privacy-access.tf
module "privacy-access" {
source = "modules/privacy-access"
instance_count = "${var.access_instance_count}"
instance_type = "${var.access_instance_type}"
…
}
Terraform 103
Modules
Terraform Modules
data-privacy/
|
├── code/
├── modules/
├── shared/
└── README.md
Terraform 103
Modules
Terraform Modules
data-privacy/
|
├── code/
├── modules/
├── shared/
└── README.md
data-privacy/
└── modules/
└── privacy-access/
├── alb.tf
├── ec2.tf
├── iam.tf
├── rds.tf
├── s3.tf
├── sg.tf
|
├── outputs.tf
└── input.tf
Terraform 103
Modules
Terraform Modules
data-privacy/
|
├── code/
├── modules/
├── shared/
└── README.md
data-privacy/
└── modules/
└── privacy-access/
├── alb.tf
├── ec2.tf
├── iam.tf
├── rds.tf
├── s3.tf
├── sg.tf
|
├── outputs.tf
└── input.tf
data-privacy/
└── code/
├── modules -> ../modules/
├── vars/
│ ├── aws-account/
│ │ ├── datadev.tfvars ->
│ │ └── dataprod.tfvars ->
│ │
│ └── env/
│ ├── prod.tfvars
│ ├── qa0.tfvars
│ └── qa2.tfvars
│
├── backend.conf
├── backend.tf -> ../shared/backend.tf
├── shared-variables.tf ->
│
├── privacy-access.tf
├── privacy-request.tf
│
├── route53.tf
├── security_groups.tf
│
├── tf-config.tf
├── data-sources.tf
├── outputs.tf
└── variables.tf
Terraform 103
Remote state access
Terraform Remote state “data source”
Terraform 103
Remote state access
data-privacy/scripts/provision/terraform/code/data-sources.tf
data "terraform_remote_state" "spark" {
backend = "s3"
config{
bucket = "my_bucket_name"
region = "${var.region}"
key = "env:/${var.env_type}/spark/main.tfstate"
}
}
Terraform Remote state “data source”
Terraform 103
Remote state access
data-privacy/scripts/provision/terraform/code/data-sources.tf
data "terraform_remote_state" "spark" {
backend = "s3"
config{
bucket = "data-engineering.infrastructure.leboncoin.io-tfstates"
region = "${var.region}"
key = "env:/${var.env_type}/spark/main.tfstate"
}
}
privacy-access.tf
module "privacy-access" {
source = "modules/privacy-access"
# Spark shared cluster
spark_role = "${data.terraform_remote_state.spark.spark_role}"
spark_security_group_id = "${data.terraform_remote_state.spark.spark_sg}"
instance_count = "${var.access_instance_count}"
instance_type = "${var.access_instance_type}"
...
}
Terraform 103
Remote state access
{
version: 3,
terraform_version: "0.11.3",
serial: 43,
lineage: "c188d838-a1a0-419a-b04d-31ccb92b6e2c",
modules: [
{
path: [
"root"
],
outputs: {
spark_master_dns: {
sensitive: false,
type: "list",
value: [
"spark-master-qa-0.data.mydomain.io"
]
},
spark_master_ips: {
sensitive: false,
type: "list",
value: [
"172.17.32.207"
]
},
spark_role: {
sensitive: false,
type: "string",
value: "spark-s3rw-qa"
},
spark_sg: {
sensitive: false,
type: "string",
value: "sg-xxxxxxxx"
}
},
Terraform 103
Workspaces
Terraform 103
Workspaces
Terraform States “workspaces”
● 1st the Monolith
main.tf
terraform.tfvars
Terraform 103
Workspaces
Terraform States “workspaces”
● 2nd the split
backend.tf
main.tf
ec2.tf
route53.tf
security-groups.tf
terraform.tfvars
Terraform 103
Workspaces
Terraform States “workspaces”
● 3rd ENVs segregation
Terraform 103
Workspaces
Terraform States “workspaces”
● 3rd ENVs segregation
Terraform 103
Workspaces
Terraform States “workspaces”
● 3rd ENVs segregation
Terraform 103
Workspaces
Terraform States “workspaces”
● 3rd ENVs segregation
WHY ?
→Use a variable in Backend
config ?
Terraform 103
Workspaces
Terraform States “workspaces”
● 3rd ENVs segregation
WHY ?
→Use a variable in Backend
config ?
Terraform 103 - Workspaces
Workspaces
Terraform States “workspaces”
● 4th the State workspace
Terraform 103 - Workspaces
Terraform 104
Tooling & Automation
Terraform 104
Tooling & Automation
Automation
Monitoring
Tools
Terraform 104
Automate your needs
To meet your workflow
Why automation ?
●
Terraform 104
Automate you needs
data-privacy/
|
├── code/
├── modules/
├── shared/
└── README.md
data-privacy/
└── code/
├── modules -> ../modules/
├── vars/
│ ├── aws-account/
│ │ ├── datadev.tfvars ->
│ │ └── dataprod.tfvars ->
│ │
│ └── env/
│ ├── prod.tfvars
│ ├── qa0.tfvars
│ └── qa2.tfvars
│
├── backend.conf
├── backend.tf -> ../shared/backend.tf
├── shared-variables.tf ->
│
├── privacy-access.tf
├── privacy-request.tf
│
├── route53.tf
├── security_groups.tf
│
├── tf-config.tf
├── data-sources.tf
├── outputs.tf
└── variables.tf
data-privacy/
└── modules/
└── privacy-access/
├── alb.tf
├── ec2.tf
├── iam.tf
├── rds.tf
├── s3.tf
├── sg.tf
|
├── outputs.tf
└── input.tf
Why automation ?
Terraform 104
Automate you needs
$ cd YOUR_PROJECT_PATH
$ terraform init -backend-config=./backend.conf
$ terraform apply -var-file=./vars/env/{env}.tfvars
-var-file=./vars/aws-account/{aws_account}.tfvars
Automated actions via “invoke”
Terraform 104
Automate you needs
$ invoke -l
Available tasks:
...
provision.apply Update the whole stack (More with '--help')
provision.destroy Destroy the aws resources (More with '--help')
provision.init Initialize Terraform (More with '--help')
provision.list-stack-envs
provision.list-stacks
provision.status Display IDs of current resources (More with '--help')
...
Terraform 104
Monitoring
Terraform 104 State Drift Detection
● TF is imperative by usage (No daemon)
● For better readability -> Split your code in “Stacks”
● Shared with data-sources among teams
● Manual actions in the AWS Console or other projects
https://www.hashicorp.com/blog/detecting-and-managing-drift-with-terraform
https://medium.com/build-acl/state-drift-detection-using-terraform-d0383628d2ea
Monitoring
Terraform 104 State Drift Detection
https://github.com/gibbster/terraform-plan-drift-checker
Monitoring
Terraform 104
Misc tooling
Pre-commit - Terraform
Terraform 104
Tools
https://pre-commit.com/
https://github.com/antonbabenko/pre-commit-terraform
Terraform-landscape
Terraform 104
Tools
https://github.com/coinbase/terraform-landscape
Terraform-docs
Terraform 104
Tools
https://github.com/segmentio/terraform-docs
Blast Radius
Terraform 104
Tools
https://github.com/28mm/blast-radius
TerraBoard
Terraform 104
Tools
https://github.com/camptocamp/terraboard
Conclusion
Terraform 101
Bases
Overview
Concepts
Basics
Terraform 102
Working together
TF internals
Remote state
State locking
Terraform 103
Better, easier, stronger
Modules
Remote state access
Workspaces
Terraform 104
Tooling & Automation
Automation
Monitoring
Tools
Conclusion
Terraform:
● 1 binary, for every OS
● Wide range of providers
● Simple concepts
Answers our needs:
● Infra as Code
● Operations safety
● Share and reuse with ease
questions /
réponses
Links
References
Official doc:
● Terraform.io
Modules registry:
● registry.terraform.io
Some inspiring presentations
● https://speakerdeck.com/jmickey/introduction-to-terraform
● https://speakerdeck.com/so0k/terraform-at-honestbee
Good tools:
● https://github.com/camptocamp/terraboard
● https://github.com/28mm/blast-radius
● https://github.com/segmentio/terraform-docs
● https://github.com/coinbase/terraform-landscape
● https://github.com/shuaibiyy/awesome-terraform

Contenu connexe

Tendances

Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingAngel Boy
 
Spark and Cassandra 2 Fast 2 Furious
Spark and Cassandra 2 Fast 2 FuriousSpark and Cassandra 2 Fast 2 Furious
Spark and Cassandra 2 Fast 2 FuriousRussell Spitzer
 
Hive data migration (export/import)
Hive data migration (export/import)Hive data migration (export/import)
Hive data migration (export/import)Bopyo Hong
 
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...CloudxLab
 
Escape From Hadoop: Spark One Liners for C* Ops
Escape From Hadoop: Spark One Liners for C* OpsEscape From Hadoop: Spark One Liners for C* Ops
Escape From Hadoop: Spark One Liners for C* OpsRussell Spitzer
 
Solr 6 Feature Preview
Solr 6 Feature PreviewSolr 6 Feature Preview
Solr 6 Feature PreviewYonik Seeley
 
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage systemAthens Big Data
 
Spark Cassandra Connector: Past, Present, and Future
Spark Cassandra Connector: Past, Present, and FutureSpark Cassandra Connector: Past, Present, and Future
Spark Cassandra Connector: Past, Present, and FutureRussell Spitzer
 
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...Lucidworks
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and TricksErik Hatcher
 
An Introduction to Basics of Search and Relevancy with Apache Solr
An Introduction to Basics of Search and Relevancy with Apache SolrAn Introduction to Basics of Search and Relevancy with Apache Solr
An Introduction to Basics of Search and Relevancy with Apache SolrLucidworks (Archived)
 
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomynzhang
 
Commands documentaion
Commands documentaionCommands documentaion
Commands documentaionTejalNijai
 
The elements of a functional mindset
The elements of a functional mindsetThe elements of a functional mindset
The elements of a functional mindsetEric Normand
 
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...Puppet
 
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014steffenbauer
 

Tendances (20)

Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
 
Spark and Cassandra 2 Fast 2 Furious
Spark and Cassandra 2 Fast 2 FuriousSpark and Cassandra 2 Fast 2 Furious
Spark and Cassandra 2 Fast 2 Furious
 
Hive data migration (export/import)
Hive data migration (export/import)Hive data migration (export/import)
Hive data migration (export/import)
 
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
 
Escape From Hadoop: Spark One Liners for C* Ops
Escape From Hadoop: Spark One Liners for C* OpsEscape From Hadoop: Spark One Liners for C* Ops
Escape From Hadoop: Spark One Liners for C* Ops
 
Solr 6 Feature Preview
Solr 6 Feature PreviewSolr 6 Feature Preview
Solr 6 Feature Preview
 
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system
21st Athens Big Data Meetup - 2nd Talk - Dive into ClickHouse storage system
 
Spark Cassandra Connector: Past, Present, and Future
Spark Cassandra Connector: Past, Present, and FutureSpark Cassandra Connector: Past, Present, and Future
Spark Cassandra Connector: Past, Present, and Future
 
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...
Rebalance API for SolrCloud: Presented by Nitin Sharma, Netflix & Suruchi Sha...
 
Query Parsing - Tips and Tricks
Query Parsing - Tips and TricksQuery Parsing - Tips and Tricks
Query Parsing - Tips and Tricks
 
An Introduction to Basics of Search and Relevancy with Apache Solr
An Introduction to Basics of Search and Relevancy with Apache SolrAn Introduction to Basics of Search and Relevancy with Apache Solr
An Introduction to Basics of Search and Relevancy with Apache Solr
 
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomy
 
Commands documentaion
Commands documentaionCommands documentaion
Commands documentaion
 
JSON in Solr: from top to bottom
JSON in Solr: from top to bottomJSON in Solr: from top to bottom
JSON in Solr: from top to bottom
 
The elements of a functional mindset
The elements of a functional mindsetThe elements of a functional mindset
The elements of a functional mindset
 
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
 
Introduction to solr
Introduction to solrIntroduction to solr
Introduction to solr
 
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark Introduction | Big Data Hadoop Spark Tutorial | CloudxLab
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 

Similaire à leboncoin DataEngineering / Terraform - beginner to advanced

Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practicesRadek Simko
 
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
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Jonathon Brouse
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Adin Ermie
 
Terraform infraestructura como código
Terraform infraestructura como códigoTerraform infraestructura como código
Terraform infraestructura como códigoVictor Adsuar
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerCalvin French-Owen
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
 
Hashicorp Terraform with Microsoft Azure
Hashicorp Terraform with Microsoft AzureHashicorp Terraform with Microsoft Azure
Hashicorp Terraform with Microsoft AzureAlan Chen
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformRadek Simko
 
Terraform infrastructure as code for mere mortals
Terraform   infrastructure as code for mere mortalsTerraform   infrastructure as code for mere mortals
Terraform infrastructure as code for mere mortalsAnderson Carvalho
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipelineAnton Babenko
 
"Continuously delivering infrastructure using Terraform and Packer" training ...
"Continuously delivering infrastructure using Terraform and Packer" training ..."Continuously delivering infrastructure using Terraform and Packer" training ...
"Continuously delivering infrastructure using Terraform and Packer" training ...Anton Babenko
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeMartin Schütte
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecastMasahiro Nagano
 
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...NETWAYS
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Radek Simko
 

Similaire à leboncoin DataEngineering / Terraform - beginner to advanced (20)

Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good 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
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 
London HUG 12/4
London HUG 12/4London HUG 12/4
London HUG 12/4
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
 
Terraform in action
Terraform in actionTerraform in action
Terraform in action
 
Terraform infraestructura como código
Terraform infraestructura como códigoTerraform infraestructura como código
Terraform infraestructura como código
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 
Terraform training 🎒 - Basic
Terraform training 🎒 - BasicTerraform training 🎒 - Basic
Terraform training 🎒 - Basic
 
Terraform Cosmos DB
Terraform Cosmos DBTerraform Cosmos DB
Terraform Cosmos DB
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
Hashicorp Terraform with Microsoft Azure
Hashicorp Terraform with Microsoft AzureHashicorp Terraform with Microsoft Azure
Hashicorp Terraform with Microsoft Azure
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with Terraform
 
Terraform infrastructure as code for mere mortals
Terraform   infrastructure as code for mere mortalsTerraform   infrastructure as code for mere mortals
Terraform infrastructure as code for mere mortals
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
"Continuously delivering infrastructure using Terraform and Packer" training ...
"Continuously delivering infrastructure using Terraform and Packer" training ..."Continuously delivering infrastructure using Terraform and Packer" training ...
"Continuously delivering infrastructure using Terraform and Packer" training ...
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 
Introduction to cloudforecast
Introduction to cloudforecastIntroduction to cloudforecast
Introduction to cloudforecast
 
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)
 

Dernier

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Dernier (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

leboncoin DataEngineering / Terraform - beginner to advanced

  • 1. Demystifying Terraform to manage AWS @lbcde 2018-10-26
  • 2. Xavier Krantz - Site Reliability Engineer @Leboncoin Previously: ● Criteo ● Viadeo ● Smile (OSS integrator) https://github.com/xakraz https://speakerdeck.com/xakraz https://fr.linkedin.com/in/xavierkrantz/en About Me
  • 3. Introduction ● Terraform 101 - Bases ● Terraform 102 - Working together ● Terraform 103 - Easier, Better, Stronger ● Terraform 104 - Automation & Tooling Conclusion Agenda
  • 4. Introduction AWS “management” today @lbcde ● Web console ● Python boto scripts (some)
  • 5. Introduction Needs ● A way to work as a team ● A way to document our work ● History
  • 6. Introduction Existing tools ● Code libraries ● Config management ● AWS Service / Other SaaS https://www.terraform.io/intro/vs/index.html
  • 7. Introduction Existing tools ● Code libraries ● Config management ● AWS Service / Other SaaS https://www.terraform.io/intro/vs/index.html
  • 8. Introduction Existing tools ● Code libraries ● Config management ● AWS Service / Other SaaS https://www.terraform.io/intro/vs/index.html
  • 11. Terraform 101 Overview Terraform is a tool for building, changing and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. terraform.io/intro
  • 12. Terraform 101 Overview What is Terraform ● Infrastructure as code ● Execution plan ● Resource graph ● Change automation tool https://www.terraform.io/intro/index.html
  • 15. Terraform 101 Concepts: ● Providers ● Resources A TANGIBLE component of you infrastructures ● Provider specific ● What you want to manage resource "aws_db_instance" "timeout_example" { allocated_storage = 10 engine = "mysql" engine_version = "5.6.17" instance_class = "db.t1.micro" name = "mydb" # ... timeouts { create = "60m" delete = "2h" } }
  • 16. Terraform 101 Concepts: ● Providers ● Resources ● Data sources A specific “dynamic” data you want ● External source ● Like dynamic variables # Find the latest available AMI that is tagged with Component = web data "aws_ami" "web" { filter { name = "state" values = ["available"] } filter { name = "tag:Component" values = ["web"] } most_recent = true }
  • 17. Terraform 101 Concepts: ● Providers ● Resources ● Data sources ● Variables Parameters of our code ● Have to be declared specifically ● Different types (String, boolean, maps, list, …) ● Can have defaults variable "key" { type = "string" } variable "images" { type = "map" default = { us-east-1 = "image-1234" us-west-2 = "image-4567" } } variable "zones" { default = ["us-east-1a", "us-east-1b"] }
  • 18. Terraform 101 Concepts: ● Providers ● Resources ● Data sources ● Variables ● Outputs Outputs = Informations we want to get after Terraform has run ● Can be queried via CLI ● Will be shared across modules and resources output "address" { value = "${aws_instance.db.public_dns}" }
  • 20. Terraform 101 Files ● *.tf ● *.tfvars *.auto.tfvars terraform.tfvars ● terraform.tfstate https://www.terraform.io/intro/getting-started/install.html Basics: ● Files
  • 21. Terraform 101 4 Main commands ● terraform init ● terraform plan ● terraform apply ● terraform destroy https://www.terraform.io/intro/getting-started/install.html Basics: ● Files ● Commands
  • 22. Terraform 101 Other capabilities ● Templates / Files ● Provisioner ● Built-in “functions” ● Basic conditionals https://www.terraform.io/intro/getting-started/provision.html https://www.terraform.io/docs/configuration/interpolation.html Basics: ● Files ● Commands ● Others
  • 24. Terraform 102 Working together TF internals Remote state State locking
  • 26. Terraform 102 Internals 1 - Pre-Compiles Check syntax, types … Validate resources 5 - Applies Makes the API call to apply the changes described in the plan 2 - Refresh the state Call the providers APIs to get an updated view 4 - Plan Computes the plan to match the desired state 3 - Compiles 2 Runs DataSources Instantiates the resources -> Gets desired state Terraform internals 6 - Applies Updates the final state file
  • 27. Terraform 102 Internals 1 - Pre-Compiles Check syntax, types … Validate resources 5 - Applies Makes the API call to apply the changes described in the plan 2 - Refresh the state Call the providers APIs to get an updated view 4 - Plan Computes the plan to match the desired state 3 - Compiles 2 Runs DataSources Instantiates the resources -> Gets desired state Terraform internals 6 - Applies Updates the final state file
  • 28. Terraform 102 - Internals
  • 29. Terraform 102 - Internals ? ?
  • 31. Terraform Remote state “Backend”: principles Terraform 102 Remote state
  • 32. Terraform Remote state “Backend”: types Terraform 102 Remote state
  • 33. Terraform Remote state “Backend”: example Terraform 102 Remote state backend.tf terraform { backend "s3" { bucket = "mybucket_name" key = "path/to/my/key" } }
  • 35. Terraform 102 - State locking
  • 36. Terraform 102 - State locking
  • 37. Terraform 102 - State locking ?
  • 38. Terraform Remote state “Backend”: ● S3 ● + DynamoDB Terraform 102 State locking backend.tf terraform { backend "s3" { bucket = "my_bucket_name" encrypt = "true" dynamodb_table = "my_ddb_table)name" region = "eu-west-1" role_arn = "arn:aws:iam::xxxxxxxxxxxx:role/AssumeRole" } }
  • 39. Terraform 102 - State locking
  • 40. Terraform 102 - State locking
  • 42. Terraform 103 Better, easier, stronger Modules Remote state access Workspaces
  • 44. Terraform 103 Modules Terraform Modules ● Reusable set of “pre” defined / packaged resources ● Helps to model the architecture Features: ● Versioned ● Various sources: ○ HTTP ○ SCM (git, svn, hg, …) ○ Local file system https://registry.terraform.io/ https://www.terraform.io/docs/modules/index.html
  • 45. Terraform 103 Modules Terraform Modules privacy-access.tf module "privacy-access" { source = "modules/privacy-access" instance_count = "${var.access_instance_count}" instance_type = "${var.access_instance_type}" … }
  • 46. Terraform 103 Modules Terraform Modules data-privacy/ | ├── code/ ├── modules/ ├── shared/ └── README.md
  • 47. Terraform 103 Modules Terraform Modules data-privacy/ | ├── code/ ├── modules/ ├── shared/ └── README.md data-privacy/ └── modules/ └── privacy-access/ ├── alb.tf ├── ec2.tf ├── iam.tf ├── rds.tf ├── s3.tf ├── sg.tf | ├── outputs.tf └── input.tf
  • 48. Terraform 103 Modules Terraform Modules data-privacy/ | ├── code/ ├── modules/ ├── shared/ └── README.md data-privacy/ └── modules/ └── privacy-access/ ├── alb.tf ├── ec2.tf ├── iam.tf ├── rds.tf ├── s3.tf ├── sg.tf | ├── outputs.tf └── input.tf data-privacy/ └── code/ ├── modules -> ../modules/ ├── vars/ │ ├── aws-account/ │ │ ├── datadev.tfvars -> │ │ └── dataprod.tfvars -> │ │ │ └── env/ │ ├── prod.tfvars │ ├── qa0.tfvars │ └── qa2.tfvars │ ├── backend.conf ├── backend.tf -> ../shared/backend.tf ├── shared-variables.tf -> │ ├── privacy-access.tf ├── privacy-request.tf │ ├── route53.tf ├── security_groups.tf │ ├── tf-config.tf ├── data-sources.tf ├── outputs.tf └── variables.tf
  • 50. Terraform Remote state “data source” Terraform 103 Remote state access data-privacy/scripts/provision/terraform/code/data-sources.tf data "terraform_remote_state" "spark" { backend = "s3" config{ bucket = "my_bucket_name" region = "${var.region}" key = "env:/${var.env_type}/spark/main.tfstate" } }
  • 51. Terraform Remote state “data source” Terraform 103 Remote state access data-privacy/scripts/provision/terraform/code/data-sources.tf data "terraform_remote_state" "spark" { backend = "s3" config{ bucket = "data-engineering.infrastructure.leboncoin.io-tfstates" region = "${var.region}" key = "env:/${var.env_type}/spark/main.tfstate" } } privacy-access.tf module "privacy-access" { source = "modules/privacy-access" # Spark shared cluster spark_role = "${data.terraform_remote_state.spark.spark_role}" spark_security_group_id = "${data.terraform_remote_state.spark.spark_sg}" instance_count = "${var.access_instance_count}" instance_type = "${var.access_instance_type}" ... }
  • 52. Terraform 103 Remote state access { version: 3, terraform_version: "0.11.3", serial: 43, lineage: "c188d838-a1a0-419a-b04d-31ccb92b6e2c", modules: [ { path: [ "root" ], outputs: { spark_master_dns: { sensitive: false, type: "list", value: [ "spark-master-qa-0.data.mydomain.io" ] }, spark_master_ips: { sensitive: false, type: "list", value: [ "172.17.32.207" ] }, spark_role: { sensitive: false, type: "string", value: "spark-s3rw-qa" }, spark_sg: { sensitive: false, type: "string", value: "sg-xxxxxxxx" } },
  • 54. Terraform 103 Workspaces Terraform States “workspaces” ● 1st the Monolith main.tf terraform.tfvars
  • 55. Terraform 103 Workspaces Terraform States “workspaces” ● 2nd the split backend.tf main.tf ec2.tf route53.tf security-groups.tf terraform.tfvars
  • 56. Terraform 103 Workspaces Terraform States “workspaces” ● 3rd ENVs segregation
  • 57. Terraform 103 Workspaces Terraform States “workspaces” ● 3rd ENVs segregation
  • 58. Terraform 103 Workspaces Terraform States “workspaces” ● 3rd ENVs segregation
  • 59. Terraform 103 Workspaces Terraform States “workspaces” ● 3rd ENVs segregation WHY ? →Use a variable in Backend config ?
  • 60. Terraform 103 Workspaces Terraform States “workspaces” ● 3rd ENVs segregation WHY ? →Use a variable in Backend config ?
  • 61. Terraform 103 - Workspaces Workspaces Terraform States “workspaces” ● 4th the State workspace
  • 62. Terraform 103 - Workspaces
  • 64. Terraform 104 Tooling & Automation Automation Monitoring Tools
  • 65. Terraform 104 Automate your needs To meet your workflow
  • 66. Why automation ? ● Terraform 104 Automate you needs data-privacy/ | ├── code/ ├── modules/ ├── shared/ └── README.md data-privacy/ └── code/ ├── modules -> ../modules/ ├── vars/ │ ├── aws-account/ │ │ ├── datadev.tfvars -> │ │ └── dataprod.tfvars -> │ │ │ └── env/ │ ├── prod.tfvars │ ├── qa0.tfvars │ └── qa2.tfvars │ ├── backend.conf ├── backend.tf -> ../shared/backend.tf ├── shared-variables.tf -> │ ├── privacy-access.tf ├── privacy-request.tf │ ├── route53.tf ├── security_groups.tf │ ├── tf-config.tf ├── data-sources.tf ├── outputs.tf └── variables.tf data-privacy/ └── modules/ └── privacy-access/ ├── alb.tf ├── ec2.tf ├── iam.tf ├── rds.tf ├── s3.tf ├── sg.tf | ├── outputs.tf └── input.tf
  • 67. Why automation ? Terraform 104 Automate you needs $ cd YOUR_PROJECT_PATH $ terraform init -backend-config=./backend.conf $ terraform apply -var-file=./vars/env/{env}.tfvars -var-file=./vars/aws-account/{aws_account}.tfvars
  • 68. Automated actions via “invoke” Terraform 104 Automate you needs $ invoke -l Available tasks: ... provision.apply Update the whole stack (More with '--help') provision.destroy Destroy the aws resources (More with '--help') provision.init Initialize Terraform (More with '--help') provision.list-stack-envs provision.list-stacks provision.status Display IDs of current resources (More with '--help') ...
  • 70. Terraform 104 State Drift Detection ● TF is imperative by usage (No daemon) ● For better readability -> Split your code in “Stacks” ● Shared with data-sources among teams ● Manual actions in the AWS Console or other projects https://www.hashicorp.com/blog/detecting-and-managing-drift-with-terraform https://medium.com/build-acl/state-drift-detection-using-terraform-d0383628d2ea Monitoring
  • 71. Terraform 104 State Drift Detection https://github.com/gibbster/terraform-plan-drift-checker Monitoring
  • 73. Pre-commit - Terraform Terraform 104 Tools https://pre-commit.com/ https://github.com/antonbabenko/pre-commit-terraform
  • 80. Terraform 102 Working together TF internals Remote state State locking
  • 81. Terraform 103 Better, easier, stronger Modules Remote state access Workspaces
  • 82. Terraform 104 Tooling & Automation Automation Monitoring Tools
  • 83. Conclusion Terraform: ● 1 binary, for every OS ● Wide range of providers ● Simple concepts Answers our needs: ● Infra as Code ● Operations safety ● Share and reuse with ease
  • 85. Links References Official doc: ● Terraform.io Modules registry: ● registry.terraform.io Some inspiring presentations ● https://speakerdeck.com/jmickey/introduction-to-terraform ● https://speakerdeck.com/so0k/terraform-at-honestbee Good tools: ● https://github.com/camptocamp/terraboard ● https://github.com/28mm/blast-radius ● https://github.com/segmentio/terraform-docs ● https://github.com/coinbase/terraform-landscape ● https://github.com/shuaibiyy/awesome-terraform