SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
Managing GCP Projects
with Terraform
GDG DevFest Pisa 0.1
Giovanni Toraldo @gionn
cloudesire.com
About me
Giovanni Toraldo
Open Source Enthusiast, Java
coder, writer of the OpenNebula
book, lead developer &
co-founder at @Cloudesire,
shooting 2 euro coin at 36
meters with crossbow
2
Monetization & Brokering
Platform for immediate
SaaSification and automated
distribution of business
applications and services.
3
4
Infrastructure as code?
Design, implement, and deploy applications infrastructure with
known software best practices:
● Code versioning
● Code reuse (modularization/abstraction)
● Code sharing
In order to achieve:
● Repeatability
● Speed
● Reliability
5
Cloud services are
easy?
Complexity is
increasing
Composition is a
must
Velocity is the key
of success
6
7
What is Terraform?
Terraform is a tool for building, changing, and versioning
infrastructure safely and efficiently.
● Declarative approach
○ Infrastructure is described using a high-level configuration syntax
● Incremental changes
○ Automatically discover the steps required from current to desired
infrastructure state
● Execution plan
○ See what Terraform will do when you apply configuration
● Dependency graph
○ automatically decide the order in which action are executed
● Automation
8
What is NOT Terraform?
● Configuration management tool
○ You still need Puppet, Chef, Ansible to manage
software on VM
● Cloud abstraction layer
○ Doesn’t expose any API, just a CLI mean to be used
by humans
○ Doesn’t hide the inner characteristics of each cloud
provider via abstraction
● A solution to your lack of cloud knowledge
9
Use cases
● Manage production environments by ops
● Manage disposable test/qa environments by dev
● Multi-tier (complex) infrastructures
● Setup demo environments
● Multi-cloud deployment
10
Install Terraform
Terraform is distributed as a single
Go binary without external
dependencies.
Download, unpack, execute.
● cd /tmp
● wget <url>
● unzip <file> || tar xvf <file>
● sudo mv terraform /usr/local/bin
● sudo chmod +x
/usr/local/bin/terraform
11
Create a Google Cloud Platform account
12
Create a new Google Cloud project
13
Navigate to Compute Engine to activate
14
Create Service account key and download
15
Create a new project
Just create an empty folder with a file auth.tf:
// Configure the Google Cloud provider
provider "google" {
credentials = "${file("account.json")}"
project = "terraform-test-197317"
region = "europe-west1 "
}
And run:
$ terraform init
16
Initialize terraform project
And run:
$ terraform init
17
Apply changes to infrastructure
Plan command to evaluate changes
Apply command to modify infrastructure
18
Terraform project files structure
There isn’t any enforcement on how to arrange resources inside a
terraform project:
● All .tf files in the current folder are automatically sources and
merged together in memory
$ ls -la
total 108
drwxr-xr-x 4 gionn dev 4096 mar 8 15:47 .
drwxr-xr-x 3 gionn dev 4096 mar 7 18:03 ..
drwxr-xr-x 7 gionn dev 4096 mar 8 15:47 .git
drwxr-xr-x 3 gionn dev 4096 mar 7 18:22 .terraform
-rw-r--r-- 1 gionn dev 2333 mar 7 18:18 account.json
-rw-r--r-- 1 gionn dev 175 mar 7 18:19 auth.tf
-rw-r--r-- 1 gionn dev 406 mar 8 15:46 vm.tf
19
Create a new VM
20
Plan output
$ terraform plan
Refreshing Terraform state in-memory prior to
plan...
The refreshed state will be used to calculate
this plan, but will not be persisted to local
or remote state storage.
---------------------------------------------
An execution plan has been generated and is
shown below.
21
Plan output
+ create
Terraform will perform the following actions:
+ google_compute_instance.default
id: <computed>
boot_disk.0.initialize_params.0.image:
"debian-cloud/debian-8"
cpu_platform: <computed>
instance_id: <computed>
label_fingerprint: <computed>
machine_type: "n1-standard-1"
metadata.%: "1"
metadata.ssh-keys: "debian:ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDDnX70/3FB4j7UvewR3T...
22
Plan output
Plan: 1 to add, 0 to change, 0 to destroy.
-------------------------------------------------
-
Note: You didn't specify an "-out" parameter to
save this plan, so Terraform can't guarantee that
exactly these actions will be performed if
"terraform apply" is subsequently run.
23
Apply output
$ terraform apply
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:
+ google_compute_instance.default
24
Apply output
Summary of the actions to perform, waiting for confirmation
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described
above.
Only 'yes' will be accepted to approve.
Enter a value: ___
25
After an apply successful operation
State is persisted to terraform.tfstate:
26
27
terraform.tfstate
A state file is required in order to:
● Map managed resources to terraform resources
● Persist additional metadata
● Cache, useful for large infrastructures
JSON structure that can be modified (bugs happens) or inspected
(custom integrations).
State should be persistent and shared among developers.
28
Terraform.tfstate sharing and locking
For solo developers or small teams: just commit to GIT.
For bigger teams, tfstate locking is required.
Multiple backends supported:
● Google cloud storage
● S3
● Consul
● Etcd
● Terraform enterprise
29
Terraform.tfstate sample output
{
"version": 3,
"terraform_version": "0.11.3",
"serial": 2,
"lineage": "d495f1c0-3c8b-45c2-bda2-f40d28382f30",
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {
"google_compute_instance.default": {
"type": "google_compute_instance",
"depends_on": [],
"primary": {
"id": "test-vm",
"attributes": {
"attached_disk.#": "0",
"boot_disk.#": "1",
"boot_disk.0.auto_delete": "true",
"boot_disk.0.device_name": "persistent-disk-0",
"boot_disk.0.disk_encryption_key_raw": "",
"boot_disk.0.disk_encryption_key_sha256": "",
30
Terraform.tfstate: where is the IP address?
"network_interface.#": "1",
"network_interface.0.access_config.#": "1",
"network_interface.0.access_config.0.assigned_nat_ip":
"104.155.126.70",
"network_interface.0.access_config.0.nat_ip": "104.155.126.70",
"network_interface.0.address": "10.132.0.2",
"network_interface.0.alias_ip_range.#": "0",
"network_interface.0.name": "nic0",
"network_interface.0.network":
"https://www.googleapis.com/compute/v1/projects/terraform-test-19731
7/global/networks/default",
"network_interface.0.network_ip": "10.132.0.2",
"network_interface.0.subnetwork":
"https://www.googleapis.com/compute/v1/projects/terraform-test-19731
7/regions/europe-west1/subnetworks/default",
"network_interface.0.subnetwork_project":
"terraform-test-197317",
"project": "terraform-test-197317",
31
Automatically print VM ip address
Add to output.tf:
output "ip" {
value = "${google_compute_instance.default.
network_interface.0.access_config.0.nat_ip}"
}
And run terraform apply:
Outputs:
ip = 104.155.126.70
32
Change infrastructure example: VM upscale
Just change the terraform attribute machine_type
(and configure allow_stopping_for_update)
Now, when terraform apply is run, terraform discover that the
machine_type of the existing resource doesn’t correspond to the
desiderata.
33
34
35
Attach a new data disk
We’ll create a new data disk resource, and reference it insiude the
instance resource.
36
37
38
39
40
Manage multiple instances with disks
● Define a variable resource
○ Set a default
● Define unique resource names to avoid conflicts
○ Leverage count.index variable
● Reference a difference disk for each instance
○ Use count.index variable as disk reference
● Override variable value via environment variable
○ TF_VAR_my_counter
41
42
github.com/
gionn/terraform-example
Questions?
43

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
 
Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.
 
Infrastructure as Code in Google Cloud
Infrastructure as Code in Google CloudInfrastructure as Code in Google Cloud
Infrastructure as Code in Google Cloud
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 
Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
 
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
Mixing Metrics and Logs with Grafana + Influx by David Kaltschmidt, Director ...
 
Terraform
TerraformTerraform
Terraform
 
Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018
 
Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflow
 
Helm – The package manager for Kubernetes
Helm – The package manager for KubernetesHelm – The package manager for Kubernetes
Helm – The package manager for Kubernetes
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
 
Scaling i/o bound Microservices
Scaling i/o bound MicroservicesScaling i/o bound Microservices
Scaling i/o bound Microservices
 
Terraforming the Kubernetes Land
Terraforming the Kubernetes LandTerraforming the Kubernetes Land
Terraforming the Kubernetes Land
 
Terraform 101
Terraform 101Terraform 101
Terraform 101
 
Terraform – Infrastructure as Code (Kielux'18)
Terraform – Infrastructure as Code (Kielux'18)Terraform – Infrastructure as Code (Kielux'18)
Terraform – Infrastructure as Code (Kielux'18)
 
Apache Airflow at Dailymotion
Apache Airflow at DailymotionApache Airflow at Dailymotion
Apache Airflow at Dailymotion
 
20180503 kube con eu kubernetes metrics deep dive
20180503 kube con eu   kubernetes metrics deep dive20180503 kube con eu   kubernetes metrics deep dive
20180503 kube con eu kubernetes metrics deep dive
 
InfluxDB & Kubernetes
InfluxDB & KubernetesInfluxDB & Kubernetes
InfluxDB & Kubernetes
 
Helm intro
Helm introHelm intro
Helm intro
 

Ähnlich wie Managing GCP Projects with Terraform (devfest Pisa 2018)

Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 

Ähnlich wie Managing GCP Projects with Terraform (devfest Pisa 2018) (20)

Self-service PR-based Terraform
Self-service PR-based TerraformSelf-service PR-based Terraform
Self-service PR-based Terraform
 
Meetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaCMeetup 2020 - Back to the Basics part 101 : IaC
Meetup 2020 - Back to the Basics part 101 : IaC
 
Git ops & Continuous Infrastructure with terra*
Git ops  & Continuous Infrastructure with terra*Git ops  & Continuous Infrastructure with terra*
Git ops & Continuous Infrastructure with terra*
 
Configuration management II - Terraform
Configuration management II - TerraformConfiguration management II - Terraform
Configuration management II - Terraform
 
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
GDG Cloud Southlake #8  Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...GDG Cloud Southlake #8  Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
 
Webinar: Enterprise Blockchain Radically Simplified with Truffle and Kaleido
Webinar: Enterprise Blockchain Radically Simplified with Truffle and KaleidoWebinar: Enterprise Blockchain Radically Simplified with Truffle and Kaleido
Webinar: Enterprise Blockchain Radically Simplified with Truffle and Kaleido
 
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
Terraform in production - experiences, best practices and deep dive- Piotr Ki...Terraform in production - experiences, best practices and deep dive- Piotr Ki...
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
 
Scaling terraform
Scaling terraformScaling terraform
Scaling terraform
 
Docker meetup - PaaS interoperability
Docker meetup - PaaS interoperabilityDocker meetup - PaaS interoperability
Docker meetup - PaaS interoperability
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
 
Terraform-2.pdf
Terraform-2.pdfTerraform-2.pdf
Terraform-2.pdf
 
A case study why Zoominfo uses Terraform Cloud in high-scale environment.
A case study why Zoominfo uses Terraform Cloud in high-scale environment. A case study why Zoominfo uses Terraform Cloud in high-scale environment.
A case study why Zoominfo uses Terraform Cloud in high-scale environment.
 
20221130 - Luxembourg HUG Meetup
20221130 - Luxembourg HUG Meetup20221130 - Luxembourg HUG Meetup
20221130 - Luxembourg HUG Meetup
 
Best Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformBest Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with Terraform
 
[scala.by] Launching new application fast
[scala.by] Launching new application fast[scala.by] Launching new application fast
[scala.by] Launching new application fast
 
Free GitOps Workshop
Free GitOps WorkshopFree GitOps Workshop
Free GitOps Workshop
 
Cloud Foundry Roadmap Update - OSCON - May 2017
Cloud Foundry Roadmap Update - OSCON - May 2017Cloud Foundry Roadmap Update - OSCON - May 2017
Cloud Foundry Roadmap Update - OSCON - May 2017
 
6 Months Sailing with Docker in Production
6 Months Sailing with Docker in Production 6 Months Sailing with Docker in Production
6 Months Sailing with Docker in Production
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
 
Apache Flink Deep Dive
Apache Flink Deep DiveApache Flink Deep Dive
Apache Flink Deep Dive
 

Mehr von Giovanni Toraldo

Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Giovanni Toraldo
 
Docker in production service discovery with consul - road to opscon 2015
Docker in production  service discovery with consul - road to opscon 2015Docker in production  service discovery with consul - road to opscon 2015
Docker in production service discovery with consul - road to opscon 2015
Giovanni Toraldo
 
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
Giovanni Toraldo
 
An introduction to cloud computing
An introduction to cloud computingAn introduction to cloud computing
An introduction to cloud computing
Giovanni Toraldo
 

Mehr von Giovanni Toraldo (15)

About code review and BUGS
About code review and BUGSAbout code review and BUGS
About code review and BUGS
 
Introduction to Traefik
Introduction to TraefikIntroduction to Traefik
Introduction to Traefik
 
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
 
Software Delivery in 2016 - A Continuous Delivery Approach
Software Delivery in 2016 - A Continuous Delivery ApproachSoftware Delivery in 2016 - A Continuous Delivery Approach
Software Delivery in 2016 - A Continuous Delivery Approach
 
From zero to Docker
From zero to DockerFrom zero to Docker
From zero to Docker
 
Clustering with Docker Swarm - Dockerops 2016 @ Cento (FE) Italy
Clustering with Docker Swarm - Dockerops 2016 @ Cento (FE) ItalyClustering with Docker Swarm - Dockerops 2016 @ Cento (FE) Italy
Clustering with Docker Swarm - Dockerops 2016 @ Cento (FE) Italy
 
Docker in production service discovery with consul - road to opscon 2015
Docker in production  service discovery with consul - road to opscon 2015Docker in production  service discovery with consul - road to opscon 2015
Docker in production service discovery with consul - road to opscon 2015
 
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps ItaliaWhen Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
When Docker ends, Chef begins ~ #idi2015 Incontro DevOps Italia
 
Easy applications deployment on OpenStack clouds
Easy applications deployment on OpenStack cloudsEasy applications deployment on OpenStack clouds
Easy applications deployment on OpenStack clouds
 
Introduction to Continuous Delivery
Introduction to Continuous DeliveryIntroduction to Continuous Delivery
Introduction to Continuous Delivery
 
ClouDesire @ Italian DevOps Initiative 2013 #idi2013
ClouDesire @ Italian DevOps Initiative 2013 #idi2013ClouDesire @ Italian DevOps Initiative 2013 #idi2013
ClouDesire @ Italian DevOps Initiative 2013 #idi2013
 
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
Cloud Computing in practice with OpenNebula ~ Develer workshop 2012
 
An introduction to cloud computing
An introduction to cloud computingAn introduction to cloud computing
An introduction to cloud computing
 
EVA Florence 2012 ~ Open low-cost HA cluster cloud
EVA Florence 2012 ~ Open low-cost HA cluster cloudEVA Florence 2012 ~ Open low-cost HA cluster cloud
EVA Florence 2012 ~ Open low-cost HA cluster cloud
 
Open@BNCF
Open@BNCFOpen@BNCF
Open@BNCF
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Kürzlich hochgeladen (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 

Managing GCP Projects with Terraform (devfest Pisa 2018)

  • 1. Managing GCP Projects with Terraform GDG DevFest Pisa 0.1 Giovanni Toraldo @gionn cloudesire.com
  • 2. About me Giovanni Toraldo Open Source Enthusiast, Java coder, writer of the OpenNebula book, lead developer & co-founder at @Cloudesire, shooting 2 euro coin at 36 meters with crossbow 2
  • 3. Monetization & Brokering Platform for immediate SaaSification and automated distribution of business applications and services. 3
  • 4. 4
  • 5. Infrastructure as code? Design, implement, and deploy applications infrastructure with known software best practices: ● Code versioning ● Code reuse (modularization/abstraction) ● Code sharing In order to achieve: ● Repeatability ● Speed ● Reliability 5
  • 6. Cloud services are easy? Complexity is increasing Composition is a must Velocity is the key of success 6
  • 7. 7
  • 8. What is Terraform? Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. ● Declarative approach ○ Infrastructure is described using a high-level configuration syntax ● Incremental changes ○ Automatically discover the steps required from current to desired infrastructure state ● Execution plan ○ See what Terraform will do when you apply configuration ● Dependency graph ○ automatically decide the order in which action are executed ● Automation 8
  • 9. What is NOT Terraform? ● Configuration management tool ○ You still need Puppet, Chef, Ansible to manage software on VM ● Cloud abstraction layer ○ Doesn’t expose any API, just a CLI mean to be used by humans ○ Doesn’t hide the inner characteristics of each cloud provider via abstraction ● A solution to your lack of cloud knowledge 9
  • 10. Use cases ● Manage production environments by ops ● Manage disposable test/qa environments by dev ● Multi-tier (complex) infrastructures ● Setup demo environments ● Multi-cloud deployment 10
  • 11. Install Terraform Terraform is distributed as a single Go binary without external dependencies. Download, unpack, execute. ● cd /tmp ● wget <url> ● unzip <file> || tar xvf <file> ● sudo mv terraform /usr/local/bin ● sudo chmod +x /usr/local/bin/terraform 11
  • 12. Create a Google Cloud Platform account 12
  • 13. Create a new Google Cloud project 13
  • 14. Navigate to Compute Engine to activate 14
  • 15. Create Service account key and download 15
  • 16. Create a new project Just create an empty folder with a file auth.tf: // Configure the Google Cloud provider provider "google" { credentials = "${file("account.json")}" project = "terraform-test-197317" region = "europe-west1 " } And run: $ terraform init 16
  • 17. Initialize terraform project And run: $ terraform init 17
  • 18. Apply changes to infrastructure Plan command to evaluate changes Apply command to modify infrastructure 18
  • 19. Terraform project files structure There isn’t any enforcement on how to arrange resources inside a terraform project: ● All .tf files in the current folder are automatically sources and merged together in memory $ ls -la total 108 drwxr-xr-x 4 gionn dev 4096 mar 8 15:47 . drwxr-xr-x 3 gionn dev 4096 mar 7 18:03 .. drwxr-xr-x 7 gionn dev 4096 mar 8 15:47 .git drwxr-xr-x 3 gionn dev 4096 mar 7 18:22 .terraform -rw-r--r-- 1 gionn dev 2333 mar 7 18:18 account.json -rw-r--r-- 1 gionn dev 175 mar 7 18:19 auth.tf -rw-r--r-- 1 gionn dev 406 mar 8 15:46 vm.tf 19
  • 20. Create a new VM 20
  • 21. Plan output $ terraform plan Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. --------------------------------------------- An execution plan has been generated and is shown below. 21
  • 22. Plan output + create Terraform will perform the following actions: + google_compute_instance.default id: <computed> boot_disk.0.initialize_params.0.image: "debian-cloud/debian-8" cpu_platform: <computed> instance_id: <computed> label_fingerprint: <computed> machine_type: "n1-standard-1" metadata.%: "1" metadata.ssh-keys: "debian:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDnX70/3FB4j7UvewR3T... 22
  • 23. Plan output Plan: 1 to add, 0 to change, 0 to destroy. ------------------------------------------------- - Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. 23
  • 24. Apply output $ terraform apply 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: + google_compute_instance.default 24
  • 25. Apply output Summary of the actions to perform, waiting for confirmation Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: ___ 25
  • 26. After an apply successful operation State is persisted to terraform.tfstate: 26
  • 27. 27
  • 28. terraform.tfstate A state file is required in order to: ● Map managed resources to terraform resources ● Persist additional metadata ● Cache, useful for large infrastructures JSON structure that can be modified (bugs happens) or inspected (custom integrations). State should be persistent and shared among developers. 28
  • 29. Terraform.tfstate sharing and locking For solo developers or small teams: just commit to GIT. For bigger teams, tfstate locking is required. Multiple backends supported: ● Google cloud storage ● S3 ● Consul ● Etcd ● Terraform enterprise 29
  • 30. Terraform.tfstate sample output { "version": 3, "terraform_version": "0.11.3", "serial": 2, "lineage": "d495f1c0-3c8b-45c2-bda2-f40d28382f30", "modules": [ { "path": [ "root" ], "outputs": {}, "resources": { "google_compute_instance.default": { "type": "google_compute_instance", "depends_on": [], "primary": { "id": "test-vm", "attributes": { "attached_disk.#": "0", "boot_disk.#": "1", "boot_disk.0.auto_delete": "true", "boot_disk.0.device_name": "persistent-disk-0", "boot_disk.0.disk_encryption_key_raw": "", "boot_disk.0.disk_encryption_key_sha256": "", 30
  • 31. Terraform.tfstate: where is the IP address? "network_interface.#": "1", "network_interface.0.access_config.#": "1", "network_interface.0.access_config.0.assigned_nat_ip": "104.155.126.70", "network_interface.0.access_config.0.nat_ip": "104.155.126.70", "network_interface.0.address": "10.132.0.2", "network_interface.0.alias_ip_range.#": "0", "network_interface.0.name": "nic0", "network_interface.0.network": "https://www.googleapis.com/compute/v1/projects/terraform-test-19731 7/global/networks/default", "network_interface.0.network_ip": "10.132.0.2", "network_interface.0.subnetwork": "https://www.googleapis.com/compute/v1/projects/terraform-test-19731 7/regions/europe-west1/subnetworks/default", "network_interface.0.subnetwork_project": "terraform-test-197317", "project": "terraform-test-197317", 31
  • 32. Automatically print VM ip address Add to output.tf: output "ip" { value = "${google_compute_instance.default. network_interface.0.access_config.0.nat_ip}" } And run terraform apply: Outputs: ip = 104.155.126.70 32
  • 33. Change infrastructure example: VM upscale Just change the terraform attribute machine_type (and configure allow_stopping_for_update) Now, when terraform apply is run, terraform discover that the machine_type of the existing resource doesn’t correspond to the desiderata. 33
  • 34. 34
  • 35. 35
  • 36. Attach a new data disk We’ll create a new data disk resource, and reference it insiude the instance resource. 36
  • 37. 37
  • 38. 38
  • 39. 39
  • 40. 40 Manage multiple instances with disks ● Define a variable resource ○ Set a default ● Define unique resource names to avoid conflicts ○ Leverage count.index variable ● Reference a difference disk for each instance ○ Use count.index variable as disk reference ● Override variable value via environment variable ○ TF_VAR_my_counter
  • 41. 41