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. 


More from Cloud

IBM Cloud inactive identities: Ideas for automated processing

4 min read - Regular cleanup is part of all account administration and security best practices, not just for cloud environments. In our blog post on identifying inactive identities, we looked at the APIs offered by IBM Cloud Identity and Access Management (IAM) and how to utilize them to obtain details on IAM identities and API keys. Some readers provided feedback and asked on how to proceed and act on identified inactive identities. In response, we are going lay out possible steps to take.…

IBM Cloud VMware as a Service introduces multitenant as a new, cost-efficient consumption model

4 min read - Businesses often struggle with ongoing operational needs like monitoring, patching and maintenance of their VMware infrastructure or the added concerns over capacity management. At the same time, cost efficiency and control are very important. Not all workloads have identical needs and different business applications have variable requirements. For example, production applications and regulated workloads may require strong isolation, but development/testing, training environments, disaster recovery sites or other applications may have lower availability requirements or they can be ephemeral in nature,…

IBM accelerates enterprise AI for clients with new capabilities on IBM Z

5 min read - Today, we are excited to unveil a new suite of AI offerings for IBM Z that are designed to help clients improve business outcomes by speeding the implementation of enterprise AI on IBM Z across a wide variety of use cases and industries. We are bringing artificial intelligence (AI) to emerging use cases that our clients (like Swiss insurance provider La Mobilière) have begun exploring, such as enhancing the accuracy of insurance policy recommendations, increasing the accuracy and timeliness of…

IBM NS1 Connect: How IBM is delivering network connectivity with premium DNS offerings

4 min read - For most enterprises, how their users access applications and data is an essential part of doing business, and how they service those application and data responses has a direct correlation to revenue generation.    According to We Are Social’s Digital 2023 Global Overview Report, there are 5.19 billion people around the world using the internet in 2023. There’s an imperative need for businesses to trust their networks to deliver meaningful content to address customer needs.  So how responsive is the…