SlideShare a Scribd company logo
1 of 26
Download to read offline
Evolution of Software Deployment
● Big, expensive mainframes with few owners
● Server rooms for many and data centers for few
● Data center colocation - first generation rent a server, still expensive
● Virtual machine, shared nodes
● Cloud providers eg. AWS and GCP
● Instead of managing hardware, tools become more software-based
● Now sysadmins are writing more software code ← Devops
Typical Cloud Setup
● Set up network
○ Virtual private cloud
○ Set up subnets and other networking tasks
○ Set up firewall rules
● Set up users and access
○ Users - real users and service accounts
○ Policies and access control
● Set up resources
○ Computation
○ Storage
○ Database
● Integrate
● Test
It’s time consuming and error prone
Infrastructure as Code (IaC)
● Scripts - IaC is nothing new, scripts provide some semi-automation. Scripts
actually work well in ad hoc contexts
● Server templating tools - Docker and Packer are good tools that enable us to
define unit deployments for applications
● Cluster orchestration tools - Today we deploy multiple apps and services
running on multiple resources. Kubernetes is a good way to orchestrate such
deployment, make efficient use of resources, and scale
● Resource provisioning tools - These tools like Terraform is great for creating
the actual resources for hosting the apps and services
Reference: Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
Heterogeneous Solutions
● Tools are designed for specifically for one of abstract layers
● They complement each other
● The diagram shows Docker, Kubernetes, and Terraform as IaC tools as a
fullstack for devops. But you can mix and match any other tools
● Use the right combination that serves your needs
● Use Terraform to manage multiple Cloud networks eg. AWS and GCP
● Use Terraform and Docker or Packer
○ Terraform a GKE cluster to deploy Docker containers
○ Terraform GCE instances to deploy Packer images
Today we focus on Terraform - a IaC tool for
provisioning Cloud resources
What is Terraform?
Reference: Terraform: Some Introduction
Benefits of Terraform
● Documentation - Codify the infrastructure as code. As least it’s much easier to
understand human-readable code
● Version control - Because the infrastructure is now code, you do versioning
allow you to quickly revert back to a specific version
● Automation - You can easily deploy the code using CI/CD or other tools
○ Faster - this is no longer a manual process
○ Safer - validations against your code: compile the code, check against
existing infrastructure state, code review, tests
● Reusability - Certain configurations, resources and repeatable provisioning
processes can be reused through your or external modules and plug-ins
GCP Connection
● Primary ways you interface with GCP
○ Admin console
○ gcloud CLI tool ← programmatic interface
○ GCP SDK ← programmatic interface
○ Terraform ← programmatic interface
● All programmatic interface requires gcloud setup
○ gcloud init - set up the project and other key configurations
○ gcloud auth - identify who you are and consequently your access
Terraform Code
● Terraform code is declarative - declare the state you desire in the
infrastructure and Terraform will figure it out how to get there
● Hence Terraform needs to know the current state. State management is a big
part of Terraform
● The Terraform constructs, here are the key ones:
○ Providers
○ Resources
○ Variables (local, input, output)
○ Expressions
○ Functions
○ Others - check out Terraform 0.12 language
// main.tf - a simple Terraform code
provider "google" {
region = var.region
project = var.project_id
}
resource "google_compute_instance" "web" {
name = "web"
machine_type = "n1-standard-1"
zone = "us-west1-a"
disk {
image = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602"
}
network_interface {
network = "default"
}
}
// variables.tf - inputs to the Terraform template
variable "region" {
description = "The region where the instance will be deployed."
type = string
default = "us-west1"
}
variable "region_zone" {
description = "The zone where the instance will be deployed."
type = string
default = "us-west1-a"
}
variable "project_id" {
description = "The ID of the GCP project."
type = string
}
// outputs.tf - outputs (state) after the resource has been deployed
// You can have a terraform.tfvars that contains all the input
// values
output "instance_id" {
description = "The unique identifier of the deployed instance."
type = string
value = google_compute_instance.web.instance_id
}
Terraform Commands
$ terraform init
$ terraform plan
$ terraform apply # Actual deployment to the Cloud
$ terraform destroy
You will see the following the following created:
- .terraform - downloaded dependencies eg. modules, providers
- *.tfstate - the current state of the infrastructure, basically a tree of the
resources
Demo
Let’s run the Terraform code
(might take a while)
See Github repository:
https://github.com/cybersamx/terraform-gke
Connect to your GCP and Start Terraforming
● Launch your shell
$ export PROJECT_ID='<YOUR_PROJECT_ID>'
$ gcloud auth revoke # Log out
$ gcloud init # Initialize with a project ID
$ gcloud auth login
$ # If the previous command doesn’t work try the following
$ gcloud auth application-default login
● Now you are now connected to GCP, you can run terraform with the right
access and authorization
● Go to the terraform project and the /dev folder and run the following
$ terraform init
$ terraform plan
$ terraform apply
GitOps
● Because Terraform is code, you can use existing workflows and tools for development
and release
● Leverage existing workflow and tools with slight variation
● Collaborate as much as possible yet isolate as possible
● Break the Terraform configuration into multiple sets of files
● Versioning - Use git to store your Terraform code
● Isolate your environments through directories
○ Folder: dev, staging, prod
○ Branch: dev, staging, master
○ Environment: dev, staging, prod
● Start off with dev, build, test, and if it passes the current env promote to the next env
● Each environment folder has its own sets of configurations
Reference: GitOps and Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
Terraform Project Layout
● dev
○ network
○ services
■ frontend-app
■ backend-app
● variables.tf
● outputs.tf
● Main.tf
○ data-storage
● staging
● prod
● global
● modules
Reference: Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
Let’s check the Terraform run and deploy
containers to the new k8s cluster
Deploying Containers to Cluster
● Now that we have set up a cluster and resources, let’s deploy an application
● We will be using a Hello World app example on Kubernetes home page
● First we need to set up kubectl for you to connect to the cluster
$ gcloud container clusters get-credentials dev-cluster --region us-west1
$ kubectl config current-context
$ gke_<PROJECT_ID>_us-west1_dev-cluster
$ # You should see the above output
$ # Query the cluster
$ kubectl get node
NAME READY UP-TO-DATE AVAILABLE AGE
Troubleshooting Tips
● Start off a project interactively, get the gcloud equivalent, and then Terraform
● Set TF_LOG=TRACE
● Remove .terraform directory (back it up first) and rerun terraform init
● Run terraform console to play around with expressions
Terraforming your Infrastructure on GCP

More Related Content

What's hot

Infrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleInfrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleDevOps Meetup Bern
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Waysmalltown
 
Google Cloud Platform (GCP)
Google Cloud Platform (GCP)Google Cloud Platform (GCP)
Google Cloud Platform (GCP)Chetan Sharma
 
Docker Swarm Introduction
Docker Swarm IntroductionDocker Swarm Introduction
Docker Swarm Introductionrajdeep
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformAdin Ermie
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & IntroductionLee Trout
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersYajushi Srivastava
 
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & Bitbucket
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & BitbucketVCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & Bitbucket
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & BitbucketMitchell Pronschinske
 
Kubernetes & Google Kubernetes Engine (GKE)
Kubernetes & Google Kubernetes Engine (GKE)Kubernetes & Google Kubernetes Engine (GKE)
Kubernetes & Google Kubernetes Engine (GKE)Akash Agrawal
 
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 TerraformDevOps.com
 
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)Adin Ermie
 

What's hot (20)

Terraform Basics
Terraform BasicsTerraform Basics
Terraform Basics
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Infrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleInfrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and Ansible
 
Docker & kubernetes
Docker & kubernetesDocker & kubernetes
Docker & kubernetes
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
Google Cloud Platform (GCP)
Google Cloud Platform (GCP)Google Cloud Platform (GCP)
Google Cloud Platform (GCP)
 
Terraform
TerraformTerraform
Terraform
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
Docker Swarm Introduction
Docker Swarm IntroductionDocker Swarm Introduction
Docker Swarm Introduction
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Introduce to Terraform
Introduce to TerraformIntroduce to Terraform
Introduce to Terraform
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & Introduction
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
 
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & Bitbucket
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & BitbucketVCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & Bitbucket
VCS + Terraform Cloud: Azure DevOps, GitLab, GitHub & Bitbucket
 
Kubernetes & Google Kubernetes Engine (GKE)
Kubernetes & Google Kubernetes Engine (GKE)Kubernetes & Google Kubernetes Engine (GKE)
Kubernetes & Google Kubernetes Engine (GKE)
 
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
 
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
 

Similar to Terraforming your Infrastructure on GCP

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.pdfssuser705051
 
Scaling terraform
Scaling terraformScaling terraform
Scaling terraformPaolo Tonin
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataInfluxData
 
DevEx | there’s no place like k3s
DevEx | there’s no place like k3sDevEx | there’s no place like k3s
DevEx | there’s no place like k3sHaggai Philip Zagury
 
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...Haggai Philip Zagury
 
Truemotion Adventures in Containerization
Truemotion Adventures in ContainerizationTruemotion Adventures in Containerization
Truemotion Adventures in ContainerizationRyan Hunter
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 
Best Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with DockerBest Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with DockerEric Smalling
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tipsSamuel Chow
 
The benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerThe benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerItai Yaffe
 
NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1Ruslan Meshenberg
 
Introduction to PaaS and Heroku
Introduction to PaaS and HerokuIntroduction to PaaS and Heroku
Introduction to PaaS and HerokuTapio Rautonen
 
Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflowmutt_data
 
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 Hung Lin
 
Making Service Deployments to AWS a breeze with Nova
Making Service Deployments to AWS a breeze with NovaMaking Service Deployments to AWS a breeze with Nova
Making Service Deployments to AWS a breeze with NovaGregor Heine
 
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 KaleidoKaleido
 

Similar to Terraforming your Infrastructure on GCP (20)

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
 
Scaling terraform
Scaling terraformScaling terraform
Scaling terraform
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxData
 
DevEx | there’s no place like k3s
DevEx | there’s no place like k3sDevEx | there’s no place like k3s
DevEx | there’s no place like k3s
 
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
 
Netty training
Netty trainingNetty training
Netty training
 
Netty training
Netty trainingNetty training
Netty training
 
Truemotion Adventures in Containerization
Truemotion Adventures in ContainerizationTruemotion Adventures in Containerization
Truemotion Adventures in Containerization
 
Introduction to IAC and Terraform
Introduction to IAC and Terraform Introduction to IAC and Terraform
Introduction to IAC and Terraform
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
Best Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with DockerBest Practices for Developing & Deploying Java Applications with Docker
Best Practices for Developing & Deploying Java Applications with Docker
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
The benefits of running Spark on your own Docker
The benefits of running Spark on your own DockerThe benefits of running Spark on your own Docker
The benefits of running Spark on your own Docker
 
NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1NetflixOSS Meetup season 3 episode 1
NetflixOSS Meetup season 3 episode 1
 
Introduction to PaaS and Heroku
Introduction to PaaS and HerokuIntroduction to PaaS and Heroku
Introduction to PaaS and Heroku
 
Introduction to Apache Airflow
Introduction to Apache AirflowIntroduction to Apache Airflow
Introduction to Apache Airflow
 
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
 
Making Service Deployments to AWS a breeze with Nova
Making Service Deployments to AWS a breeze with NovaMaking Service Deployments to AWS a breeze with Nova
Making Service Deployments to AWS a breeze with Nova
 
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
 

More from Samuel Chow

GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the Cloud
GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the CloudGCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the Cloud
GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the CloudSamuel Chow
 
Docker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google CloudDocker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google CloudSamuel Chow
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and MicroserviceSamuel Chow
 
UI Design - Lessons Learned, Principles, and Best Practices
UI Design - Lessons Learned, Principles, and Best PracticesUI Design - Lessons Learned, Principles, and Best Practices
UI Design - Lessons Learned, Principles, and Best PracticesSamuel Chow
 
Mobile Analytics
Mobile AnalyticsMobile Analytics
Mobile AnalyticsSamuel Chow
 
iOS Release Management
iOS Release ManagementiOS Release Management
iOS Release ManagementSamuel Chow
 
Frisbee Thrower Prototype
Frisbee Thrower PrototypeFrisbee Thrower Prototype
Frisbee Thrower PrototypeSamuel Chow
 
Frisbee Thrower Concepts (Part 1)
Frisbee Thrower Concepts (Part 1)Frisbee Thrower Concepts (Part 1)
Frisbee Thrower Concepts (Part 1)Samuel Chow
 

More from Samuel Chow (8)

GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the Cloud
GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the CloudGCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the Cloud
GCPLA Meetup Workshop - Migration from a Legacy Infrastructure to the Cloud
 
Docker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google CloudDocker, Kubernetes, and Google Cloud
Docker, Kubernetes, and Google Cloud
 
Docker and Microservice
Docker and MicroserviceDocker and Microservice
Docker and Microservice
 
UI Design - Lessons Learned, Principles, and Best Practices
UI Design - Lessons Learned, Principles, and Best PracticesUI Design - Lessons Learned, Principles, and Best Practices
UI Design - Lessons Learned, Principles, and Best Practices
 
Mobile Analytics
Mobile AnalyticsMobile Analytics
Mobile Analytics
 
iOS Release Management
iOS Release ManagementiOS Release Management
iOS Release Management
 
Frisbee Thrower Prototype
Frisbee Thrower PrototypeFrisbee Thrower Prototype
Frisbee Thrower Prototype
 
Frisbee Thrower Concepts (Part 1)
Frisbee Thrower Concepts (Part 1)Frisbee Thrower Concepts (Part 1)
Frisbee Thrower Concepts (Part 1)
 

Recently uploaded

%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 masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%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 Rustenburgmasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
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.pptxAnnaArtyushina1
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%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 tembisamasabamasaba
 
%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 Benonimasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
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...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
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...WSO2
 
%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 masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 

Recently uploaded (20)

%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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%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
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
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
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%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
 
%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
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
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...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
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...
 
%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
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

Terraforming your Infrastructure on GCP

  • 1.
  • 2. Evolution of Software Deployment ● Big, expensive mainframes with few owners ● Server rooms for many and data centers for few ● Data center colocation - first generation rent a server, still expensive ● Virtual machine, shared nodes ● Cloud providers eg. AWS and GCP ● Instead of managing hardware, tools become more software-based ● Now sysadmins are writing more software code ← Devops
  • 3. Typical Cloud Setup ● Set up network ○ Virtual private cloud ○ Set up subnets and other networking tasks ○ Set up firewall rules ● Set up users and access ○ Users - real users and service accounts ○ Policies and access control ● Set up resources ○ Computation ○ Storage ○ Database ● Integrate ● Test
  • 4. It’s time consuming and error prone
  • 5. Infrastructure as Code (IaC) ● Scripts - IaC is nothing new, scripts provide some semi-automation. Scripts actually work well in ad hoc contexts ● Server templating tools - Docker and Packer are good tools that enable us to define unit deployments for applications ● Cluster orchestration tools - Today we deploy multiple apps and services running on multiple resources. Kubernetes is a good way to orchestrate such deployment, make efficient use of resources, and scale ● Resource provisioning tools - These tools like Terraform is great for creating the actual resources for hosting the apps and services Reference: Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
  • 6.
  • 7. Heterogeneous Solutions ● Tools are designed for specifically for one of abstract layers ● They complement each other ● The diagram shows Docker, Kubernetes, and Terraform as IaC tools as a fullstack for devops. But you can mix and match any other tools ● Use the right combination that serves your needs ● Use Terraform to manage multiple Cloud networks eg. AWS and GCP ● Use Terraform and Docker or Packer ○ Terraform a GKE cluster to deploy Docker containers ○ Terraform GCE instances to deploy Packer images
  • 8. Today we focus on Terraform - a IaC tool for provisioning Cloud resources
  • 9. What is Terraform? Reference: Terraform: Some Introduction
  • 10. Benefits of Terraform ● Documentation - Codify the infrastructure as code. As least it’s much easier to understand human-readable code ● Version control - Because the infrastructure is now code, you do versioning allow you to quickly revert back to a specific version ● Automation - You can easily deploy the code using CI/CD or other tools ○ Faster - this is no longer a manual process ○ Safer - validations against your code: compile the code, check against existing infrastructure state, code review, tests ● Reusability - Certain configurations, resources and repeatable provisioning processes can be reused through your or external modules and plug-ins
  • 11. GCP Connection ● Primary ways you interface with GCP ○ Admin console ○ gcloud CLI tool ← programmatic interface ○ GCP SDK ← programmatic interface ○ Terraform ← programmatic interface ● All programmatic interface requires gcloud setup ○ gcloud init - set up the project and other key configurations ○ gcloud auth - identify who you are and consequently your access
  • 12. Terraform Code ● Terraform code is declarative - declare the state you desire in the infrastructure and Terraform will figure it out how to get there ● Hence Terraform needs to know the current state. State management is a big part of Terraform ● The Terraform constructs, here are the key ones: ○ Providers ○ Resources ○ Variables (local, input, output) ○ Expressions ○ Functions ○ Others - check out Terraform 0.12 language
  • 13.
  • 14. // main.tf - a simple Terraform code provider "google" { region = var.region project = var.project_id } resource "google_compute_instance" "web" { name = "web" machine_type = "n1-standard-1" zone = "us-west1-a" disk { image = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160602" } network_interface { network = "default" } }
  • 15. // variables.tf - inputs to the Terraform template variable "region" { description = "The region where the instance will be deployed." type = string default = "us-west1" } variable "region_zone" { description = "The zone where the instance will be deployed." type = string default = "us-west1-a" } variable "project_id" { description = "The ID of the GCP project." type = string }
  • 16. // outputs.tf - outputs (state) after the resource has been deployed // You can have a terraform.tfvars that contains all the input // values output "instance_id" { description = "The unique identifier of the deployed instance." type = string value = google_compute_instance.web.instance_id }
  • 17. Terraform Commands $ terraform init $ terraform plan $ terraform apply # Actual deployment to the Cloud $ terraform destroy You will see the following the following created: - .terraform - downloaded dependencies eg. modules, providers - *.tfstate - the current state of the infrastructure, basically a tree of the resources
  • 18. Demo
  • 19. Let’s run the Terraform code (might take a while) See Github repository: https://github.com/cybersamx/terraform-gke
  • 20. Connect to your GCP and Start Terraforming ● Launch your shell $ export PROJECT_ID='<YOUR_PROJECT_ID>' $ gcloud auth revoke # Log out $ gcloud init # Initialize with a project ID $ gcloud auth login $ # If the previous command doesn’t work try the following $ gcloud auth application-default login ● Now you are now connected to GCP, you can run terraform with the right access and authorization ● Go to the terraform project and the /dev folder and run the following $ terraform init $ terraform plan $ terraform apply
  • 21. GitOps ● Because Terraform is code, you can use existing workflows and tools for development and release ● Leverage existing workflow and tools with slight variation ● Collaborate as much as possible yet isolate as possible ● Break the Terraform configuration into multiple sets of files ● Versioning - Use git to store your Terraform code ● Isolate your environments through directories ○ Folder: dev, staging, prod ○ Branch: dev, staging, master ○ Environment: dev, staging, prod ● Start off with dev, build, test, and if it passes the current env promote to the next env ● Each environment folder has its own sets of configurations Reference: GitOps and Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
  • 22. Terraform Project Layout ● dev ○ network ○ services ■ frontend-app ■ backend-app ● variables.tf ● outputs.tf ● Main.tf ○ data-storage ● staging ● prod ● global ● modules Reference: Terraform: Up and Running, 2nd Ed. by Yevgeniy Brikman
  • 23. Let’s check the Terraform run and deploy containers to the new k8s cluster
  • 24. Deploying Containers to Cluster ● Now that we have set up a cluster and resources, let’s deploy an application ● We will be using a Hello World app example on Kubernetes home page ● First we need to set up kubectl for you to connect to the cluster $ gcloud container clusters get-credentials dev-cluster --region us-west1 $ kubectl config current-context $ gke_<PROJECT_ID>_us-west1_dev-cluster $ # You should see the above output $ # Query the cluster $ kubectl get node NAME READY UP-TO-DATE AVAILABLE AGE
  • 25. Troubleshooting Tips ● Start off a project interactively, get the gcloud equivalent, and then Terraform ● Set TF_LOG=TRACE ● Remove .terraform directory (back it up first) and rerun terraform init ● Run terraform console to play around with expressions