Terraform automation on IBM Cloud (#½): Provisioning a Kubernetes Cluster on IBM Cloud using Terraform

ibmcloud regions
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
resource_group = var.resource_group
region = var.ibmcloud_region
}

Variables

variable "ibmcloud_api_key" {}

variable "resource_group" {
default = "the_ressource_group_name"
}

variable "ibmcloud_region" {
default = "ibmcloud_reguin"
}

variable "cluster_name" {
description = "Name of the cluster"
type = string
default = "the_cluster_name"
}

variable "zone" {
default = "xxxxx"
}

variable "public_vlan_id" {
default = "xxxxxx"
}

variable "private_vlan_id" {
default = "xxxxxx"
}
ibmcloud ks vlan ls --zone <xxx>
ID        Name   Number   Type      Router
1519999 vlan 1355 private bcr02a.dal10
1519898 vlan 1357 private bcr02a.dal10
1518787 vlan 1252 public fcr02a.dal10
1518888 vlan 1254 public fcr02a.dal10

Versions file

terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.23.0"
}
}
}

Main Script


data "ibm_resource_group" "cluster_group" {
name = var.resource_group
}

resource ibm_container_cluster "xxxx" {
name = var.cluster_name
datacenter = var.zone
machine_type = "b3c.4x16"
hardware = "shared"
public_vlan_id = var.public_vlan_id
private_vlan_id = var.private_vlan_id

kube_version = "1.20.10"

default_pool_size = 2

public_service_endpoint = "true"
private_service_endpoint = "true"

resource_group_id = data.ibm_resource_group.cluster_group.id

}
    machine_type    = "b3c.4x16" 

kube_version = "1.20.10"

default_pool_size = 2
terraform init
terraform plan
terraform apply
terraform plan -target="ibm_container_cluster.xxx"
terraform apply -target="ibm_container_cluster.xxxx"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alain Airom (Ayrom)

Alain Airom (Ayrom)

196 Followers

IT guy for a long time, looking for technical challenges everyday!