Skip to main content

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 Networking as well as high-level ones, such as DNS entries and SaaS features. It basically talks to the API and gives it the configuration of desired state and the respective REST API of choice or provider does the work. It is written in a language called HCL (HashiCorp’s Configuration Language)

Fun-Fact: You can write a provider and make your own code for any resource that is backed by an API (maybe JSON, XML etc) even for Google Calender, Philps Hue Bulb.

Interesting Video

INEVITABLE DEVILS (INSTALLING AND SETTING UP) 

This essentially requires a Project, a Service Account and necessary Roles assigned to the one who administers or the one who has created this. Do check out the documentation of GCP for creating a project and a service account. Once created, download a JSON format key of the created service and save it safely and make sure it is handy to use.

Open the download section of Terraform’s official website and download the suitable version for your PC, set it up and add to the PATH. To avoid any confusion do check the link below for a detailed guide.


BASICS 

Once you have Terraform installed and ready, you need to just understand 3 steps to set your configuration running.

1. terraform init

2. terraform plan

3. terraform apply

            - terraform init: It scans through all the terraform files in the folder, lists out the providers, downloads the required ones and initializes or keeps them ready to talk to the API. That is a vital step in your process. It returns the provider version and is also alterable.


- terraform plan: Once you’re done with initializing, planning becomes important. Run the command terraform plan . Terraform will talk with API and gives you the list of things that are going to be added, changed or destroyed by this action or the updated file, provided, there are NO ERRORS found.


- terraform apply: This finally builds and applies the latest configurations of the desired state. VOILA, you have your infrastructure built in your provider.

Ending Note: This might not sound very interesting, but once you gain mastery over this basic process, you can use the same to operate on any provider of your choice.

Comments

Popular posts from this blog

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!...