-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from castai/feat/gke_provider_CORE-2251
feat: gke cluster castai module
- Loading branch information
Showing
6 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |