Skip to content

Commit 5781adf

Browse files
Add OPEA ChatQnA Example + Add support for C4 and N4 (#39)
* Add OPEA ChatQna example * Clean main.tf and variables.tf * terraform-docs: automated action --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 68a2600 commit 5781adf

File tree

8 files changed

+146
-11
lines changed

8 files changed

+146
-11
lines changed

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ Note that this example may create resources. Run `terraform destroy` when you do
182182
| Name | Version |
183183
|------|---------|
184184
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
185-
| <a name="requirement_google"></a> [google](#requirement\_google) | ~> 5.11 |
185+
| <a name="requirement_google"></a> [google](#requirement\_google) | ~> 6.5 |
186186

187187
## Providers
188188

189189
| Name | Version |
190190
|------|---------|
191-
| <a name="provider_google"></a> [google](#provider\_google) | ~> 5.11 |
191+
| <a name="provider_google"></a> [google](#provider\_google) | ~> 6.5 |
192192

193193
## Modules
194194

@@ -205,16 +205,16 @@ No modules.
205205

206206
| Name | Description | Type | Default | Required |
207207
|------|-------------|------|---------|:--------:|
208-
| <a name="input_access_config"></a> [access\_config](#input\_access\_config) | Access configurations, i.e. IPs via which this instance can be accessed via the Internet. Omit to ensure that the instance is not accessible from the Internet. If omitted, ssh provisioners will not work unless Terraform can send traffic to the instance's network. This can be represented as multiple maps | <pre>list(object({<br> nat_ip = optional(string, null)<br> public_ptr_domain_name = optional(string)<br> network_tier = optional(string)<br> }))</pre> | `[]` | no |
208+
| <a name="input_access_config"></a> [access\_config](#input\_access\_config) | Access configurations, i.e. IPs via which this instance can be accessed via the Internet. Omit to ensure that the instance is not accessible from the Internet. If omitted, ssh provisioners will not work unless Terraform can send traffic to the instance's network. This can be represented as multiple maps | <pre>list(object({<br/> nat_ip = optional(string, null)<br/> public_ptr_domain_name = optional(string)<br/> network_tier = optional(string)<br/> }))</pre> | `[]` | no |
209209
| <a name="input_allow_stopping_for_update"></a> [allow\_stopping\_for\_update](#input\_allow\_stopping\_for\_update) | If true, allows Terraform to stop the instance to update its properties | `bool` | `null` | no |
210210
| <a name="input_automatic_restart"></a> [automatic\_restart](#input\_automatic\_restart) | Specifies if the instance should be restarted if it was terminated by Compute Engine (not a user). | `bool` | `true` | no |
211211
| <a name="input_boot_disk_auto_delete"></a> [boot\_disk\_auto\_delete](#input\_boot\_disk\_auto\_delete) | Whether the disk will be auto-deleted when the instance is deleted. | `bool` | `true` | no |
212212
| <a name="input_boot_disk_byo_encryption_key"></a> [boot\_disk\_byo\_encryption\_key](#input\_boot\_disk\_byo\_encryption\_key) | A 256-bit [customer-supplied encryption key] (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption), encoded in RFC 4648 base64 to encrypt this disk. | `string` | `null` | no |
213213
| <a name="input_boot_disk_labels"></a> [boot\_disk\_labels](#input\_boot\_disk\_labels) | A set of key/value label pairs assigned to the disk. This field is only applicable for persistent disks. | `map(string)` | `{}` | no |
214214
| <a name="input_boot_disk_mode"></a> [boot\_disk\_mode](#input\_boot\_disk\_mode) | The mode in which to attach this disk, either READ\_WRITE or READ\_ONLY. | `string` | `"READ_WRITE"` | no |
215-
| <a name="input_boot_disk_size"></a> [boot\_disk\_size](#input\_boot\_disk\_size) | Size of the OS disk | `number` | `100` | no |
215+
| <a name="input_boot_disk_size"></a> [boot\_disk\_size](#input\_boot\_disk\_size) | Size of the OS disk | `number` | `500` | no |
216216
| <a name="input_boot_disk_source"></a> [boot\_disk\_source](#input\_boot\_disk\_source) | The name or self\_link of the existing disk (such as those managed by google\_compute\_disk) or disk image. | `string` | `null` | no |
217-
| <a name="input_boot_disk_type"></a> [boot\_disk\_type](#input\_boot\_disk\_type) | Disk type associated with the OS disk. Values can be either pd-ssd, local-ssd, or pd-standard | `string` | `"pd-ssd"` | no |
217+
| <a name="input_boot_disk_type"></a> [boot\_disk\_type](#input\_boot\_disk\_type) | Disk type associated with the OS disk. Values can be either pd-ssd, local-ssd, or pd-standard | `string` | `null` | no |
218218
| <a name="input_boot_image_family"></a> [boot\_image\_family](#input\_boot\_image\_family) | The image from which to initialize this disk | `string` | `"ubuntu-2204-lts"` | no |
219219
| <a name="input_boot_image_project"></a> [boot\_image\_project](#input\_boot\_image\_project) | The ID of the project in which the source image resides. | `string` | `"ubuntu-os-cloud"` | no |
220220
| <a name="input_can_ip_forward"></a> [can\_ip\_forward](#input\_can\_ip\_forward) | Conditional that allows sending and receiving of packets with non-matching source or destination IPs. | `bool` | `false` | no |
@@ -226,7 +226,7 @@ No modules.
226226
| <a name="input_enable_secure_boot"></a> [enable\_secure\_boot](#input\_enable\_secure\_boot) | Verify the digital signature of all boot components, and halt the boot process if signature verification fails. | `bool` | `false` | no |
227227
| <a name="input_enable_vtpm"></a> [enable\_vtpm](#input\_enable\_vtpm) | Use a virtualized trusted platform module, which is a specialized computer chip you can use to encrypt objects like keys and certificates. | `bool` | `true` | no |
228228
| <a name="input_hostname"></a> [hostname](#input\_hostname) | A custom hostname for the instance. Must be a fully qualified DNS name and RFC-1035-valid | `string` | `null` | no |
229-
| <a name="input_ipv6_access_config"></a> [ipv6\_access\_config](#input\_ipv6\_access\_config) | Access configurations, i.e. IPs via which this instance can be accessed via the Internet. Omit to ensure that the instance is not accessible from the Internet. If omitted, ssh provisioners will not work unless Terraform can send traffic to the instance's network. This can be represented as multiple maps | <pre>list(object({<br> public_ptr_domain_name = optional(string, null)<br> network_tier = optional(string, null)<br> }))</pre> | `[]` | no |
229+
| <a name="input_ipv6_access_config"></a> [ipv6\_access\_config](#input\_ipv6\_access\_config) | Access configurations, i.e. IPs via which this instance can be accessed via the Internet. Omit to ensure that the instance is not accessible from the Internet. If omitted, ssh provisioners will not work unless Terraform can send traffic to the instance's network. This can be represented as multiple maps | <pre>list(object({<br/> public_ptr_domain_name = optional(string, null)<br/> network_tier = optional(string, null)<br/> }))</pre> | `[]` | no |
230230
| <a name="input_machine_type"></a> [machine\_type](#input\_machine\_type) | The machine type to create | `string` | `"c3-standard-4"` | no |
231231
| <a name="input_name"></a> [name](#input\_name) | A unique name for the resource, required by GCE. Changing this forces a new resource to be created. | `string` | n/a | yes |
232232
| <a name="input_network"></a> [network](#input\_network) | The name or self\_link of the network to attach this interface to. | `string` | `"default"` | no |
@@ -236,7 +236,7 @@ No modules.
236236
| <a name="input_preemptible"></a> [preemptible](#input\_preemptible) | Specifies if the instance is preemptible. If this field is set to true, then automatic\_restart must be set to false. | `bool` | `false` | no |
237237
| <a name="input_project"></a> [project](#input\_project) | The ID of the project in which the resource resides. | `string` | `""` | no |
238238
| <a name="input_provisioning_model"></a> [provisioning\_model](#input\_provisioning\_model) | Describe the type of preemptible VM. This field accepts the value STANDARD or SPOT | `string` | `"STANDARD"` | no |
239-
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | Service account and scopes that will be associated with the GCE instance. | <pre>object({<br> service_email = optional(string, null)<br> scopes = optional(set(string), [])<br> })</pre> | `{}` | no |
239+
| <a name="input_service_account"></a> [service\_account](#input\_service\_account) | Service account and scopes that will be associated with the GCE instance. | <pre>object({<br/> service_email = optional(string, null)<br/> scopes = optional(set(string), [])<br/> })</pre> | `{}` | no |
240240
| <a name="input_stack_type"></a> [stack\_type](#input\_stack\_type) | he stack type for this network interface to identify whether the IPv6 feature is enabled or not. | `string` | `"IPV4_ONLY"` | no |
241241
| <a name="input_subnetwork"></a> [subnetwork](#input\_subnetwork) | The name or self\_link of the subnetwork to attach this interface to. Either network or subnetwork must be provided. | `string` | `null` | no |
242242
| <a name="input_subnetwork_project"></a> [subnetwork\_project](#input\_subnetwork\_project) | The project in which the subnetwork belongs. If the subnetwork is a name and this field is not provided, the provider project is used. | `string` | `null` | no |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<p align="center">
2+
<img src="https://github.com/intel/terraform-intel-gcp-vm/blob/main/images/logo-classicblue-800px.png?raw=true" alt="Intel Logo" width="250"/>
3+
</p>
4+
5+
# Intel® Optimized Cloud Modules for Terraform
6+
7+
© Copyright 2024, Intel Corporation
8+
9+
## GCP C4 Instance with 5th Generation Intel® Xeon® Scalable Processor (Emerald Rapids) & Open Platform for Enterprise AI (OPEA) ChatQnA Example
10+
11+
This demo will showcase Retrieval Augmented Generation (RAG) CPU inference using 5th Gen Xeon Scalable Processors on GCP using the OPEA ChatQnA Example. For more information about OPEA, go [here](https://opea.dev/). For more information on this specific example, go [here](https://github.com/opea-project/GenAIExamples/tree/main/ChatQnA).
12+
13+
## Usage
14+
15+
## After cloning the repo, modify /examples/gen-ai-xeon-opea-chatqna/variables.tf to add your Huggingface Token
16+
17+
Some Models required a Token. Modify the Huggingface Token variable to your specific Huggingface Token, for information on creating a Huggingface token go [here](https://huggingface.co/docs/hub/en/security-tokens)
18+
19+
```hcl
20+
variable "huggingface_token" {
21+
description = "Huggingface Token"
22+
default = " <YOUR HUGGINGFACE TOKEN> "
23+
type = string
24+
}
25+
```
26+
27+
**If needed, also modify values on /examples/gen-ai-xeon-opea-chatqna/main.tf to match your needs**
28+
29+
## GCP Cloud Shell Usage
30+
31+
1. Log on to GCP Portal
32+
2. Enter the GCP Cloud Shell (terminal button on top right of page)
33+
3. Run the following commands in order:
34+
35+
36+
```bash
37+
git clone https://github.com/intel/terraform-intel-gcp-vm.git
38+
cd terraform-intel-gcp-vm/examples/gen-ai-xeon-opea-chatqna
39+
# ADD TOKEN TO variables.tf (SEE ABOVE)
40+
terraform init
41+
terraform plan
42+
terraform apply
43+
44+
# (enter your GCP project ID and "yes" to confirm)
45+
46+
```
47+
48+
After the Terraform module successfully creates the GCP VM instance, **wait ~15 minutes** for the module to launch the containers and download the LLMs before continuing.
49+
50+
## Accessing the Demo
51+
52+
You can access the demos using the following:
53+
54+
- OPEA ChatQnA: `http://yourpublicip:5174`
55+
56+
57+
## Deleting the Demo
58+
59+
To delete the demo, run `terraform destroy` to delete all resources created.
60+
61+
## Pre-requisites for running on a local Workstation (disregard if using GCP Cloud Shell)
62+
63+
1. Google Cloud CLI: https://cloud.google.com/sdk/docs/install
64+
2. CGP account access configured: https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference.html#running-terraform-on-your-workstation
65+
3. Terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli
66+
4. Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#cloud-config
2+
package_update: true
3+
package_upgrade: true
4+
5+
package:
6+
- git
7+
8+
runcmd:
9+
- apt install ansible -y
10+
- git clone https://github.com/intel/optimized-cloud-recipes.git /tmp/optimized-cloud-recipes
11+
- cd /tmp/optimized-cloud-recipes/recipes/ai-opea-chatqna-xeon
12+
- cp opea.sh /etc/profile.d/opea.sh
13+
- echo 'export HUGGINGFACEHUB_API_TOKEN=${HUGGINGFACEHUB_API_TOKEN}' | sudo tee -a /etc/profile.d/opea.sh
14+
- chmod +x /etc/profile.d/opea.sh
15+
- source /etc/profile.d/opea.sh
16+
- ansible-playbook recipe.yml
17+
18+
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Random ID to minimize the chances of name conflicts
2+
resource "random_id" "rid" {
3+
byte_length = 3
4+
}
5+
6+
#GCP Linux VM with Intel OPEA ChatQnA
7+
module "linux_vm" {
8+
source = "intel/gcp-vm/intel"
9+
project = var.project
10+
boot_image_project = "ubuntu-os-cloud"
11+
boot_image_family = "ubuntu-2204-lts"
12+
name = "ai-opea-chatqna-${random_id.rid.dec}"
13+
zone = "us-east4-a"
14+
machine_type = "c4-highcpu-48"
15+
allow_stopping_for_update = true
16+
tags = ["ai-opea-chatqna-${random_id.rid.dec}"]
17+
user_data = templatefile("./cloud_init.yml", { HUGGINGFACEHUB_API_TOKEN = var.huggingface_token })
18+
access_config = [{
19+
nat_ip = null
20+
public_ptr_domain_name = null
21+
network_tier = "PREMIUM"
22+
}, ]
23+
}
24+
25+
#Required firewall rules
26+
resource "google_compute_firewall" "rules" {
27+
project = var.project
28+
name = "ai-opea-chatqna-${random_id.rid.dec}"
29+
network = "default"
30+
description = "Allows access to OPEA AI ChatQnA"
31+
32+
allow {
33+
protocol = "tcp"
34+
ports = ["22","80", "443", "6379", "8001", "6006", "6007", "6000", "7000", "8808", "8000", "8888", "5173", "5174", "9009", "9000"]
35+
}
36+
source_ranges = ["0.0.0.0/0"]
37+
target_tags = ["ai-opea-chatqna-${random_id.rid.dec}"]
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
variable "project" {
2+
type = string
3+
description = "Enter GCP Project ID"
4+
}
5+
6+
# Variable for Huggingface Token
7+
variable "huggingface_token" {
8+
description = "Enter a Huggingface Token to be used to download the models"
9+
default = " <YOUR HUGGINGFACE TOKEN> "
10+
type = string
11+
}

main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
# Intel CPU, we are not populating the min CPU platform. We are using the default CPU platform that GCP will provide for these older generation of instances
88

99
locals {
10-
machine_type_regex = "^([cemn][123u])"
10+
machine_type_regex = "^([cemn][1234u])"
1111
machine_types = {
1212
"n2": "Intel Ice Lake",
1313
"c3": "Intel Sapphire Rapids",
1414
"m3": "Intel Ice Lake",
1515
"c2": "Intel Cascade Lake"
16+
"c4": null
17+
"n4": null
1618
"n1": null
1719
"m1": null
1820
"m2": null

variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ variable "boot_image_family" {
103103
variable "boot_disk_size" {
104104
type = number
105105
description = "Size of the OS disk"
106-
default = 100
106+
default = 500
107107
}
108108

109109
variable "boot_disk_type" {
110110
type = string
111111
description = "Disk type associated with the OS disk. Values can be either pd-ssd, local-ssd, or pd-standard"
112-
default = "pd-ssd"
112+
default = null
113113
}
114114

115115
variable "boot_image_project" {

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
google = {
66
source = "hashicorp/google"
7-
version = "~> 5.11"
7+
version = "~> 6.5"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)