Skip to main content

EXCEL TO GCP


 FROM EXCEL TO GOOGLE CLOUD PLATFORM

 

Introduction: 

    Tools are those which help us to ease our work. It can no more be called a great tool if the process of using it becomes harder or complicated. Since LANPAR (created in 1969), spreadsheets have been very useful to stack data and compute it easily. They became so popular that, now, apparently, it is a must! 

    It would turn out more interesting, if we used this simpler method of data acquisition to build infrastructure on GCP. Every cloud provider for that matter has an end left free for open-source developers to build tools in the form of REST-API. Python has a great capability of handling dictionaries and hence, JSON types. This can be exploited more to make it work for our easy use. 

    So, here is how I tried to make one such bundle of a package to create my VPC Networks, Subnets and Instances in it and also add Firewall rules to manage the traffic! 

 

Why python and how? 

    There is not a particular reason why I chose python, maybe because I know it well and I felt that it is capable of handling the JSON dictionaries. There are libraries for Python, R, Go, Ruby and many languages provided by GCP itself and here's what you need to know about it.

Python guide to GCP 

 

  

 We also have an option to read excel files/spreadsheets in Python using a library called pandas. This library (pandas) lets us read the spreadsheet and converts the whole document into something called a data-frame, in simpler words, makes it a table and every column can be treated as a list, hence giving us a dictionary, whose key is the head and value comprised of list of underneath values.

 

 

 

 

You can program it in such a way that, you can extract each value, and pass it on to API, and GCP with python will do rest of the work for you.


What does it take?

     Going through the python library provided by GCP, we get cleared of one thing. The library uses Google Cloud SDK for authorization and authentication. It is a must install CLI app in the system that work on, apart from Python itself. Click here to know how to install Google Cloud SDK in your PC. 

    Once the SDK gets installed, run

 'gcloud auth application-default login' 

command to initialize and set up credentials of your account inside the SDK, which will be then saved to be used later. It automatically updates the API request calls with the credentials. Later, you need not keep providing your credentials, every time you make your requests.

     After SDK, comes the Python libraries. You need to install google-api-client-library, in simpler words, run,

pip install --upgrade google-api-python-client
 in the terminal and 'pip' will do the work for you and get your job done! once installed. Then, one is capable of using the tool but, before, you need to enable the needed API. This can be done in console itself (the easy way). Open the tab of the resources that is desired to be used and click on Enable API is available. If you cannot find it, that means the API is already enabled.

 

 KEYS:     

     In the library google-api-python-client we use a subclass called discovery. First and foremost step, whenever we start, is to import this class. This class need to initialized in the following way.

  
 
Once this is done, the object compute now contains all the functions that can be used to create, change, list, delete any resources under that category. In GCP, we have several categories of APIs - namely, Compute Engine, Storage, Kubernetes etc.. Compute Engine can cover vast variety of subcategories such as Instances, Networks, Firewalls, etc.. (more can be seen here)

  

    Once our 'compute' carries all the methods, we can now build things over that. I would be writing a blog explaining each and every concepts about how to use such methods, for now you can click here for the documentation from GCP for creating instances using this client.

 

 

 Excel to Python:

 

    Till now we saw, how to get things to work from Python to GCP, now comes the other half from Excel (Spreadsheet) to Python. Once you have your Excel sheet ready, then we a library called Pandas to handle this file. Pandas takes the data from the file and converts it into a object called Dataframe. Making it a list of dictionaries, with the keys as the name of columns and the values being the enlisted data below. We shall use this feature to break down our requirements that will be given to functions as parameters.

 

 

Comments

Popular posts from this blog

Compute de Instances

  Lets get kick-started with creation of Compute Instances using Terraform. Note that you all ready have a project (that is linked with a billing account), a service account and keys of using that in JSON format. Spinning up an instance is very simple here. List out the configuration of the Instance that needs to be created and give them to TF in HCL language. Lets do a quick example. Configurtions of Desired Instance are as follows:   > Instance in South-Asia-1 (zone b) > Machine type is “f1-micro” which is a free-tier one > Image / OS should be Linux Debian 9 > Let the Subnet to be default > Make sure that it get updated as soon as you create it Now, Nothing can stop you from spinning it up but, how do you think Terraform would know where to do this? We haven’t told it Which provider it should create (GCP, AWS, Azure etc..), It doesn’t know, who are you (which can be found in key of service account. To Begin Create a file ...

T in Terraform

                    Lets do GCP using Terraform With the IT world moving towards cloud infrastructure, it has become very vital for everyone to keep pace in building, maintaining and even destroying infrastructure on any platform. Choosing the platform might be in the individual’s interest, but for this demo, let us start with Google Cloud Platform. T IN TERRAFORM   Terraform is a tool that helps the user in building, changing and versioning the infrastructure efficiently. It describes and manages the state of your infrastructure. With all the configurations and components of the infrastructure provided in a single package or a file, it takes care of attaining the desired state as defined in the Terraform file (.tf file)  Terraform is one of the best examples for IaaC (Infrastructure as a Code) skeleton. It is capable of handling both, low-level components, such as Compute Instances, Storage and Networkin...