Skip to content

Commit

Permalink
CRUSOE-16011: Implement Terraform support for CMK NodePools and Clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Liaw committed Dec 19, 2024
1 parent b38aac0 commit 43e401d
Show file tree
Hide file tree
Showing 16 changed files with 1,256 additions and 20 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ linters:
- gocritic
- gofmt
- gofumpt
- gomnd
- gosec
- gosec
- gosimple
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ GOCOVER_VERSION = latest

default: install

.PHONY: build
build:
@go build

.PHONY: dev
dev: build-deps test lint docs

Expand Down
6 changes: 6 additions & 0 deletions crusoe/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/crusoecloud/terraform-provider-crusoe/internal/ib_partition"
"github.com/crusoecloud/terraform-provider-crusoe/internal/instance_group"
"github.com/crusoecloud/terraform-provider-crusoe/internal/instance_template"
"github.com/crusoecloud/terraform-provider-crusoe/internal/kubernetes_cluster"
"github.com/crusoecloud/terraform-provider-crusoe/internal/kubernetes_node_pool"
"github.com/crusoecloud/terraform-provider-crusoe/internal/load_balancer"
"github.com/crusoecloud/terraform-provider-crusoe/internal/project"
"github.com/crusoecloud/terraform-provider-crusoe/internal/vm"
Expand Down Expand Up @@ -63,6 +65,8 @@ func (p *crusoeProvider) DataSources(_ context.Context) []func() datasource.Data
instance_template.NewInstanceTemplatesDataSource,
instance_group.NewInstanceGroupsDataSource,
load_balancer.NewLoadBalancerDataSource,
kubernetes_cluster.NewKubernetesClusterDataSource,
kubernetes_node_pool.NewKubernetesNodePoolDataSource,
}
}

Expand All @@ -80,6 +84,8 @@ func (p *crusoeProvider) Resources(_ context.Context) []func() resource.Resource
instance_template.NewInstanceTemplateResource,
instance_group.NewInstanceGroupResource,
load_balancer.NewLoadBalancerResource,
kubernetes_cluster.NewKubernetesClusterResource,
kubernetes_node_pool.NewKubernetesNodePoolResource,
}
}

Expand Down
35 changes: 35 additions & 0 deletions docs/data-sources/kubernetes_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "crusoe_kubernetes_cluster Data Source - terraform-provider-crusoe"
subcategory: ""
description: |-
---

# crusoe_kubernetes_cluster (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `add_ons` (List of String)
- `cluster_cidr` (String)
- `configuration` (String)
- `location` (String)
- `name` (String)
- `node_cidr_mask_size` (Number)
- `project_id` (String)
- `service_cluster_ip_range` (String)
- `subnet_id` (String)
- `version` (String)

### Read-Only

- `dns_name` (String)
- `id` (String) The ID of this resource.
- `nodepool_ids` (List of String)
33 changes: 33 additions & 0 deletions docs/data-sources/kubernetes_node_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "crusoe_kubernetes_node_pool Data Source - terraform-provider-crusoe"
subcategory: ""
description: |-
---

# crusoe_kubernetes_node_pool (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `cluster_id` (String)
- `image_id` (String)
- `instance_count` (Number)
- `instance_ids` (List of String)
- `name` (String)
- `node_labels` (Map of String)
- `project_id` (String)
- `state` (String)
- `subnet_id` (String)
- `type` (String)

### Read-Only

- `id` (String) The ID of this resource.
38 changes: 38 additions & 0 deletions docs/resources/kubernetes_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "crusoe_kubernetes_cluster Resource - terraform-provider-crusoe"
subcategory: ""
description: |-
---

# crusoe_kubernetes_cluster (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `configuration` (String) The configuration of the Kubernetes cluster. Supports `standard` and `ha`.
- `location` (String)
- `name` (String)
- `version` (String)

### Optional

- `add_ons` (List of String)
- `cluster_cidr` (String)
- `node_cidr_mask_size` (Number)
- `project_id` (String)
- `service_cluster_ip_range` (String)
- `subnet_id` (String)

### Read-Only

- `dns_name` (String)
- `id` (String) The ID of this resource.
- `nodepool_ids` (List of String)
39 changes: 39 additions & 0 deletions docs/resources/kubernetes_node_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "crusoe_kubernetes_node_pool Resource - terraform-provider-crusoe"
subcategory: ""
description: |-
---

# crusoe_kubernetes_node_pool (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cluster_id` (String)
- `instance_count` (Number)
- `name` (String)
- `ssh_key` (String)
- `type` (String)

### Optional

- `ib_partition_id` (String)
- `project_id` (String)
- `requested_node_labels` (Map of String)
- `subnet_id` (String)

### Read-Only

- `all_node_labels` (Map of String)
- `id` (String) The ID of this resource.
- `image_id` (String)
- `instance_ids` (List of String)
- `state` (String)
44 changes: 44 additions & 0 deletions examples/kubernetes/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
terraform {
required_providers {
crusoe = {
source = "crusoecloud/crusoe"
}
}
}

locals {
# Optional: Add your SSH public key to the created nodes to allow SSH access
my_ssh_key = file("~/.ssh/id_ed25519.pub")
}

resource "crusoe_kubernetes_cluster" "my_cluster" {
name = "tf-cluster"
version = "1.30"
configuration = "ha"
location = "us-east1-a"

# Optional: Set cluster/service CIDRs and node CIDR mask size
# cluster_cidr = "192.168.1.0/24"
# node_cidr_mask_size = "27"
# service_cluster_ip_range = "192.168.2.0/24"
}

resource "crusoe_kubernetes_node_pool" "c1a_nodepool" {
name = "tf-c1a-nodepool"
cluster_id = crusoe_kubernetes_cluster.my_cluster.id
instance_count = "1"
type = "c1a.2x"
ssh_key = local.my_ssh_key
requested_node_labels = {
# Optional: Kubernetes Node objects will be labeled with the following key:value pairs
# "labelkey" = "labelvalue"
}
}

output "cluster" {
value = crusoe_kubernetes_cluster.my_cluster
}

output "nodepool" {
value = crusoe_kubernetes_node_pool.c1a_nodepool
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/BurntSushi/toml v0.3.1
github.com/antihax/optional v1.0.0
github.com/crusoecloud/client-go v0.1.68
github.com/crusoecloud/client-go v0.1.69
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/terraform-plugin-docs v0.18.0
github.com/hashicorp/terraform-plugin-framework v1.3.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/crusoecloud/client-go v0.1.68 h1:7hOawWDLiuLGE1PIMzoHtjq1bNiRmwADT82h9l/MNcI=
github.com/crusoecloud/client-go v0.1.68/go.mod h1:k1FgpUllEJtE53osEwsF+JfbFKILn5t3UuBdHYBVpdY=
github.com/crusoecloud/client-go v0.1.69 h1:Ux3koAesaMn1EtxgSNutYvSGZyiNxZN4VCb0mw/5Vts=
github.com/crusoecloud/client-go v0.1.69/go.mod h1:k1FgpUllEJtE53osEwsF+JfbFKILn5t3UuBdHYBVpdY=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Loading

0 comments on commit 43e401d

Please sign in to comment.