diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..fb0d47c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,50 @@ +name: CI Pipeline + +on: + workflow_dispatch: + push: + branches: + - "main" + paths-ignore: + - ".github/**" + - "*.md" + - "docs/**" + - "!README.md" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + CI: + env: + TF_VAR_credentials: ${{ secrets.GOOGLE_CREDENTIALS }} + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: "1.9.6" + + - name: Check is doc is update to date + run: | + make doc + if ! git diff --exit-code; then + echo "Documentation not up to date. Please run \"make doc\" and commit changes!" >&2 + exit 1 + fi + + - uses: terraform-linters/setup-tflint@v4 + name: Setup TFLint + + - name: Init TFLint + run: tflint --init + env: + # https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting + GITHUB_TOKEN: ${{ github.token }} + + - run: terraform init + + - run: make check diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml new file mode 100644 index 0000000..dc3360a --- /dev/null +++ b/.github/workflows/pull-requests.yaml @@ -0,0 +1,44 @@ +name: Pull Request Pipeline + +on: + workflow_dispatch: + pull_request: + branches: + - "main" + paths-ignore: + - ".github/**" + - "*.md" + - "docs/**" + - "!README.md" + +jobs: + CI: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: "1.9.3" + + - name: Check is doc is update to date + run: | + make doc + if ! git diff --exit-code; then + echo "Documentation not up to date. Please run \"make doc\" and commit changes!" >&2 + exit 1 + fi + + - uses: terraform-linters/setup-tflint@v4 + name: Setup TFLint + + - name: Init TFLint + run: tflint --init + env: + # https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting + GITHUB_TOKEN: ${{ github.token }} + + - run: terraform init + + - run: make check-no-tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e87ddcc --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +**/.terraform/ +*.secrets.auto.tfvars +secrets.auto.tfvars +.idea/ +backend.tfvars +.terraform.lock.hcl +credentials.json diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 0000000..667bbdf --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,229 @@ +formatter: "markdown" # this is required + +version: "" + +header-from: main.tf +footer-from: "" + +recursive: + enabled: false + path: modules + +sections: + hide: [] + show: [] + +content: |- + # Nebuly Platform (GCP) + + Terraform module for provisioning Nebuly Platform resources on GCP. + + Available on [Terraform Registry](https://registry.terraform.io/modules/nebuly-ai/nebuly-platform/gcp/latest). + + ## Prerequisites + + ### Nebuly Credentials + + Before using this Terraform module, ensure that you have your Nebuly credentials ready. + These credentials are necessary to activate your installation and should be provided as input via the `nebuly_credentials` input. + + ### Required GCP APIs + + Before using this Terraform module, ensure that the following GCP APIs are enabled in your Google Cloud project: + + - [sqladmin.googleapis.com](https://cloud.google.com/sql/docs/mysql/admin-api) + - [servicenetworking.googleapis.com](https://cloud.google.com/service-infrastructure/docs/service-networking/getting-started) + - [cloudresourcemanager.googleapis.com](https://cloud.google.com/resource-manager/reference/rest) + - [container.googleapis.com](https://cloud.google.com/kubernetes-engine/docs/reference/rest) + - [secretmanager.googleapis.com](https://cloud.google.com/secret-manager/docs/reference/rest) + + You can enable the APIs using either the GCP Console or the gcloud CLI, as explained in the [GCP Documentation](https://cloud.google.com/endpoints/docs/openapi/enable-api#gcloud). + + ### Required GCP Quotas + + Ensure that your GCP project has the necessary quotas for the following resources over the regions you plan to deploy Nebuly: + + - **Name**: GPUs (all regions) + + **Min Value**: 2 + - **Name**: NVIDIA L4 GPUs + + **Min Value**: 1 + - **Name**: NVIDIA T4 GPUs + + **Min Value**: 1 + + For more information on how to check and increase quotas, refer to the [GCP Documentation](https://cloud.google.com/docs/quotas/view-manage). + + + ## Quickstart + + To get started with Nebuly installation on GCP, you can follow the steps below. + + These instructions will guide you through the installation using Nebuly's default standard configuration with the Nebuly Helm Chart. + + For specific configurations or assistance, reach out to the Nebuly Slack channel or email [support@nebuly.ai](mailto:support@nebuly.ai). + + ### 1. Terraform setup + + Import Nebuly into your Terraform root module, provide the necessary variables, and apply the changes. + + For configuration examples, you can refer to the [Examples](#examples). + + Once the Terraform changes are applied, proceed with the next steps to deploy Nebuly on the provisioned Google Kubernetes Engine (GKE) cluster. + + ### 2. Connect to the GKE Cluster + + For connecting to the created GKE cluster, you can follow the steps below. For more information, + refer to the [GKE Documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl). + + * Install the [GCloud CLI](https://cloud.google.com/sdk/docs/install-sdk). + + * Install [kubectl](https://kubernetes.io/docs/reference/kubectl/): + ```shell + gcloud components install kubectl + ``` + + * Install the Install the gke-gcloud-auth-plugin: + ```shell + gcloud components install gke-gcloud-auth-plugin + ``` + + * Fetch the command for retrieving the credentials from the module outputs: + + ```shell + terraform output gke_cluster_get_credentials + ``` + + * Run the command you got from the previous step + + ### 3. Create image pull secret + + The auto-generated Helm values use the name defined in the k8s_image_pull_secret_name input variable for the Image Pull Secret. If you prefer a custom name, update either the Terraform variable or your Helm values accordingly. + Create a Kubernetes [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for + authenticating with your Docker registry and pulling the Nebuly Docker images. + + ### 4. Bootstrap GKE cluster + + Retrieve the auto-generated values from the Terraform outputs and save them to a file named `values-bootstrap.yaml`: + + ```shell + terraform output helm_values_bootstrap + ``` + + Install the bootstrap Helm chart to set up all the dependencies required for installing the Nebuly Platform Helm chart on GKE. + + Refer to the [chart documentation](https://github.com/nebuly-ai/helm-charts/tree/main/bootstrap-gcp) for all the configuration details. + + ```shell + helm install oci://ghcr.io/nebuly-ai/helm-charts/bootstrap-gcp \ + --namespace nebuly-bootstrap \ + --generate-name \ + --create-namespace \ + -f values-bootstrap.yaml + ``` + + + ### 5. Create Secret Provider Class + Create a Secret Provider Class to allow GKE to fetch credentials from the provisioned Key Vault. + + * Get the Secret Provider Class YAML definition from the Terraform module outputs: + ```shell + terraform output secret_provider_class + ``` + + * Copy the output of the command into a file named secret-provider-class.yaml. + + * Run the following commands to install Nebuly in the Kubernetes namespace nebuly: + + ```shell + kubectl create ns nebuly + kubectl apply --server-side -f secret-provider-class.yaml + ``` + + + ### 6. Install nebuly-platform chart + + Retrieve the auto-generated values from the Terraform outputs and save them to a file named `values.yaml`: + + ```shell + terraform output helm_values + ``` + + Install the Nebuly Platform Helm chart. + Refer to the [chart documentation](https://github.com/nebuly-ai/helm-charts/tree/main/nebuly-platform) for detailed configuration options. + + ```shell + helm install oci://ghcr.io/nebuly-ai/helm-charts/nebuly-platform \ + --namespace nebuly \ + -f values.yaml \ + --timeout 16m \ + + ``` + + > ℹ️ During the initial installation of the chart, all required Nebuly LLMs are uploaded to your model registry. + > This process can take approximately 5 minutes. If the helm install command appears to be stuck, don't worry: it's simply waiting for the upload to finish. + + ### 7. Access Nebuly + + Retrieve the external Load Balancer IP address to access the Nebuly Platform: + + ```shell + kubectl get svc -n nebuly-bootstrap -o jsonpath='{range .items[?(@.status.loadBalancer.ingress)]}{.status.loadBalancer.ingress[0].ip}{"\n"}{end}' + ``` + + You can then register a DNS A record pointing to the Load Balancer IP address to access Nebuly via the custom domain you provided + in the input variable `platform_domain`. + + + ## Examples + + You can find examples of code that uses this Terraform module in the [examples](./examples) directory. + + {{ .Header }} + + + {{ .Providers }} + + + {{ .Outputs }} + + + {{ .Inputs }} + + ## Resources + + {{ range .Module.Resources }} + - {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }}) + {{- end }} + +output: + file: "" + mode: inject + template: |- + + {{ .Content }} + + +output-values: + enabled: false + from: "" + +sort: + enabled: true + by: name + +settings: + anchor: true + color: true + default: true + description: false + escape: true + hide-empty: false + html: true + indent: 2 + lockfile: false + read-comments: true + required: true + sensitive: true + type: true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b282a05 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 NebulyAI Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2d866c6 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +OK?=\033[0;32m[Ok]\033[0m + +##@ General +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + + +##@ Dev +.PHONY: doc +doc: ## Generate the doc + docker run --rm --volume "$$(pwd):/terraform-docs" -u $$(id -u) quay.io/terraform-docs/terraform-docs:0.19.0 markdown /terraform-docs > README.md + + +.PHONY: lint +lint: ## Lint the codebase + @echo "\033[0;33m[Linting...]\033[0m" + @if command -v tflint > /dev/null; then \ + tflint; \ + else \ + docker run --rm -v $$(pwd):/data -t ghcr.io/terraform-linters/tflint; \ + fi + @echo "${OK}" + +.PHONY: validate +validate: + @echo "\033[0;33m[Terraform validate...]\033[0m" + @terraform validate + @echo "${OK}" + +.PHONY: test +test: ## Run the tests + @echo "\033[0;33m[Running tests...]\033[0m" + @terraform test --verbose + @echo "${OK}" + +.PHONY: formatting +formatting: + @echo "\033[0;33m[Terraform fmt...]\033[0m" + @terraform fmt -check + @echo "${OK}" + + +.PHONY: check-no-tests +check-no-tests: formatting validate lint + +.PHONY: check +check: check-no-tests test diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e3d06a --- /dev/null +++ b/README.md @@ -0,0 +1,257 @@ +# Nebuly Platform (GCP) + +Terraform module for provisioning Nebuly Platform resources on GCP. + +Available on [Terraform Registry](https://registry.terraform.io/modules/nebuly-ai/nebuly-platform/gcp/latest). + +## Prerequisites + +### Nebuly Credentials + +Before using this Terraform module, ensure that you have your Nebuly credentials ready. +These credentials are necessary to activate your installation and should be provided as input via the `nebuly_credentials` input. + +### Required GCP APIs + +Before using this Terraform module, ensure that the following GCP APIs are enabled in your Google Cloud project: + +- [sqladmin.googleapis.com](https://cloud.google.com/sql/docs/mysql/admin-api) +- [servicenetworking.googleapis.com](https://cloud.google.com/service-infrastructure/docs/service-networking/getting-started) +- [cloudresourcemanager.googleapis.com](https://cloud.google.com/resource-manager/reference/rest) +- [container.googleapis.com](https://cloud.google.com/kubernetes-engine/docs/reference/rest) +- [secretmanager.googleapis.com](https://cloud.google.com/secret-manager/docs/reference/rest) + +You can enable the APIs using either the GCP Console or the gcloud CLI, as explained in the [GCP Documentation](https://cloud.google.com/endpoints/docs/openapi/enable-api#gcloud). + +### Required GCP Quotas + +Ensure that your GCP project has the necessary quotas for the following resources over the regions you plan to deploy Nebuly: + +- **Name**: GPUs (all regions) + + **Min Value**: 2 +- **Name**: NVIDIA L4 GPUs + + **Min Value**: 1 +- **Name**: NVIDIA T4 GPUs + + **Min Value**: 1 + +For more information on how to check and increase quotas, refer to the [GCP Documentation](https://cloud.google.com/docs/quotas/view-manage). + + +## Quickstart + +To get started with Nebuly installation on GCP, you can follow the steps below. + +These instructions will guide you through the installation using Nebuly's default standard configuration with the Nebuly Helm Chart. + +For specific configurations or assistance, reach out to the Nebuly Slack channel or email [support@nebuly.ai](mailto:support@nebuly.ai). + +### 1. Terraform setup + +Import Nebuly into your Terraform root module, provide the necessary variables, and apply the changes. + +For configuration examples, you can refer to the [Examples](#examples). + +Once the Terraform changes are applied, proceed with the next steps to deploy Nebuly on the provisioned Google Kubernetes Engine (GKE) cluster. + +### 2. Connect to the GKE Cluster + +For connecting to the created GKE cluster, you can follow the steps below. For more information, +refer to the [GKE Documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl). + +* Install the [GCloud CLI](https://cloud.google.com/sdk/docs/install-sdk). + +* Install [kubectl](https://kubernetes.io/docs/reference/kubectl/): +```shell +gcloud components install kubectl +``` + +* Install the Install the gke-gcloud-auth-plugin: +```shell +gcloud components install gke-gcloud-auth-plugin +``` + +* Fetch the command for retrieving the credentials from the module outputs: + +```shell +terraform output gke_cluster_get_credentials +``` + +* Run the command you got from the previous step + +### 3. Create image pull secret + +The auto-generated Helm values use the name defined in the k8s_image_pull_secret_name input variable for the Image Pull Secret. If you prefer a custom name, update either the Terraform variable or your Helm values accordingly. +Create a Kubernetes [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for +authenticating with your Docker registry and pulling the Nebuly Docker images. + +### 4. Bootstrap GKE cluster + +Retrieve the auto-generated values from the Terraform outputs and save them to a file named `values-bootstrap.yaml`: + +```shell +terraform output helm_values_bootstrap +``` + +Install the bootstrap Helm chart to set up all the dependencies required for installing the Nebuly Platform Helm chart on GKE. + +Refer to the [chart documentation](https://github.com/nebuly-ai/helm-charts/tree/main/bootstrap-gcp) for all the configuration details. + +```shell +helm install oci://ghcr.io/nebuly-ai/helm-charts/bootstrap-gcp \ + --namespace nebuly-bootstrap \ + --generate-name \ + --create-namespace \ + -f values-bootstrap.yaml +``` + + +### 5. Create Secret Provider Class +Create a Secret Provider Class to allow GKE to fetch credentials from the provisioned Key Vault. + +* Get the Secret Provider Class YAML definition from the Terraform module outputs: + ```shell + terraform output secret_provider_class + ``` + +* Copy the output of the command into a file named secret-provider-class.yaml. + +* Run the following commands to install Nebuly in the Kubernetes namespace nebuly: + + ```shell + kubectl create ns nebuly + kubectl apply --server-side -f secret-provider-class.yaml + ``` + + +### 6. Install nebuly-platform chart + +Retrieve the auto-generated values from the Terraform outputs and save them to a file named `values.yaml`: + +```shell +terraform output helm_values +``` + +Install the Nebuly Platform Helm chart. +Refer to the [chart documentation](https://github.com/nebuly-ai/helm-charts/tree/main/nebuly-platform) for detailed configuration options. + +```shell +helm install oci://ghcr.io/nebuly-ai/helm-charts/nebuly-platform \ + --namespace nebuly \ + -f values.yaml \ + --timeout 16m \ + +``` + +> ℹ️ During the initial installation of the chart, all required Nebuly LLMs are uploaded to your model registry. +> This process can take approximately 5 minutes. If the helm install command appears to be stuck, don't worry: it's simply waiting for the upload to finish. + +### 7. Access Nebuly + +Retrieve the external Load Balancer IP address to access the Nebuly Platform: + +```shell +kubectl get svc -n nebuly-bootstrap -o jsonpath='{range .items[?(@.status.loadBalancer.ingress)]}{.status.loadBalancer.ingress[0].ip}{"\n"}{end}' +``` + +You can then register a DNS A record pointing to the Load Balancer IP address to access Nebuly via the custom domain you provided +in the input variable `platform_domain`. + + +## Examples + +You can find examples of code that uses this Terraform module in the [examples](./examples) directory. + + + + +## Providers + +| Name | Version | +|------|---------| +| [google](#provider\_google) | ~>6.3.0 | +| [random](#provider\_random) | ~>3.6 | +| [tls](#provider\_tls) | ~>4.0 | + + +## Outputs + +| Name | Description | +|------|-------------| +| [gke\_cluster\_get\_credentials](#output\_gke\_cluster\_get\_credentials) | The command for connecting with the provisioned GKE cluster. | +| [helm\_values](#output\_helm\_values) | The `values.yaml` file for installing Nebuly with Helm.

The default standard configuration is used, which uses Nginx as ingress controller and exposes the application to the Internet. This configuration can be customized according to specific needs. | +| [secret\_provider\_class](#output\_secret\_provider\_class) | The `secret-provider-class.yaml` file to make Kubernetes reference the secrets stored in the Key Vault. | + + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [gke\_cluster\_admin\_users](#input\_gke\_cluster\_admin\_users) | The list of email addresses of the users who will have admin access to the GKE cluster. | `set(string)` | n/a | yes | +| [gke\_delete\_protection](#input\_gke\_delete\_protection) | Whether the GKE Cluster should have delete protection enabled. | `bool` | `true` | no | +| [gke\_kubernetes\_version](#input\_gke\_kubernetes\_version) | The used Kubernetes version for the GKE cluster. | `string` | `"1.30.3"` | no | +| [gke\_nebuly\_namespaces](#input\_gke\_nebuly\_namespaces) | The namespaces used by Nebuly installation. Update this if you use custom namespaces in the Helm chart installation. | `set(string)` |
[
"nebuly",
"nebuly-bootstrap"
]
| no | +| [gke\_node\_pools](#input\_gke\_node\_pools) | The node Pools used by the GKE cluster. |
map(object({
machine_type = string
min_nodes = number
max_nodes = number
node_count = number
node_locations = optional(set(string), null)
preemptible = optional(bool, false)
labels = optional(map(string), {})
guest_accelerator = optional(object({
type = string
count = number
}), null)
}))
|
{
"gpu-primary": {
"guest_accelerator": {
"count": 1,
"type": "nvidia-l4"
},
"labels": {
"gke-no-default-nvidia-gpu-device-plugin": true,
"nebuly.com/accelerator": "nvidia-l4"
},
"machine_type": "g2-standard-8",
"max_nodes": 1,
"min_nodes": 0,
"node_count": null
},
"gpu-secondary": {
"guest_accelerator": {
"count": 1,
"type": "nvidia-tesla-t4"
},
"labels": {
"gke-no-default-nvidia-gpu-device-plugin": true,
"nebuly.com/accelerator": "nvidia-tesla-t4"
},
"machine_type": "n1-standard-4",
"max_nodes": 1,
"min_nodes": 0,
"node_count": null
},
"web-services": {
"machine_type": "n2-highmem-4",
"max_nodes": 1,
"min_nodes": 1,
"node_count": 1
}
}
| no | +| [gke\_service\_account\_name](#input\_gke\_service\_account\_name) | The name of the Kubernetes Service Account used by Nebuly installation. | `string` | `"nebuly"` | no | +| [k8s\_image\_pull\_secret\_name](#input\_k8s\_image\_pull\_secret\_name) | The name of the Kubernetes Image Pull Secret to use.
This value will be used to auto-generate the values.yaml file for installing the Nebuly Platform Helm chart. | `string` | `"nebuly-docker-pull"` | no | +| [labels](#input\_labels) | Common labels that will be applied to all resources. | `map(string)` | `{}` | no | +| [nebuly\_credentials](#input\_nebuly\_credentials) | The credentials provided by Nebuly are required for activating your platform installation.
If you haven't received your credentials or have lost them, please contact support@nebuly.ai. |
object({
client_id : string
client_secret : string
})
| n/a | yes | +| [network\_cidr\_blocks](#input\_network\_cidr\_blocks) | The CIDR blocks of the VPC network used by Nebuly.

- primary: The primary CIDR block of the VPC network.
- secondary\_gke\_pods: The secondary CIDR block used by GKE for pods.
- secondary\_gke\_services: The secondary CIDR block used by GKE for services. |
object({
primary : string
secondary_gke_pods : string
secondary_gke_services : string
})
|
{
"primary": "10.0.0.0/16",
"secondary_gke_pods": "10.4.0.0/16",
"secondary_gke_services": "10.6.0.0/16"
}
| no | +| [openai\_api\_key](#input\_openai\_api\_key) | The API Key used for authenticating with OpenAI. | `string` | n/a | yes | +| [openai\_endpoint](#input\_openai\_endpoint) | The endpoint of the OpenAI API. | `string` | n/a | yes | +| [openai\_gpt4\_deployment\_name](#input\_openai\_gpt4\_deployment\_name) | The name of the deployment to use for the GPT-4 model. | `string` | n/a | yes | +| [platform\_domain](#input\_platform\_domain) | The domain on which the deployed Nebuly platform is made accessible. | `string` | n/a | yes | +| [postgres\_server\_backup\_configuration](#input\_postgres\_server\_backup\_configuration) | The backup settings of the PostgreSQL server. |
object({
enabled = bool
point_in_time_recovery_enabled = bool
n_retained_backups = number
})
|
{
"enabled": true,
"n_retained_backups": 14,
"point_in_time_recovery_enabled": true
}
| no | +| [postgres\_server\_delete\_protection](#input\_postgres\_server\_delete\_protection) | Whether the PostgreSQL server should have delete protection enabled. | `bool` | `true` | no | +| [postgres\_server\_disk\_size](#input\_postgres\_server\_disk\_size) | The size of the disk in GB for the PostgreSQL server. |
object({
initial = number
limit = number
})
|
{
"initial": 16,
"limit": 1000
}
| no | +| [postgres\_server\_edition](#input\_postgres\_server\_edition) | The edition of the PostgreSQL server. Possible values are ENTERPRISE, ENTERPRISE\_PLUS. | `string` | `"ENTERPRISE"` | no | +| [postgres\_server\_high\_availability](#input\_postgres\_server\_high\_availability) | The high availability configuration for the PostgreSQL server. |
object({
enabled : bool
})
|
{
"enabled": true
}
| no | +| [postgres\_server\_maintenance\_window](#input\_postgres\_server\_maintenance\_window) | Time window when the PostgreSQL server can automatically restart to apply updates. Specified in UTC time. |
object({
day : string
hour : number
})
|
{
"day": "6",
"hour": 23
}
| no | +| [postgres\_server\_tier](#input\_postgres\_server\_tier) | The tier of the PostgreSQL server. Default value: 4 vCPU, 16GB memory. | `string` | `"db-custom-4-15360"` | no | +| [region](#input\_region) | The region where the resources will be created | `string` | n/a | yes | +| [resource\_prefix](#input\_resource\_prefix) | The prefix that is used for generating resource names. | `string` | n/a | yes | + +## Resources + + +- resource.google_compute_global_address.main (/terraform-docs/main.tf#43) +- resource.google_compute_network.main (/terraform-docs/main.tf#38) +- resource.google_compute_network_peering_routes_config.main (/terraform-docs/main.tf#73) +- resource.google_compute_subnetwork.main (/terraform-docs/main.tf#50) +- resource.google_container_cluster.main (/terraform-docs/main.tf#206) +- resource.google_container_node_pool.main (/terraform-docs/main.tf#253) +- resource.google_project_iam_binding.gke_cluster_admin (/terraform-docs/main.tf#321) +- resource.google_project_iam_member.gke_secret_accessors (/terraform-docs/main.tf#298) +- resource.google_secret_manager_secret.jwt_signing_key (/terraform-docs/main.tf#338) +- resource.google_secret_manager_secret.nebuly_client_id (/terraform-docs/main.tf#365) +- resource.google_secret_manager_secret.nebuly_client_secret (/terraform-docs/main.tf#377) +- resource.google_secret_manager_secret.openai_api_key (/terraform-docs/main.tf#353) +- resource.google_secret_manager_secret.postgres_analytics_password (/terraform-docs/main.tf#150) +- resource.google_secret_manager_secret.postgres_analytics_username (/terraform-docs/main.tf#138) +- resource.google_secret_manager_secret.postgres_auth_password (/terraform-docs/main.tf#191) +- resource.google_secret_manager_secret.postgres_auth_username (/terraform-docs/main.tf#179) +- resource.google_secret_manager_secret_version.jwt_signing_key (/terraform-docs/main.tf#346) +- resource.google_secret_manager_secret_version.nebuly_client_id (/terraform-docs/main.tf#373) +- resource.google_secret_manager_secret_version.nebuly_client_secret (/terraform-docs/main.tf#385) +- resource.google_secret_manager_secret_version.openai_api_key (/terraform-docs/main.tf#361) +- resource.google_secret_manager_secret_version.postgres_analytics_password (/terraform-docs/main.tf#158) +- resource.google_secret_manager_secret_version.postgres_analytics_username (/terraform-docs/main.tf#146) +- resource.google_secret_manager_secret_version.postgres_auth_password (/terraform-docs/main.tf#199) +- resource.google_secret_manager_secret_version.postgres_auth_username (/terraform-docs/main.tf#187) +- resource.google_service_account.gke_node_pool (/terraform-docs/main.tf#249) +- resource.google_service_networking_connection.main (/terraform-docs/main.tf#68) +- resource.google_sql_database.analytics (/terraform-docs/main.tf#122) +- resource.google_sql_database.auth (/terraform-docs/main.tf#163) +- resource.google_sql_database_instance.main (/terraform-docs/main.tf#82) +- resource.google_sql_user.analytics (/terraform-docs/main.tf#133) +- resource.google_sql_user.auth (/terraform-docs/main.tf#174) +- resource.google_storage_bucket.main (/terraform-docs/main.tf#391) +- resource.google_storage_bucket_iam_binding.gke_storage_object_user (/terraform-docs/main.tf#309) +- resource.random_password.analytics (/terraform-docs/main.tf#128) +- resource.random_password.auth (/terraform-docs/main.tf#169) +- resource.tls_private_key.jwt_signing_key (/terraform-docs/main.tf#334) +- data source.google_compute_zones.available (/terraform-docs/main.tf#23) +- data source.google_container_engine_versions.main (/terraform-docs/main.tf#24) +- data source.google_project.current (/terraform-docs/main.tf#22) diff --git a/examples/basic/README.md b/examples/basic/README.md new file mode 100644 index 0000000..27cff88 --- /dev/null +++ b/examples/basic/README.md @@ -0,0 +1,3 @@ +# Basic usage + +This example shows a basic usage of the Nebuly's platform GCP Terraform module. diff --git a/examples/basic/main.tf b/examples/basic/main.tf new file mode 100644 index 0000000..7b89d6f --- /dev/null +++ b/examples/basic/main.tf @@ -0,0 +1,74 @@ +# ------ Variables ------ # +variable "region" { + type = string + default = "us-central1" +} +variable "project" { + type = string +} + + +# ----------- Terraform setup ----------- # +terraform { + required_version = ">1.8" + required_providers { + google = { + source = "hashicorp/google" + version = "~>6.3" + } + } +} +provider "google" { + region = var.region + project = var.project +} + + +# ------ Main ------ # +module "nebuly" { + source = "nebuly-ai/nebuly-platform/gcp" + version = "~0.1.0" + + region = var.region + resource_prefix = "dev-" + + gke_cluster_admin_users = [ + "your-user@email.com", + ] + + openai_api_key = "my-key" + openai_endpoint = "https://api.openai.com" + openai_gpt4_deployment_name = "gpt-4" + nebuly_credentials = { + client_id = "" + client_secret = "" + } +} + + +# ------ Outputs ------ # +output "helm_values_bootstrap" { + value = module.nebuly.helm_values_bootstrap + sensitive = true + description = < 0 ? 1 : 0 + + project = data.google_project.current.project_id + role = "roles/container.clusterAdmin" + + members = [ + for user in var.gke_cluster_admin_users : "user:${user}" + ] +} + + +# ------ Auth ------ # +resource "tls_private_key" "jwt_signing_key" { + algorithm = "RSA" + rsa_bits = 4096 +} +resource "google_secret_manager_secret" "jwt_signing_key" { + secret_id = "${var.resource_prefix}jwt-signing-key" + labels = var.labels + + replication { + auto {} + } +} +resource "google_secret_manager_secret_version" "jwt_signing_key" { + secret = google_secret_manager_secret.jwt_signing_key.id + secret_data = tls_private_key.jwt_signing_key.private_key_pem +} + + +# ------ External Credentials ------ # +resource "google_secret_manager_secret" "openai_api_key" { + secret_id = "${var.resource_prefix}openai-api-key" + labels = var.labels + + replication { + auto {} + } +} +resource "google_secret_manager_secret_version" "openai_api_key" { + secret = google_secret_manager_secret.openai_api_key.id + secret_data = var.openai_api_key +} +resource "google_secret_manager_secret" "nebuly_client_id" { + secret_id = "${var.resource_prefix}nebuly-client-id" + labels = var.labels + + replication { + auto {} + } +} +resource "google_secret_manager_secret_version" "nebuly_client_id" { + secret = google_secret_manager_secret.nebuly_client_id.id + secret_data = var.nebuly_credentials.client_id +} +resource "google_secret_manager_secret" "nebuly_client_secret" { + secret_id = "${var.resource_prefix}nebuly-client-secret" + labels = var.labels + + replication { + auto {} + } +} +resource "google_secret_manager_secret_version" "nebuly_client_secret" { + secret = google_secret_manager_secret.nebuly_client_secret.id + secret_data = var.nebuly_credentials.client_secret +} + +# ------ Storage ------ # +resource "google_storage_bucket" "main" { + name = "${var.resource_prefix}nebuly" + location = var.region + force_destroy = true + uniform_bucket_level_access = true + labels = var.labels + storage_class = "STANDARD" +} + + +# ------ Post provisioning ------ # +locals { + secret_provider_class_name = "nebuly-platform" + secret_provider_class_secret_name = "nebuly-platform-credentials" + + # k8s secrets keys + k8s_secret_key_analytics_db_username = "analytics-db-username" + k8s_secret_key_analytics_db_password = "analytics-db-password" + k8s_secret_key_auth_db_username = "auth-db-username" + k8s_secret_key_auth_db_password = "auth-db-password" + k8s_secret_key_jwt_signing_key = "jwt-signing-key" + k8s_secret_key_openai_api_key = "openai-api-key" + k8s_secret_key_nebuly_client_id = "nebuly-azure-client-id" + k8s_secret_key_nebuly_client_secret = "nebuly-azure-client-secret" + + helm_values = templatefile( + "${path.module}/templates/helm-values.tpl.yaml", + { + platform_domain = var.platform_domain + image_pull_secret_name = var.k8s_image_pull_secret_name + + openai_endpoint = var.openai_endpoint + openai_frustration_deployment = var.openai_gpt4_deployment_name + + secret_provider_class_name = local.secret_provider_class_name + secret_provider_class_secret_name = local.secret_provider_class_secret_name + + k8s_secret_key_analytics_db_username = local.k8s_secret_key_analytics_db_username + k8s_secret_key_analytics_db_password = local.k8s_secret_key_analytics_db_password + k8s_secret_key_auth_db_username = local.k8s_secret_key_auth_db_username + k8s_secret_key_auth_db_password = local.k8s_secret_key_auth_db_password + + k8s_secret_key_jwt_signing_key = local.k8s_secret_key_jwt_signing_key + k8s_secret_key_openai_api_key = local.k8s_secret_key_openai_api_key + k8s_secret_key_nebuly_client_secret = local.k8s_secret_key_nebuly_client_secret + k8s_secret_key_nebuly_client_id = local.k8s_secret_key_nebuly_client_id + + analytics_postgres_server_url = google_sql_database_instance.main.private_ip_address + analytics_postgres_db_name = google_sql_database.analytics.name + auth_postgres_server_url = google_sql_database_instance.main.private_ip_address + auth_postgres_db_name = google_sql_database.auth.name + + gcp_bucket_name = google_storage_bucket.main.name + gcp_project_name = data.google_project.current.project_id + }, + ) + secret_provider_class = templatefile( + "${path.module}/templates/secret-provider-class.tpl.yaml", + { + secret_provider_class_name = local.secret_provider_class_name + secret_provider_class_secret_name = local.secret_provider_class_secret_name + + secret_name_jwt_signing_key = google_secret_manager_secret_version.jwt_signing_key.name + secret_name_auth_db_username = google_secret_manager_secret_version.postgres_auth_username.name + secret_name_auth_db_password = google_secret_manager_secret_version.postgres_auth_password.name + secret_name_analytics_db_username = google_secret_manager_secret_version.postgres_analytics_username.name + secret_name_analytics_db_password = google_secret_manager_secret_version.postgres_analytics_password.name + secret_name_openai_api_key = google_secret_manager_secret_version.openai_api_key.name + + secret_name_nebuly_client_id = google_secret_manager_secret_version.nebuly_client_id.name + secret_name_nebuly_client_secret = google_secret_manager_secret_version.nebuly_client_secret.name + + k8s_secret_key_auth_db_username = local.k8s_secret_key_auth_db_username + k8s_secret_key_auth_db_password = local.k8s_secret_key_auth_db_password + k8s_secret_key_analytics_db_username = local.k8s_secret_key_analytics_db_username + k8s_secret_key_analytics_db_password = local.k8s_secret_key_analytics_db_password + k8s_secret_key_jwt_signing_key = local.k8s_secret_key_jwt_signing_key + k8s_secret_key_openai_api_key = local.k8s_secret_key_openai_api_key + k8s_secret_key_nebuly_client_secret = local.k8s_secret_key_nebuly_client_secret + k8s_secret_key_nebuly_client_id = local.k8s_secret_key_nebuly_client_id + }, + ) +} + diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..22ed99e --- /dev/null +++ b/outputs.tf @@ -0,0 +1,28 @@ +output "gke_cluster_get_credentials" { + value = "gcloud container clusters get-credentials ${google_container_cluster.main.name} --region=${var.region} --project=${data.google_project.current.project_id}" + description = "The command for connecting with the provisioned GKE cluster." +} + +# ------ Deploy ------ # +#output "helm_values_bootstrap" { +# value = local.bootstrap_helm_values +# sensitive = true +# description = < 0 + error_message = "The OpenAI API Key must be provided." + } +} +variable "nebuly_credentials" { + type = object({ + client_id : string + client_secret : string + }) + description = < 0, + length(var.nebuly_credentials.client_secret) > 0 + ]) + error_message = "The client_id and client_secret must be provided." + } +} +variable "k8s_image_pull_secret_name" { + description = <