November 7, 2019 By Sai Vennam 4 min read

Every developer should automate their infrastructure—here’s why.

Imagine you want to start writing an application on Kubernetes. You go to your favorite cloud, spin up a cluster, choose all the config options you need. Over the next few weeks, you iteratively develop your application and add more pieces to the puzzle, like third-party service integrations and a database. After a while, you decide it’s time to move this into production.

You know the best approach is to create a new production environment and keep “dev” separate. Although your code has changed drastically, its history is neatly kept in GitHub—no issues there. But what about your Kubernetes cluster, attached databases, service integrations, and volume claims? Are you certain that you can recreate the state of your dev environment’s infrastructure?

Here’s where Infrastructure as Code (IaC) comes in—it allows you to codify your cloud environments so you can automate provisioning of your infrastructure. To learn more about IaC, check out my video below, and if you want to get hands-on with, keep scrolling down.

IBM Cloud Schematics (Terraform-as-a-Service)

IBM Cloud Schematics is IBM’s cloud automation tool. The best thing about it? It’s based entirely on open source Terraform! See the blog post “IBM Cloud Schematics: Enabling Infrastructure as Code” for more info on the offering.

Today, let’s deploy a simple Kubernetes cluster on IBM Cloud using Schematics.

Navigate to the Schematics Dashboard and click Create a workspace.

Choose a name for your workspace, and input the GitHub repository URL: https://github.com/svennam92/ibmcloud-terraform

Note: You could also fork this if you want your own repo.

When you hit Retrieve input variables, it’ll pull the Terraform files from GitHub and you’ll see a list of configurable variables. As you input these variables, let’s break down the main.tf Terraform file that Schematics is using to automate the infrastructure.

Using the IBM Cloud provider for Terraform

The first thing in the main.tf Terraform file is the provider setting for using IBM Cloud:

provider "ibm" {
  ibmcloud_api_key = "${var.ibmcloud_api_key}"
}

As part of this, you’ll need to configure the API key that Terraform will use to authenticate with IBM Cloud. Create an API key using the API Keys dashboard and copy it into your Schematics workspace creation.

For each Terraform variable, Schematics allows you to configure it directly in the creation flow.

Next, you’ll need to configure the Kubernetes cluster resource you’re creating. The following is the basic required resource config:

# The Kubernetes Cluster Resource
resource "ibm_container_cluster" "cluster" {
  name              = "${var.cluster_name}"
  datacenter        = "${var.datacenter}"
  hardware          = "${var.hardware}"
  default_pool_size = "${var.poolsize}"
  machine_type      = "${var.machine_type}"
  public_vlan_id    = "${var.public_vlan_id}"
  private_vlan_id   = "${var.private_vlan_id}"
  kube_version      = "${var.kube_version}"
}

Defaults are available for most fields, but you will need to manually configure the VLANs.

Note: If you’ve never created a cluster before, these VLANs are created for you, and you can simply input null.

Once completed, it should look something like this:

To customize most of these fields, you may want help from the CLI. Download the IBM Cloud CLI here.

Finally, hit Create to provision the Schematics workspace.

Navigating IBM Cloud Schematics

Schematics allows you to fully manage your Terraform-based infrastructure automation. This includes making changes to the configuration, getting the latest Terraform config from GitHub, tracking provisioned resources, and finding resources to get started. Joining our Slack is a great way to have your questions answered or raise any issues:

With Terraform, there’s a “planning” stage before you start provisioning your infrastructure. This lets you ensure all the knobs are in the right position before launching. To do so, hit Generate Plan:

Verify the logs:

Once you’ve verified the infrastructure that will be provisioned, hit Apply Plan. It generally takes around 20 minutes while your cluster is being provisioned and set-up:

That’s it! What’s next?

Once completed, you can access your Kubernetes cluster directly from your Schematics workspace or by navigating to your IBM Cloud Kubernetes Dashboard. You’ve successfully “codified” and automated the creation of a simple Kubernetes cluster. 

But, we’re really just scratching the surface for using Terraform in Schematics. Stay tuned for more content where I’ll show how to set up networking, service creation/binding, VPCs, and more. 

Was this article helpful?
YesNo

More from Cloud

Enhance your data security posture with a no-code approach to application-level encryption

4 min read - Data is the lifeblood of every organization. As your organization’s data footprint expands across the clouds and between your own business lines to drive value, it is essential to secure data at all stages of the cloud adoption and throughout the data lifecycle. While there are different mechanisms available to encrypt data throughout its lifecycle (in transit, at rest and in use), application-level encryption (ALE) provides an additional layer of protection by encrypting data at its source. ALE can enhance…

Attention new clients: exciting financial incentives for VMware Cloud Foundation on IBM Cloud

4 min read - New client specials: Get up to 50% off when you commit to a 1- or 3-year term contract on new VCF-as-a-Service offerings, plus an additional value of up to USD 200K in credits through 30 June 2025 when you migrate your VMware workloads to IBM Cloud®.1 Low starting prices: On-demand VCF-as-a-Service deployments begin under USD 200 per month.2 The IBM Cloud benefit: See the potential for a 201%3 return on investment (ROI) over 3 years with reduced downtime, cost and…

The history of the central processing unit (CPU)

10 min read - The central processing unit (CPU) is the computer’s brain. It handles the assignment and processing of tasks, in addition to functions that make a computer run. There’s no way to overstate the importance of the CPU to computing. Virtually all computer systems contain, at the least, some type of basic CPU. Regardless of whether they’re used in personal computers (PCs), laptops, tablets, smartphones or even in supercomputers whose output is so strong it must be measured in floating-point operations per…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters