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

New 4th Gen Intel Xeon profiles and dynamic network bandwidth shake up the IBM Cloud Bare Metal Servers for VPC portfolio

3 min read - We’re pleased to announce that 4th Gen Intel® Xeon® processors on IBM Cloud Bare Metal Servers for VPC are available on IBM Cloud. Our customers can now provision Intel’s newest microarchitecture inside their own virtual private cloud and gain access to a host of performance enhancements, including more core-to-memory ratios (21 new server profiles/) and dynamic network bandwidth exclusive to IBM Cloud VPC. For anyone keeping track, that’s 3x as many provisioning options than our current 2nd Gen Intel Xeon…

IBM and AWS: Driving the next-gen SAP transformation  

5 min read - SAP is the epicenter of business operations for companies around the world. In fact, 77% of the world’s transactional revenue touches an SAP system, and 92% of the Forbes Global 2000 companies use SAP, according to Frost & Sullivan.   Global challenges related to profitability, supply chains and sustainability are creating economic uncertainty for many companies. Modernizing SAP systems and embracing cloud environments like AWS can provide these companies with a real-time view of their business operations, fueling growth and increasing…

Experience unmatched data resilience with IBM Storage Defender and IBM Storage FlashSystem

3 min read - IBM Storage Defender is a purpose-built end-to-end data resilience solution designed to help businesses rapidly restart essential operations in the event of a cyberattack or other unforeseen events. It simplifies and orchestrates business recovery processes by providing a comprehensive view of data resilience and recoverability across primary and  auxiliary storage in a single interface. IBM Storage Defender deploys AI-powered sensors to quickly detect threats and anomalies. Signals from all available sensors are aggregated by IBM Storage Defender, whether they come…

IBM Newsletters

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