Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions vertex_ai_reasoning_engine_basic/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
8 changes: 8 additions & 0 deletions vertex_ai_reasoning_engine_basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "google_vertex_ai_reasoning_engine" "reasoning_engine" {
display_name = "reasoning-engine-${local.name_suffix}"
description = "A basic reasoning engine"
region = "us-central1"
}

data "google_project" "project" {
}
7 changes: 7 additions & 0 deletions vertex_ai_reasoning_engine_basic/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
79 changes: 79 additions & 0 deletions vertex_ai_reasoning_engine_basic/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Vertex Ai Reasoning Engine Basic - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="vertex_ai_reasoning_engine_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.

## Terraforming!

Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
the project name from the environment variable.

```bash
export GOOGLE_CLOUD_PROJECT={{project-id}}
```

After that, let's get Terraform started. Run the following to pull in the providers.

```bash
terraform init
```

With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!

```bash
terraform apply
```

Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.

```bash
yes
```


## Post-Apply

### Editing your config

Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.

```bash
terraform plan
```

So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
run a 'plan' again.

```bash
terraform plan
```

Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
at the 'yes' prompt.

```bash
terraform apply
```

```bash
yes
```

## Cleanup

Run the following to remove the resources Terraform provisioned:

```bash
terraform destroy
```
```bash
yes
```
15 changes: 15 additions & 0 deletions vertex_ai_reasoning_engine_full/backing_file.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file has some scaffolding to make sure that names are unique and that
# a region and zone are selected when you try to create your Terraform resources.

locals {
name_suffix = "${random_pet.suffix.id}"
}

resource "random_pet" "suffix" {
length = 2
}

provider "google" {
region = "us-central1"
zone = "us-central1-c"
}
166 changes: 166 additions & 0 deletions vertex_ai_reasoning_engine_full/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Generate pickle files with the cloudpickle library:
#
# local_agent = LangchainAgent(
# model=MODEL,
# agent_executor_kwargs={"return_intermediate_steps": True},
# )
#
# output_filename = "pickle.pkl"
#
# with open(output_filename, "wb") as f:
# cloudpickle.dump(local_agent, f)

locals {
class_methods = [
{
api_mode = "async"
description = null
name = "async_query"
parameters = {
type = "object"
required = []
properties = {}
}
}
]
}

resource "google_vertex_ai_reasoning_engine" "reasoning_engine" {
display_name = "reasoning-engine-${local.name_suffix}"
description = "A basic reasoning engine"
region = "us-central1"

encryption_spec {
kms_key_name = "example-key-${local.name_suffix}"
}

spec {
agent_framework = "google-adk"
class_methods = jsonencode(local.class_methods)
service_account = google_service_account.service_account.email

deployment_spec {

env {
name = "var_1"
value = "value_2"
}

env {
name = "var_2"
value = "value_2"
}

secret_env {
name = "secret_var_1"

secret_ref {
secret = google_secret_manager_secret.secret.secret_id
version = "latest"
}
}

secret_env {
name = "secret_var_2"

secret_ref {
secret = google_secret_manager_secret.secret.secret_id
version = "latest"
}
}
}

package_spec {
dependency_files_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_dependencies_tar_gz.name}"
pickle_object_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_pickle.name}"
python_version = "3.11"
requirements_gcs_uri = "${google_storage_bucket.bucket.url}/${google_storage_bucket_object.bucket_obj_requirements_txt.name}"
}
}

depends_on = [
time_sleep.wait_5_minutes
]
}

# Ensure we wait enough time for IAM permissions to be propagated
resource "time_sleep" "wait_5_minutes" {
create_duration = "5m"

depends_on = [
google_project_iam_member.sa_iam_ai_platform_user,
google_project_iam_member.sa_iam_object_viewer,
google_project_iam_member.sa_iam_viewer,
google_secret_manager_secret_iam_member.secret_access,
google_secret_manager_secret_version.secret_version
]
}

resource "google_secret_manager_secret_version" "secret_version" {
secret = google_secret_manager_secret.secret.id
secret_data = "test"
}

resource "google_secret_manager_secret" "secret" {
secret_id = "secret-${local.name_suffix}"

replication {
auto {}
}
}

resource "google_secret_manager_secret_iam_member" "secret_access" {
secret_id = google_secret_manager_secret.secret.id
role = "roles/secretmanager.secretAccessor"
member = google_service_account.service_account.member
}

resource "google_storage_bucket" "bucket" {
name = "reasoning-engine-${local.name_suffix}"
location = "us-central1"
uniform_bucket_level_access = true
force_destroy = true
}

resource "google_storage_bucket_object" "bucket_obj_requirements_txt" {
name = "requirements.txt"
bucket = google_storage_bucket.bucket.id
source = "./test-fixtures/requirements_adk.txt"
}

resource "google_storage_bucket_object" "bucket_obj_pickle" {
name = "code.pkl"
bucket = google_storage_bucket.bucket.id
source = "./test-fixtures/pickle_adk.pkl"
}

resource "google_storage_bucket_object" "bucket_obj_dependencies_tar_gz" {
name = "dependencies.tar.gz"
bucket = google_storage_bucket.bucket.id
source = "./test-fixtures/dependencies_adk.tar.gz"
}

resource "google_service_account" "service_account" {
account_id = "sa-${local.name_suffix}"
}

resource "google_project_iam_member" "sa_iam_object_viewer" {
role = "roles/storage.objectViewer"
project = data.google_project.project.id
member = google_service_account.service_account.member
}

resource "google_project_iam_member" "sa_iam_ai_platform_user" {
role = "roles/aiplatform.user"
project = data.google_project.project.id
member = google_service_account.service_account.member
}

resource "google_project_iam_member" "sa_iam_viewer" {
role = "roles/viewer"
project = data.google_project.project.id
member = google_service_account.service_account.member
}

data "google_project" "project" {
}
7 changes: 7 additions & 0 deletions vertex_ai_reasoning_engine_full/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
===

These examples use real resources that will be billed to the
Google Cloud Platform project you use - so make sure that you
run "terraform destroy" before quitting!

===
79 changes: 79 additions & 0 deletions vertex_ai_reasoning_engine_full/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Vertex Ai Reasoning Engine Full - Terraform

## Setup

<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="vertex_ai_reasoning_engine_full" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>

Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.

<walkthrough-project-billing-setup></walkthrough-project-billing-setup>

Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.

## Terraforming!

Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
the project name from the environment variable.

```bash
export GOOGLE_CLOUD_PROJECT={{project-id}}
```

After that, let's get Terraform started. Run the following to pull in the providers.

```bash
terraform init
```

With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!

```bash
terraform apply
```

Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.

```bash
yes
```


## Post-Apply

### Editing your config

Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.

```bash
terraform plan
```

So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
run a 'plan' again.

```bash
terraform plan
```

Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
at the 'yes' prompt.

```bash
terraform apply
```

```bash
yes
```

## Cleanup

Run the following to remove the resources Terraform provisioned:

```bash
terraform destroy
```
```bash
yes
```