Skip to content

Commit

Permalink
add kind for local setup (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MChorfa committed Nov 24, 2021
1 parent 967b470 commit c1f30cd
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- [Multi-Cloud Kubernetes](#multi-cloud-kubernetes)
- [Table of Contents](#table-of-contents)
- [Workflows](#workflows)
- [Cluster Workflows](#cluster-workflows)
- [Workload Workflows](#workload-workflows)
- [Other Workflows](#other-workflows)
- [Author Information](#author-information)
- [License](#license)

Expand All @@ -20,6 +23,7 @@ The code in this repository is split out into a handful of distinct workflows, e
* `./clusters/eks` contains code for AWS EKS Clusters
* `./clusters/doks` contains code for Digital Ocean Kubernetes Clusters
* `./clusters/gke` contains code for Google Cloud GKE Clusters
* `./clusters/kind` contains code for Kubernetes in Docker (kind) Clusters

### Workload Workflows

Expand Down
13 changes: 13 additions & 0 deletions clusters/kind/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions clusters/kind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Workspace `kind`

> This directory contains [kind Provider](https://registry.terraform.io/providers/kyma-incubator/kind/latest) Resources.
## Requirements

* Terraform CLI `1.0.9` or newer
* ```
## Downstream Consumption
The Kubernetes Cluster can be consumed via the [attributes reference](https://registry.terraform.io/providers/kyma-incubator/kind/latest/docs/resources/cluster#attributes-reference):
```hcl
output "cluster_config" {
description = "Kind Cluster Config."
value = kind_cluster.cluster.kubeconfig
}
```

## Execution Mode

Upon terraform initialization, make sure to:

1. YOUR_ORGANIZATION_NAME > Workspaces >YOUR_WORKSPACE_NAME > Settings > General
1. Switch `Execution Mode`from `Remote` to `Local`
1. Save the settings
46 changes: 46 additions & 0 deletions clusters/kind/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# see https://registry.terraform.io/providers/kyma-incubator/kind/latest
resource "kind_cluster" "cluster" {
name = var.tfe_workspaces_prefix
kubeconfig_path = pathexpand(var.kind_cluster_config_path)
wait_for_ready = true

# see https://github.com/kubernetes-sigs/kind/releases
# ex: v1.21.1@sha256:fae9a58f17f18f06aeac9772ca8b5ac680ebbed985e266f711d936e91d113bad
node_image = "kindest/node:${var.kind_kubernetes_version}"

# see https://github.com/kyma-incubator/terraform-provider-kind/blob/master/kind/structure_kind_config.go
kind_config {
kind = "Cluster"
api_version = "kind.x-k8s.io/v1alpha4"

node {
role = "control-plane"

kubeadm_config_patches = [
"kind: InitConfiguration\nnodeRegistration:\n kubeletExtraArgs:\n node-labels: \"ingress-ready=true\"\n"
]

extra_port_mappings {
container_port = 80
host_port = 80
}

extra_port_mappings {
container_port = 443
host_port = 443
}
}

node {
role = "worker"
}

node {
role = "worker"
}

node {
role = "worker"
}
}
}
36 changes: 36 additions & 0 deletions clusters/kind/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_config" {
description = "Kind Cluster Config."
value = kind_cluster.cluster.kubeconfig
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_client_certificate" {
description = "Kind Cluster Client Certificate."
value = kind_cluster.cluster.client_certificate
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_client_key" {
description = "Kind Cluster Client Key."
value = kind_cluster.cluster.client_key
sensitive = true
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_ca_certificate" {
description = "Kind Cluster CA Certificate."
value = kind_cluster.cluster.cluster_ca_certificate
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_endpoint" {
description = "Kind Cluseter Endpoint."
value = kind_cluster.cluster.endpoint
}

# this variable is used for testing purposes and has no bearing on the demo
# see https://www.terraform.io/docs/language/values/outputs.html
output "workspace_url" {
value = "https://app.terraform.io/app/a-demo-organization/workspaces/${var.tfe_workspaces_prefix}-kind"
}
2 changes: 2 additions & 0 deletions clusters/kind/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see https://registry.terraform.io/providers/kyma-incubator/kind/latest
provider "kind" {}
23 changes: 23 additions & 0 deletions clusters/kind/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
terraform {
# see https://www.terraform.io/docs/language/settings/backends/remote.html
backend "remote" {
hostname = "app.terraform.io"
organization = "a-demo-organization"

workspaces {
name = "multi-cloud-k8s-kind"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-provider-requirements
required_providers {
# see https://registry.terraform.io/providers/kyma-incubator/kind/0.0.9
kind = {
source = "kyma-incubator/kind"
version = "0.0.9"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-a-required-terraform-version
required_version = "1.0.9"
}
2 changes: 2 additions & 0 deletions clusters/kind/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kind_kubernetes_version = "v1.21.1"
kind_cluster_config_path = "~/.kube/config"
18 changes: 18 additions & 0 deletions clusters/kind/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "tfe_workspaces_prefix" {
type = string
description = "Prefix for TFE Workspaces."
default = "multi-cloud-k8s"
}

# see https://github.com/kubernetes-sigs/kind/releases
variable "kind_kubernetes_version" {
type = string
description = "Kubernetes version to use with Kind Cluster."
default = "v1.21.1@sha256:fae9a58f17f18f06aeac9772ca8b5ac680ebbed985e266f711d936e91d113bad"
}

variable "kind_cluster_config_path" {
type = string
description = "The location where this cluster's kubeconfig will be saved to."
default = "~/.kube/config"
}
3 changes: 2 additions & 1 deletion outputs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ variable "tfe_workspaces" {
"aks",
"eks",
"doks",
"gke"
"gke",
"kind"
]
}

Expand Down
4 changes: 4 additions & 0 deletions workspaces/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ variable "tfe_workspaces" {
execution_mode = "remote"
working_directory = "/clusters/gke"
}, {
description = "Manages Kind Clusters."
execution_mode = "local"
working_directory = "/clusters/kind"
}, {
description = "Collects Terraform Cloud Workspace Outputs."
execution_mode = "remote"
working_directory = "/outputs"
Expand Down

0 comments on commit c1f30cd

Please sign in to comment.