Managing Google Cloud using Infrastructure as Code (IaC)
GDG Cloud Lahore
The place for cloud developers to come together to learn, and explore the latest advances in cloud technologies.
Author: Adil Shahzad
Code Repository: https://github.com/GDGCloudLahore/GCP-Deployment-Manager-IaC.git
Infrastructure as Code
Infrastructure as Code (IaC) is a method used to manage and set up computer networks, servers, and other IT infrastructure through machine-readable files, rather than physical hardware configuration or interactive configuration tools. To understand it easily, think of it like building a model house using LEGO blocks. In traditional methods (like building a house by hand), you would manually place each brick. But with IaC, you create a blueprint or a plan that tells an automated system exactly how to build your model house. Whenever you want to build the house, you just use this plan, and the system automatically assembles the LEGO blocks as per your design.
This approach makes the entire process of managing IT infrastructure more efficient, consistent, and error-free. You can easily modify the plan if you want to change something (like adding a room to your model house), and the system will adjust everything accordingly. It's like updating your LEGO blueprint, and the model updates itself.
Understanding API
API stands for Application Programming Interface. Imagine an API as a menu in a restaurant. The menu provides a list of dishes you can order, along with a description of each dish. When you specify which dish you want, the kitchen (the system) prepares the dish and serves it to you (the user). In this analogy, the menu is the API, the order is the request, and the dish that is served to you is the response.
Now, when it comes to Google Cloud API, think of it as a specialized menu offered by a very advanced restaurant (Google Cloud). This restaurant offers a variety of dishes (services) like storing your data, running your website, or analyzing large amounts of information. Each dish/service is accessed through its part of the menu/API. So, when you ask for a specific service, like data storage, the Google Cloud kitchen works behind the scenes to provide you with that service.
In simpler terms, APIs allow different software programs to communicate with each other. Google Cloud API, in particular, lets your software access the various services offered by Google Cloud, like storing files, processing data, or even running complex algorithms.
Exploring Cloud Shell
Google Cloud Shell provides a convenient, ready-to-use command-line environment for interacting with Google Cloud services without the hassle of setting up and maintaining a separate computer or server for these tasks.
Managing Version Controlling using Git
Managing version control using Git is crucial for efficient collaboration in software development. Git allows multiple individuals to work on the same project without interfering with each other's changes. Here are the top git commands you can use , for more commands checkout here : Git Cheatsheet
1. git init
2. git status
3. git add
领英推荐
4. git commit
5. git push
6. git pull
GCP Deployment Manager
Google Cloud Deployment Manager is a tool that lets you manage your Google Cloud resources using a declarative format. Here is the overview of how to write a Deployment Manager template file.
Here is the sample YAML template for Deployment Manager to create a virtual machine.
resources:
- name: my-vm
type: compute.v1.instance
properties:
zone: us-central1-a
machineType: zones/us-central1-a/machineTypes/f1-micro
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: projects/debian-cloud/global/images/family/debian-9
networkInterfaces:
- network: global/networks/default
Hands-on Lab
First, access the Cloud Shell and ensure you have access to the project. Then, from the terminal, type the following command to clone the repository.
git clone https://github.com/GDGCloudLahore/GCP-Deployment-Manager-IaC.git
Next, navigate to the cloned folder. Now, add the following command. The Google Cloud Shell will ask you for authorization
gcloud deployment-manager deployments create my-vm-deployment --config vm-deployment.yaml
After receiving a successful creation message, you are now able to view the compute resource.
Conclusion
I hope you like this blog. We have many blogs in the pipeline that we are working on. You are welcome to contribute to our GitHub Repository if you have experience working with Deployment Manager. If you have any questions, please feel free to ask me on LinkedIn.