Skip to content

Commit

Permalink
Merge pull request #1 from castai/feat/gke_provider_CORE-2251
Browse files Browse the repository at this point in the history
feat: gke cluster castai module
  • Loading branch information
aldor007 authored Apr 11, 2022
2 parents ce7d3b5 + f5c2ee2 commit a5b0fb1
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform.d
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generate-doc:
terraform-docs markdown table --output-file README.md --output-mode inject .
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<a href="https://cast.ai">
<img src="https://cast.ai/wp-content/themes/cast/img/cast-logo-dark-blue.svg" align="right" height="100" />
</a>

Terraform module for connecting an GKE cluster to CAST AI
==================


Website: https://www.cast.ai

Requirements
------------

- [Terraform](https://www.terraform.io/downloads.html) 0.13+

Using the module
------------

A module to connect an GKE cluster to CAST AI.

Requires `castai/castai` and `hashicorp/google` providers to be configured.

For Phase 2 onboarding credentials from `terraform-gke-iam` are required

```hcl
module "castai_gke_cluster" {
source = "castai/gke-cluster/castai"
project_id = var.project_id
gke_cluster_name = var.cluster_name
gke_cluster_region = var.cluster_region
gke_credentials = module.castai_gke_iam.private_key
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
autoscaler_policies_json = var.autoscaler_policies_json
}
```


<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | >= 0.16.0 |
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 2.49 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_castai"></a> [castai](#provider\_castai) | >= 0.16.0 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [castai_autoscaler.castai_autoscaler_policies](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/autoscaler) | resource |
| [castai_gke_cluster.castai_cluster](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/gke_cluster) | resource |
| [helm_release.castai_agent](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.castai_cluster_controller](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_api_url"></a> [api\_url](#input\_api\_url) | URL of alternative CAST AI API to be used during development or testing | `string` | `"https://api.cast.ai"` | no |
| <a name="input_autoscaler_policies_json"></a> [autoscaler\_policies\_json](#input\_autoscaler\_policies\_json) | Optional json object to override CAST AI cluster autoscaler policies | `string` | `""` | no |
| <a name="input_delete_nodes_on_disconnect"></a> [delete\_nodes\_on\_disconnect](#input\_delete\_nodes\_on\_disconnect) | Optionally delete Cast AI created nodes when the cluster is destroyed | `bool` | `false` | no |
| <a name="input_gke_cluster_name"></a> [gke\_cluster\_name](#input\_gke\_cluster\_name) | Name of the cluster to be connected to CAST AI. | `string` | n/a | yes |
| <a name="input_gke_cluster_region"></a> [gke\_cluster\_region](#input\_gke\_cluster\_region) | Region of the cluster to be connected to CAST AI. | `string` | n/a | yes |
| <a name="input_gke_credentials"></a> [gke\_credentials](#input\_gke\_credentials) | Optional GCP Service account credentials.json | `string` | n/a | yes |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The project id from GCP | `string` | n/a | yes |
| <a name="input_ssh_public_key"></a> [ssh\_public\_key](#input\_ssh\_public\_key) | Optional SSH public key for VM instances. Accepted values are base64 encoded SSH public key or AWS key pair ID | `string` | `null` | no |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
76 changes: 76 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
resource "castai_gke_cluster" "castai_cluster" {
project_id = var.project_id
region = var.gke_cluster_region
name = var.gke_cluster_name
ssh_public_key = var.ssh_public_key
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
credentials_json = var.gke_credentials
}

resource "helm_release" "castai_agent" {
name = "castai-agent"
repository = "https://castai.github.io/helm-charts"
chart = "castai-agent"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true

set {
name = "provider"
value = "gke"
}

set {
name = "createNamespace"
value = "false"
}

dynamic "set" {
for_each = var.api_url != "" ? [var.api_url] : []
content {
name = "apiURL"
value = var.api_url
}
}

set_sensitive {
name = "apiKey"
value = castai_gke_cluster.castai_cluster.cluster_token
}
}

resource "helm_release" "castai_cluster_controller" {
name = "cluster-controller"
repository = "https://castai.github.io/helm-charts"
chart = "castai-cluster-controller"
namespace = "castai-agent"
create_namespace = true
cleanup_on_fail = true

set {
name = "castai.clusterID"
value = castai_gke_cluster.castai_cluster.id
}

dynamic "set" {
for_each = var.api_url != "" ? [var.api_url] : []
content {
name = "castai.apiURL"
value = var.api_url
}
}

set_sensitive {
name = "castai.apiKey"
value = castai_gke_cluster.castai_cluster.cluster_token
}

depends_on = [helm_release.castai_agent]
}

resource "castai_autoscaler" "castai_autoscaler_policies" {
autoscaler_policies_json = var.autoscaler_policies_json
cluster_id = castai_gke_cluster.castai_cluster.id

depends_on = [helm_release.castai_agent]
}
44 changes: 44 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "api_url" {
type = string
description = "URL of alternative CAST AI API to be used during development or testing"
default = "https://api.cast.ai"
}

variable "project_id" {
type = string
description = "The project id from GCP"
}

variable "gke_cluster_name" {
type = string
description = "Name of the cluster to be connected to CAST AI."
}

variable "autoscaler_policies_json" {
type = string
description = "Optional json object to override CAST AI cluster autoscaler policies"
default = ""
}

variable "delete_nodes_on_disconnect" {
type = bool
description = "Optionally delete Cast AI created nodes when the cluster is destroyed"
default = false
}

variable "ssh_public_key" {
type = string
description = "Optional SSH public key for VM instances. Accepted values are base64 encoded SSH public key or AWS key pair ID"
default = null
}

variable "gke_cluster_region" {
type = string
description = "Region of the cluster to be connected to CAST AI."
}

variable "gke_credentials" {
type = string
description = "Optional GCP Service account credentials.json"
}

14 changes: 14 additions & 0 deletions version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 0.13"

required_providers {
google = {
source = "hashicorp/google"
version = ">= 2.49"
}
castai = {
source = "castai/castai"
version = ">= 0.16.0"
}
}
}

0 comments on commit a5b0fb1

Please sign in to comment.