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.
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
Post a Comment