Terraform provider with Tanzu Mission Control gives operations teams the ability to be infrastructure agnostic and build a code pipeline that accommodates a variety of infrastructure back ends. With Terraform, you can attach any conformant Kubernetes cluster to Tanzu Mission Control, therefore providing increased DevOps velocity by offering an additional route to consistent deployments and management of Kubernetes. In this post, I will explain the steps to create workload cluster using Terraform on vSphere with Tanzu.
Pre reqs
For this demo, I have registered management cluster (vSphere with Tanzu) to TMC.
Install terraform
Install steps are given here, you can follow the same based on bootstrap machine:
Install steps for ubuntu
# Install HashiCorp's package repository
$ sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
# Add the HashiCorp GPG key
$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
# Add the official HashiCorp Linux repository
$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
# Update to add the repository, and install the Terraform CLI.
$ sudo apt-get update && sudo apt-get install terraform
Check Terraform Version:
terraform --version
Create a directory with name as terraform-demo:
# Create a directory
mkdir terraform-demo
cd terraform-demo
Create files with below content in directory terraform-demo and provide endpoint, vmw_cloud_api_token as shown in screenshot:
Create file (provider.tf) with below content in directory terraform-demo
// Tanzu Mission Control terraform provider initialization
terraform {
required_providers {
tanzu-mission-control = {
source = "vmware/tanzu-mission-control"
version = "1.0.1"
}
}
}
// Basic details needed to configure Tanzu Mission Control provider
provider "tanzu-mission-control" {
endpoint = "<org name>.tmc.cloud.vmware.com" // Required, provide the org name
vmw_cloud_api_token = "<APi Token>" // Required, provide the API Token
}
variable "SESSION_NAMESPACE" {}
endpoint and api token ref
Create file (create-cg.tf) with below content in directory terraform-demo
// Create cluster group
resource "tanzu-mission-control_cluster_group" "create_cluster_group" {
name = "${var.SESSION_NAMESPACE}-cg"
}
Create file (tkgs-create-cluster.tf) with below content in directory terraform-demo