diff --git a/terraform/lke-cluster.tf b/terraform/lke-cluster.tf new file mode 100644 index 0000000..5ab5491 --- /dev/null +++ b/terraform/lke-cluster.tf @@ -0,0 +1,34 @@ +resource "linode_lke_cluster" "cluster1" { + k8s_version = var.k8s_version + label = var.label + region = var.region + tags = var.tags + + dynamic "pool" { + for_each = var.pools + content { + type = pool.value["type"] + count = pool.value["count"] + } + } +} + +output "kubeconfig" { + description = "Linode kubeconfig." + value = base64decode(linode_lke_cluster.cluster1.kubeconfig) + sensitive = true +} + +resource "local_file" "kubeconfig" { + content = base64decode(linode_lke_cluster.cluster1.kubeconfig) + filename = "../.kube-config" + file_permission = "0400" +} + +output "api_endpoints" { + value = linode_lke_cluster.cluster1.api_endpoints +} + +output "status" { + value = linode_lke_cluster.cluster1.status +} diff --git a/terraform/provider.tf b/terraform/provider.tf new file mode 100644 index 0000000..46149d9 --- /dev/null +++ b/terraform/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + linode = { + source = "linode/linode" + version = "1.16.0" + } + } +} + +provider "linode" { + token = var.token +} + +provider "local" {} \ No newline at end of file diff --git a/terraform/terraform.auto.tfvars b/terraform/terraform.auto.tfvars new file mode 100644 index 0000000..d94697e --- /dev/null +++ b/terraform/terraform.auto.tfvars @@ -0,0 +1,9 @@ +label = "production-lke-cluster" +k8s_version = "1.21" +region = "us-central" +pools = [ + { + type : "g6-standard-1" + count : 1 + } +] \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..9b090cf --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,38 @@ +variable "token" { + description = "Your Linode API Personal Access Token. (required)" +} + +variable "k8s_version" { + description = "The Kubernetes version to use for this cluster. (required)" + default = "1.17" +} + +variable "label" { + description = "The unique label to assign to this cluster. (required)" + default = "default-lke-cluster" +} + +variable "region" { + description = "The region where your cluster will be located. (required)" + default = "us-east" +} + +variable "tags" { + description = "Tags to apply to your cluster for organizational purposes. (optional)" + type = list(string) + default = ["testing"] +} + +variable "pools" { + description = "The Node Pool specifications for the Kubernetes cluster. (required)" + type = list(object({ + type = string + count = number + })) + default = [ + { + type = "g6-standard-4" + count = 3 + }, + ] +}