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:
- 1 x Virtual Private Cloud
- 3 x Security Groups
- 1 x Default
- 2 x Related to the Kubernetes Cluster (created by the Kubernetes Service creation)
- 1 x Access control list
- 1 x Routing table
- 1 x Virtual Private Endpoint Gateway (created by the Kubernetes Service creation)
- 1 x Public load balancer (created by the Kubernetes Service creation)
- 3 x Security Groups
- 1 x Kubernetes Cluster
- Including 3 fully IBM managed master nodes
- Configured 2 worker nodes (see IBM Cloud responsibilities)
- Enabled Block Storage for VPC
- Enabled service endpoint for public and private communication

Terraform variables overview
Name | Description | Type | Default Value |
---|---|---|---|
flavor | Default worker node flaver. Use ‘ibmcloud ks flavors –zone us-south-1’ to verify the availability. | String | bx2.4×16 |
worker_count | Default worker node count is set to 2. | Integer | 2 |
resource_group | IBM Cloud resource group name. | String | default |
vpc_name | The Virtual Private Cloud name. | String | operator-sample |
region | IBM Cloud region for the Kubernetes Cluster and the VPC | String | us-south |
kube_version | The tested Kubernetes Cluster version for the example is 1.23.8. | String | 1.23.8 |
cluster_name | Kubernetes Cluster Name running in VPC Gen2. | String | operator-sample-ks-cluster |
kubernetes_pricing | Kubernetes Cluster pricing. | String | tiered-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 https://github.com/thomassuedbroecker/terraform-vpc-kubernetes.git
cd terraform-vpc-kubernetes
Step 2: Verify the configuration of the variables.tf
file
nano variables.tf
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 IC_API_KEY=YOUR_IBM_CLOUD_ACCESS_KEY
export TF_LOG=debug
export REGION="us-south"
export GROUP="default"
Step 5: Execute the bash automation
Execute the create_vpc_kubernetes_cluster_with_terraform.sh bash script. The creation can take up to 2 hours, depending on the which region you are using and where you are located.
sh create_vpc_kubernetes_cluster_with_terraform.sh
Summary
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?
Greetings,
Thomas
#ibmcloud, #vpc, #schematics, #terraform, #kubernetes
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
LikeLike
Hi Reid,
thanks for your awesome feedback. Maybe you can check out the blog post with the related workshop for Code Engine:
https://suedbroecker.net/2021/05/28/new-hands-on-workshop-get-started-to-deploy-a-java-microservices-application-to-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.
Greetings,
Thomas
LikeLike