Use Terraform to create a VPC and a Kubernetes Cluster on IBM Cloud

This blog post contains a simple example to create a Virtual Private Cloud and a Kubernetes Cluster on IBM Cloud using Terraform. The example is based on following resources:

You can find a GitHub project with all the source code for Terraform and a bash automation here.

The blog post is structured in following sections:

  • Simplified architecture overview
  • Terraform variables overview
  • Prerequisites (for an automated bash setup)
  • Step by step example setup
  • Summary

Simplified architecture of overview

Here you can get an overview of the simplified architecture and the resources which will be created/configured on IBM Cloud:

Terraform variables overview

NameDescriptionTypeDefault Value
flavorDefault worker node flaver. Use ‘ibmcloud ks flavors –zone us-south-1’ to verify the availability.Stringbx2.4×16
worker_countDefault worker node count is set to 2.Integer2
resource_groupIBM Cloud resource group name.Stringdefault
vpc_nameThe Virtual Private Cloud name.Stringoperator-sample
regionIBM Cloud region for the Kubernetes Cluster and the VPCStringus-south
kube_versionThe tested Kubernetes Cluster version for the example is 1.23.8.String1.23.8
cluster_nameKubernetes Cluster Name running in VPC Gen2.Stringoperator-sample-ks-cluster
kubernetes_pricingKubernetes Cluster pricing.Stringtiered-pricing

Note: IBM Cloud on the Terraform registry.

Prerequisites for a local setup

To use an example bash automation following tools need to be installed on the local computer

  • IBM Cloud CLI
    • Plugin VPC infrastructure
    • Plugin Container-service
  • Terraform

Example setup

Here are the steps to use Terraform locally with a bash automation, but you can also use Schematics on IBM Cloud for the setup. Here is an older blog post I wrote which does cover an example how to use Schematics for creating a Red Hat OpenShift cluster. Just follow this link.

Step 1: Clone the repo

git clone
cd terraform-vpc-kubernetes

Step 2: Verify the configuration of the file


Step 3: Create a variables.env file

cat variables_template.env > variables.env

Step 4: Add an IBM Cloud access key to your local variables.env file

nano variables.env

Content of the file:

export TF_LOG=debug
export REGION="us-south"
export GROUP="default"

Step 5: Execute the bash automation

Execute the bash script. The creation can take up to 2 hours, depending on the which region you are using and where you are located.



I like using Terraform for infrastructure as code locally on my machine or using it with Schematics on IBM Cloud. With Schematics you have an easy overview of your created resources and you can directly navigate to you resources, update your resources or delete your resources. In the following image you see the resources created by the Terraform example when I was using Schematics:

There is a lot of useful documentation out there, so that you can achieve very fast an implementation with Terraform. In my case I used as a starting point these three very useful links:

I hope this was useful to you and let’s see what’s next?



#ibmcloud, #vpc, #schematics, #terraform, #kubernetes

4 thoughts on “Use Terraform to create a VPC and a Kubernetes Cluster on IBM Cloud

Add yours

  1. Hi Thomas,

    Nice blog post! I’m researching an approach for doing something similar to what you’ve done here. I had assumed your approach was the way to go. Recently, I’ve discovered IBM’s VPC API and was wondering how you think it might fit in to what you’re doing? Finally, IBM seems to have created something new called IBM Cloud code engine. Trying to figure out how to position it vs. Schematics / Terraform. You’re thoughts would be appreciated. Reid


    1. Hi Reid,

      thanks for your awesome feedback. Maybe you can check out the blog post with the related workshop for Code Engine: .

      Code Engine is a serverless platform and I would say not related to “Schematics / Terraform” which do handle infrastructure as code.

      I hope that helps a bit.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at

Up ↑

%d bloggers like this: