Skip to content

Commit 236967a

Browse files
Add new Agent Engine (google_vertex_ai_reasoning_engine) resource (#14480) (#1123)
[upstream:0b824e0485ebff0224e2899a03ad29cc1ac8e435] Signed-off-by: Modular Magician <[email protected]>
1 parent b9b4878 commit 236967a

File tree

8 files changed

+376
-0
lines changed

8 files changed

+376
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "google_vertex_ai_reasoning_engine" "reasoning_engine" {
2+
display_name = "reasoning-engine-${local.name_suffix}"
3+
description = "A basic reasoning engine"
4+
region = "us-central1"
5+
}
6+
7+
data "google_project" "project" {
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Vertex Ai Reasoning Engine Basic - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="vertex_ai_reasoning_engine_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Generate pickle files with the cloudpickle library:
2+
#
3+
# local_agent = LangchainAgent(
4+
# model=MODEL,
5+
# agent_executor_kwargs={"return_intermediate_steps": True},
6+
# )
7+
#
8+
# output_filename = "pickle.pkl"
9+
#
10+
# with open(output_filename, "wb") as f:
11+
# cloudpickle.dump(local_agent, f)
12+
13+
locals {
14+
class_methods = [
15+
{
16+
api_mode = "async"
17+
description = null
18+
name = "async_query"
19+
parameters = {
20+
type = "object"
21+
required = []
22+
properties = {}
23+
}
24+
}
25+
]
26+
}
27+
28+
resource "google_vertex_ai_reasoning_engine" "reasoning_engine" {
29+
display_name = "reasoning-engine-${local.name_suffix}"
30+
description = "A basic reasoning engine"
31+
region = "us-central1"
32+
33+
encryption_spec {
34+
kms_key_name = "example-key-${local.name_suffix}"
35+
}
36+
37+
spec {
38+
agent_framework = "google-adk"
39+
class_methods = jsonencode(local.class_methods)
40+
service_account = google_service_account.service_account.email
41+
42+
deployment_spec {
43+
44+
env {
45+
name = "var_1"
46+
value = "value_2"
47+
}
48+
49+
env {
50+
name = "var_2"
51+
value = "value_2"
52+
}
53+
54+
secret_env {
55+
name = "secret_var_1"
56+
57+
secret_ref {
58+
secret = google_secret_manager_secret.secret.secret_id
59+
version = "latest"
60+
}
61+
}
62+
63+
secret_env {
64+
name = "secret_var_2"
65+
66+
secret_ref {
67+
secret = google_secret_manager_secret.secret.secret_id
68+
version = "latest"
69+
}
70+
}
71+
}
72+
73+
package_spec {
74+
dependency_files_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_dependencies_tar_gz.name}"
75+
pickle_object_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_pickle.name}"
76+
python_version = "3.11"
77+
requirements_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_requirements_txt.name}"
78+
}
79+
}
80+
81+
depends_on = [
82+
time_sleep.wait_5_minutes
83+
]
84+
}
85+
86+
# Ensure we wait enough time for IAM permissions to be propagated
87+
resource "time_sleep" "wait_5_minutes" {
88+
create_duration = "5m"
89+
90+
depends_on = [
91+
google_project_iam_member.sa_iam_ai_platform_user,
92+
google_project_iam_member.sa_iam_object_viewer,
93+
google_project_iam_member.sa_iam_viewer,
94+
google_secret_manager_secret_iam_member.secret_access,
95+
google_secret_manager_secret_version.secret_version
96+
]
97+
}
98+
99+
resource "google_secret_manager_secret_version" "secret_version" {
100+
secret = google_secret_manager_secret.secret.id
101+
secret_data = "test"
102+
}
103+
104+
resource "google_secret_manager_secret" "secret" {
105+
secret_id = "secret-${local.name_suffix}"
106+
107+
replication {
108+
auto {}
109+
}
110+
}
111+
112+
resource "google_secret_manager_secret_iam_member" "secret_access" {
113+
secret_id = google_secret_manager_secret.secret.id
114+
role = "roles/secretmanager.secretAccessor"
115+
member = google_service_account.service_account.member
116+
}
117+
118+
resource "google_storage_bucket" "bucket" {
119+
name = "reasoning-engine-${local.name_suffix}"
120+
location = "us-central1"
121+
uniform_bucket_level_access = true
122+
force_destroy = true
123+
}
124+
125+
resource "google_storage_bucket_object" "bucket_obj_requirements_txt" {
126+
name = "requirements.txt"
127+
bucket = google_storage_bucket.bucket.id
128+
source = "./test-fixtures/requirements_adk.txt"
129+
}
130+
131+
resource "google_storage_bucket_object" "bucket_obj_pickle" {
132+
name = "code.pkl"
133+
bucket = google_storage_bucket.bucket.id
134+
source = "./test-fixtures/pickle_adk.pkl"
135+
}
136+
137+
resource "google_storage_bucket_object" "bucket_obj_dependencies_tar_gz" {
138+
name = "dependencies.tar.gz"
139+
bucket = google_storage_bucket.bucket.id
140+
source = "./test-fixtures/dependencies_adk.tar.gz"
141+
}
142+
143+
resource "google_service_account" "service_account" {
144+
account_id = "sa-${local.name_suffix}"
145+
}
146+
147+
resource "google_project_iam_member" "sa_iam_object_viewer" {
148+
role = "roles/storage.objectViewer"
149+
project = data.google_project.project.id
150+
member = google_service_account.service_account.member
151+
}
152+
153+
resource "google_project_iam_member" "sa_iam_ai_platform_user" {
154+
role = "roles/aiplatform.user"
155+
project = data.google_project.project.id
156+
member = google_service_account.service_account.member
157+
}
158+
159+
resource "google_project_iam_member" "sa_iam_viewer" {
160+
role = "roles/viewer"
161+
project = data.google_project.project.id
162+
member = google_service_account.service_account.member
163+
}
164+
165+
data "google_project" "project" {
166+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Vertex Ai Reasoning Engine Full - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="[email protected]" analyticsId="UA-125550242-1" tutorialName="vertex_ai_reasoning_engine_full" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```

0 commit comments

Comments
 (0)