/terraform-provider-kind

Terraform Provider for kind (Kubernetes IN Docker)

Primary LanguageGoApache License 2.0Apache-2.0

Terraform Provider for kind

Overview

The Terraform Provider for kind enables Terraform to provision local Kubernetes clusters on base of Kubernetes IN Docker (kind).

Prerequisites

Development

Perform the following steps to build the providers:

  1. Build the provider:

    go build -o terraform-provider-kind
  2. Move the provider binary into the terraform plugins folder.

    NOTE: For details on Terraform plugins see this document.

Usage

Perform the following steps to use the provider:

  1. Go to the provider example folder:
    cd examples
  2. Edit the main.tf file and provide the following kind configuration:
provider "kind" {}

# creating a cluster with kind of the name "test-cluster" with kubernetes version hardcoded in kind defaults https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/defaults/image.go#L21
resource "kind" "my-cluster" {
    name = "test-cluster"
}

To override the node image used, you can specify the node_image like so:

provider "kind" {}

# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.16.1
resource "kind" "my-cluster" {
    name = "test-cluster"
    node_image = "kindest/node:v1.16.1"
}

To override the default kind config, you can specify the kind_config with HEREDOC:

provider "kind" {}

# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.15.7 and two nodes
resource "kind" "my-cluster" {
    name = "test-cluster"
    node_image = "kindest/node:v1.15.7"
    kind_config =<<KIONF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
KIONF
}
  1. Initialize Terraform:
    terraform init
  2. Plan the provisioning:
    terraform plan
  3. Deploy the cluster:
    terraform apply