SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Immutable infrastructure
with Terraform
by Sergii Marchenko
Sergii Marchenko
Head of IT at Dev-Pro
10 years in IT
Loves Terraform, and PowerShell :))
Knows a bit about DevOps
Thinks he can write some code in Go
Email: sergihire@gmail.com
Skype: sergihire
https://github.com/s-marchenko/GoWeb-PostgreSQL
How configuration docs look like
Spinning up a new server
IaC approaches
IaC is a must
1. Chief
2. Puppet
3. Ansible
4. Cloudformation
5. Terraform
6. Pulumi
7. Code (Java, Go, JS)
IaC tools
IaC approaches
Mutable or Immutable
Mutable
1. Server Drifts (Provisioning at diff time, manual actions, random failures)
2. You don't know how to configure it once again (Snowflake Server)
3. Hard to support multiple identical servers (Dev/Stage/Prod, Blue-Green)
IaC approaches
Immutable
1. Don’t install new software
2. Don’t update servers
3. Don’t change configs
4. Don’t update code
5. Just one thing you can do with you infra - DELETE IT
Immutable principles
Software update?
Build a new image, replace the old one.
Config update?
Build a new image, replace the old one.
Deploy a new version of the code?
Build a new image, replace the old one.
Docker brings us immutable approach
Why Terraform?
TF is good
● A master is not required
● An agent is not required
● Declarative
● There is a state in the state file
● SImple Configuration Language (HCL)
● TF plan
● Count
● Loops (For, if)
TF is good
● TF is a kind of documentation
● Clear change management (version control)
● Reusable (dev, stg, prod)
● Not only for a small team, works for 10+ DevOps/SRE
● The best way to implement Immutable infrastructure approach
● Fast (hey, Ansible)
Why Terraform
Modules
● Modules
● Yes, modules
● One more time, modules
● Many modules
Simple TF code
resource "google_compute_disk" "default" {
name = "test-disk"
type = "pd-ssd"
zone = "us-west1-b"
image = "debian-8-jessie-v20170523"
labels = {
environment = "dev"
}
Module
module "database" {
source = "../database"
environment = var.environment
region = var.region
whitelist = var.whitelist
project_name = var.project_name
}
How to start?
No manual actions!
1. No manual actions
2. No, you can't create a tiny resource manually
3. Yes, it matters
4. No, there are no exceptions to the rule
5. Yes, local-exec is better than manual actions
Use a Vault for secrets
1. Hashi Vault
2. AWS KMS
3. Azure Key Vault
Use modules
1. Reusable
2. Simple
3. Testable
Create before destroy
resource "google_compute_instance" "vm" {
name = "${var.environment}-${var.role}-${count.index}-${replace(var.code_version,".","-")}"
zone = element(var.zone, count.index)
deletion_protection = false
machine_type = var.machine_type
count = var.vm_count
project = var.project_name
lifecycle {
create_before_destroy = true
}
...
}
Dependency, triggers
resource "null_resource" "startupscript" {
count = "${var.vm_count}"
depends_on = [google_compute_instance.vm]
triggers = {
cluster_instance_ids = google_compute_instance.vm[count.index].instance_id
}
lifecycle {
create_before_destroy = true
}
}
Files structure
1. Separate persistent data
2. Separate networking
3. Global, mgmt and envs
Tests everything
1. From top to bottom (Automation QA tests, Integration, “Units”)
2. Use Terratest - https://github.com/gruntwork-io/terratest
3. Write tests in Golang
Terraform tests
package test
import (
"github.com/gruntwork-io/terratest/modules/terraform"
"testing"
)
func TestVmExample(t *testing.T) {
t.Parallel()
terraformOptions := &terraform.Options{
// You should update this relative path to point at your mysql
// example directory!
TerraformDir: "../modules/vm_test",
Vars: map[string]interface{}{
"environment": "test",
"region": "europe-north1",
"project_name": "learned-acolyte-221721",
"path_to_context": "/Users/sergii.marchenko/work/keys/gcp/Iegor-072a850167f3.json",
},
}
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
}
Releases without testing
Releases with IaC and tests
Tests, demo
Don’t stop
1. Use it for Resource Groups/Accounts
2. Use it for Data Structures (Keys)
While a yak is shaving, your business is losing
money
Don’t re-configure resources, create new!
Is it a silver bullet?
Immutability trade-off
1. Persistent data
2. Works in clouds, it’s hard to implement on hardware (NOT 100%)
Why NOT use Terraform
1. Immutable doesn't work in some cases
2. IaC is not cheap
3. Security is a pain in the ass
4. Terraform has weaknesses
a. Backend doesn't support interpolation
b. TF state contains secrets
c. Multiple issues
But, it still works for many cases
Resources:
Book: Terraform: Up & Running, 2nd edition
Course: https://learn.hashicorp.com/terraform
Video: https://www.youtube.com/watch?v=LVgP63BkhKQ
Some code to play with: https://github.com/s-
marchenko/GoWeb-PostgreSQL
My contacts:
Email: sergihire@gmail.com
Skype: sergihire
https://github.com/s-marchenko/GoWeb-PostgreSQL

Weitere ähnliche Inhalte

Was ist angesagt?

Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Carlos Sanchez
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and Agent
Ranjit Avasarala
 

Was ist angesagt? (20)

Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using docker
 
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
Infrastructure testing with Jenkins, Puppet and Vagrant - Agile Testing Days ...
 
Continuous Security
Continuous SecurityContinuous Security
Continuous Security
 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerRunning High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
 
Ansible not only for Dummies
Ansible not only for DummiesAnsible not only for Dummies
Ansible not only for Dummies
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
 
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and ChefScaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
Scaling Next-Generation Internet TV on AWS With Docker, Packer, and Chef
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Kubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of KubernetesKubernetes Boston — Custom High Availability of Kubernetes
Kubernetes Boston — Custom High Availability of Kubernetes
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Amazon EC2 Container Service in Action
Amazon EC2 Container Service in ActionAmazon EC2 Container Service in Action
Amazon EC2 Container Service in Action
 
Vagrant crash course
Vagrant crash courseVagrant crash course
Vagrant crash course
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 
About Node.js
About Node.jsAbout Node.js
About Node.js
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and Agent
 
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache MesosCI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 

Ähnlich wie IaC and Immutable Infrastructure with Terraform, Сергей Марченко

Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011
rob_dimarco
 
Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012
threepointone
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro
 

Ähnlich wie IaC and Immutable Infrastructure with Terraform, Сергей Марченко (20)

Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Puppet for Sys Admins
Puppet for Sys AdminsPuppet for Sys Admins
Puppet for Sys Admins
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011
 
Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)Building Hermetic Systems (without Docker)
Building Hermetic Systems (without Docker)
 
Continuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsContinuous Delivery: The Dirty Details
Continuous Delivery: The Dirty Details
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Node azure
Node azureNode azure
Node azure
 
Mist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache SparkMist - Serverless proxy to Apache Spark
Mist - Serverless proxy to Apache Spark
 
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
Data Summer Conf 2018, “Mist – Serverless proxy for Apache Spark (RUS)” — Vad...
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for Java
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012Amplify your stack - Jsfoo pune 2012
Amplify your stack - Jsfoo pune 2012
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 

Mehr von Sigma Software

Mehr von Sigma Software (20)

Fast is Best. Using .NET MinimalAPIs
Fast is Best. Using .NET MinimalAPIsFast is Best. Using .NET MinimalAPIs
Fast is Best. Using .NET MinimalAPIs
 
"Are you developing or declining? Don't become an IT-dinosaur"
"Are you developing or declining? Don't become an IT-dinosaur""Are you developing or declining? Don't become an IT-dinosaur"
"Are you developing or declining? Don't become an IT-dinosaur"
 
Michael Smolin, "Decrypting customer's cultural code"
Michael Smolin, "Decrypting customer's cultural code"Michael Smolin, "Decrypting customer's cultural code"
Michael Smolin, "Decrypting customer's cultural code"
 
Max Kunytsia, “Why is continuous product discovery better than continuous del...
Max Kunytsia, “Why is continuous product discovery better than continuous del...Max Kunytsia, “Why is continuous product discovery better than continuous del...
Max Kunytsia, “Why is continuous product discovery better than continuous del...
 
Marcelino Moreno, "Product Management Mindset"
Marcelino Moreno, "Product Management Mindset"Marcelino Moreno, "Product Management Mindset"
Marcelino Moreno, "Product Management Mindset"
 
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
 
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
 
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
 
Stoyan Atanasov “How crucial is the BA role in an IT Project"
Stoyan Atanasov “How crucial is the BA role in an IT Project"Stoyan Atanasov “How crucial is the BA role in an IT Project"
Stoyan Atanasov “How crucial is the BA role in an IT Project"
 
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
 
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
 
VOLVO x HACK SPRINT
VOLVO x HACK SPRINTVOLVO x HACK SPRINT
VOLVO x HACK SPRINT
 
Business digitalization trends and challenges
Business digitalization trends and challengesBusiness digitalization trends and challenges
Business digitalization trends and challenges
 
Дмитро Терещенко, "How to secure your application with Secure SDLC"
Дмитро Терещенко, "How to secure your application with Secure SDLC"Дмитро Терещенко, "How to secure your application with Secure SDLC"
Дмитро Терещенко, "How to secure your application with Secure SDLC"
 
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
 
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
 
Training solutions and content creation
Training solutions and content creationTraining solutions and content creation
Training solutions and content creation
 
False news - false truth: tips & tricks how to avoid them
False news - false truth: tips & tricks how to avoid themFalse news - false truth: tips & tricks how to avoid them
False news - false truth: tips & tricks how to avoid them
 
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
 
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

IaC and Immutable Infrastructure with Terraform, Сергей Марченко

  • 2. Sergii Marchenko Head of IT at Dev-Pro 10 years in IT Loves Terraform, and PowerShell :)) Knows a bit about DevOps Thinks he can write some code in Go Email: sergihire@gmail.com Skype: sergihire https://github.com/s-marchenko/GoWeb-PostgreSQL
  • 4. Spinning up a new server
  • 6. 1. Chief 2. Puppet 3. Ansible 4. Cloudformation 5. Terraform 6. Pulumi 7. Code (Java, Go, JS) IaC tools
  • 8. Mutable 1. Server Drifts (Provisioning at diff time, manual actions, random failures) 2. You don't know how to configure it once again (Snowflake Server) 3. Hard to support multiple identical servers (Dev/Stage/Prod, Blue-Green)
  • 10. 1. Don’t install new software 2. Don’t update servers 3. Don’t change configs 4. Don’t update code 5. Just one thing you can do with you infra - DELETE IT Immutable principles
  • 11. Software update? Build a new image, replace the old one. Config update? Build a new image, replace the old one. Deploy a new version of the code? Build a new image, replace the old one. Docker brings us immutable approach
  • 12.
  • 14. TF is good ● A master is not required ● An agent is not required ● Declarative ● There is a state in the state file ● SImple Configuration Language (HCL) ● TF plan ● Count ● Loops (For, if)
  • 15. TF is good ● TF is a kind of documentation ● Clear change management (version control) ● Reusable (dev, stg, prod) ● Not only for a small team, works for 10+ DevOps/SRE ● The best way to implement Immutable infrastructure approach ● Fast (hey, Ansible)
  • 17. Modules ● Modules ● Yes, modules ● One more time, modules ● Many modules
  • 18. Simple TF code resource "google_compute_disk" "default" { name = "test-disk" type = "pd-ssd" zone = "us-west1-b" image = "debian-8-jessie-v20170523" labels = { environment = "dev" }
  • 19. Module module "database" { source = "../database" environment = var.environment region = var.region whitelist = var.whitelist project_name = var.project_name }
  • 21. No manual actions! 1. No manual actions 2. No, you can't create a tiny resource manually 3. Yes, it matters 4. No, there are no exceptions to the rule 5. Yes, local-exec is better than manual actions
  • 22. Use a Vault for secrets 1. Hashi Vault 2. AWS KMS 3. Azure Key Vault
  • 23. Use modules 1. Reusable 2. Simple 3. Testable
  • 24. Create before destroy resource "google_compute_instance" "vm" { name = "${var.environment}-${var.role}-${count.index}-${replace(var.code_version,".","-")}" zone = element(var.zone, count.index) deletion_protection = false machine_type = var.machine_type count = var.vm_count project = var.project_name lifecycle { create_before_destroy = true } ... }
  • 25. Dependency, triggers resource "null_resource" "startupscript" { count = "${var.vm_count}" depends_on = [google_compute_instance.vm] triggers = { cluster_instance_ids = google_compute_instance.vm[count.index].instance_id } lifecycle { create_before_destroy = true } }
  • 26. Files structure 1. Separate persistent data 2. Separate networking 3. Global, mgmt and envs
  • 27. Tests everything 1. From top to bottom (Automation QA tests, Integration, “Units”) 2. Use Terratest - https://github.com/gruntwork-io/terratest 3. Write tests in Golang
  • 28. Terraform tests package test import ( "github.com/gruntwork-io/terratest/modules/terraform" "testing" ) func TestVmExample(t *testing.T) { t.Parallel() terraformOptions := &terraform.Options{ // You should update this relative path to point at your mysql // example directory! TerraformDir: "../modules/vm_test", Vars: map[string]interface{}{ "environment": "test", "region": "europe-north1", "project_name": "learned-acolyte-221721", "path_to_context": "/Users/sergii.marchenko/work/keys/gcp/Iegor-072a850167f3.json", }, } defer terraform.Destroy(t, terraformOptions) terraform.InitAndApply(t, terraformOptions) }
  • 30. Releases with IaC and tests
  • 32. Don’t stop 1. Use it for Resource Groups/Accounts 2. Use it for Data Structures (Keys)
  • 33. While a yak is shaving, your business is losing money Don’t re-configure resources, create new!
  • 34. Is it a silver bullet?
  • 35. Immutability trade-off 1. Persistent data 2. Works in clouds, it’s hard to implement on hardware (NOT 100%)
  • 36. Why NOT use Terraform 1. Immutable doesn't work in some cases 2. IaC is not cheap 3. Security is a pain in the ass 4. Terraform has weaknesses a. Backend doesn't support interpolation b. TF state contains secrets c. Multiple issues
  • 37. But, it still works for many cases
  • 38. Resources: Book: Terraform: Up & Running, 2nd edition Course: https://learn.hashicorp.com/terraform Video: https://www.youtube.com/watch?v=LVgP63BkhKQ Some code to play with: https://github.com/s- marchenko/GoWeb-PostgreSQL
  • 39. My contacts: Email: sergihire@gmail.com Skype: sergihire https://github.com/s-marchenko/GoWeb-PostgreSQL