terraform {
  required_providers {
    kind = {
      source  = "tehcyx/kind"
      version = "~> 0.9"
    }
  }
}

provider "kind" {}

# One cluster for all three environments. It publishes one node port per environment.
resource "kind_cluster" "shop" {
  name            = "shop"
  kubeconfig_path = "${path.module}/kubeconfig"
  wait_for_ready  = true

  kind_config {
    kind        = "Cluster"
    api_version = "kind.x-k8s.io/v1alpha4"

    node {
      role = "control-plane"

      extra_port_mappings {
        container_port = 30180
        host_port      = 8180
      }

      extra_port_mappings {
        container_port = 30280
        host_port      = 8280
      }

      extra_port_mappings {
        container_port = 30380
        host_port      = 8380
      }
    }
  }
}

output "kubeconfig_path" {
  value = kind_cluster.shop.kubeconfig_path
}
