Add ability to use existing source files in GCS. (#3653)
This commit is contained in:
@@ -114,6 +114,37 @@ module "agent_engine" {
|
|||||||
# tftest inventory=minimal-pickle.yaml
|
# tftest inventory=minimal-pickle.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You may want to upload your files on the GCS bucket outside Terrafrom.
|
||||||
|
In this example, the module expects your package config files to be already present in the GCS bucket.
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
module "agent_engine" {
|
||||||
|
source = "./fabric/modules/agent-engine"
|
||||||
|
name = "my-agent"
|
||||||
|
project_id = var.project_id
|
||||||
|
region = var.region
|
||||||
|
|
||||||
|
agent_engine_config = {
|
||||||
|
agent_framework = "google-adk"
|
||||||
|
}
|
||||||
|
|
||||||
|
bucket_config = {
|
||||||
|
create = false
|
||||||
|
}
|
||||||
|
|
||||||
|
deployment_files = {
|
||||||
|
package_config = {
|
||||||
|
are_paths_local = false
|
||||||
|
dependencies_path = "dependencies.tar.gz"
|
||||||
|
pickle_path = "pickle.pkl"
|
||||||
|
requirements_path = "requirements.txt"
|
||||||
|
}
|
||||||
|
source_config = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# tftest inventory=pickle-gcs.yaml
|
||||||
|
```
|
||||||
|
|
||||||
### Unmanaged deployments
|
### Unmanaged deployments
|
||||||
|
|
||||||
By default, this module tracks and controls code updates. This means you can only the agent code via Terraform.
|
By default, this module tracks and controls code updates. This means you can only the agent code via Terraform.
|
||||||
@@ -269,15 +300,15 @@ The module allows you to dynamically reference context values for resources crea
|
|||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [agent_engine_config](variables.tf#L17) | The agent configuration. | <code title="object({ agent_framework = string class_methods = optional(list(any), []) container_concurrency = optional(number) environment_variables = optional(map(string), {}) max_instances = optional(number) min_instances = optional(number) python_version = optional(string, "3.12") resource_limits = optional(object({ cpu = string memory = string })) secret_environment_variables = optional(map(object({ secret_id = string version = optional(string, "latest") })), {}) })">object({…})</code> | ✓ | |
|
| [agent_engine_config](variables.tf#L17) | The agent configuration. | <code title="object({ agent_framework = string class_methods = optional(list(any), []) container_concurrency = optional(number) environment_variables = optional(map(string), {}) max_instances = optional(number) min_instances = optional(number) python_version = optional(string, "3.12") resource_limits = optional(object({ cpu = string memory = string })) secret_environment_variables = optional(map(object({ secret_id = string version = optional(string, "latest") })), {}) })">object({…})</code> | ✓ | |
|
||||||
| [name](variables.tf#L121) | The name of the agent. | <code>string</code> | ✓ | |
|
| [name](variables.tf#L122) | The name of the agent. | <code>string</code> | ✓ | |
|
||||||
| [project_id](variables.tf#L127) | The id of the project where to deploy the agent. | <code>string</code> | ✓ | |
|
| [project_id](variables.tf#L128) | The id of the project where to deploy the agent. | <code>string</code> | ✓ | |
|
||||||
| [region](variables.tf#L133) | The region where to deploy the agent. | <code>string</code> | ✓ | |
|
| [region](variables.tf#L134) | The region where to deploy the agent. | <code>string</code> | ✓ | |
|
||||||
| [bucket_config](variables.tf#L40) | The GCS bucket configuration. | <code title="object({ create = optional(bool, true) deletion_protection = optional(bool, true) name = optional(string) uniform_bucket_level_access = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
| [bucket_config](variables.tf#L40) | The GCS bucket configuration. | <code title="object({ create = optional(bool, true) deletion_protection = optional(bool, true) name = optional(string) uniform_bucket_level_access = optional(bool, true) })">object({…})</code> | | <code>{}</code> |
|
||||||
| [context](variables.tf#L52) | Context-specific interpolations. | <code title="object({ custom_roles = optional(map(string), {}) iam_principals = optional(map(string), {}) locations = optional(map(string), {}) kms_keys = optional(map(string), {}) project_ids = optional(map(string), {}) })">object({…})</code> | | <code>{}</code> |
|
| [context](variables.tf#L52) | Context-specific interpolations. | <code title="object({ custom_roles = optional(map(string), {}) iam_principals = optional(map(string), {}) locations = optional(map(string), {}) kms_keys = optional(map(string), {}) project_ids = optional(map(string), {}) })">object({…})</code> | | <code>{}</code> |
|
||||||
| [deployment_files](variables.tf#L65) | The to source files path and names. | <code title="object({ package_config = optional(object({ dependencies_path = optional(string, "./src/dependencies.tar.gz") pickle_path = optional(string, "./src/pickle.pkl") requirements_path = optional(string, "./src/requirements.txt") }), null) source_config = optional(object({ entrypoint_module = optional(string, "agent") entrypoint_object = optional(string, "agent") requirements_path = optional(string, "requirements.txt") source_path = optional(string, "./src/source.tar.gz") }), null) })">object({…})</code> | | <code title="{ package_config = null source_config = {} }">{…}</code> |
|
| [deployment_files](variables.tf#L65) | The to source files path and names. | <code title="object({ package_config = optional(object({ are_paths_local = optional(bool, true) dependencies_path = optional(string, "./src/dependencies.tar.gz") pickle_path = optional(string, "./src/pickle.pkl") requirements_path = optional(string, "./src/requirements.txt") }), null) source_config = optional(object({ entrypoint_module = optional(string, "agent") entrypoint_object = optional(string, "agent") requirements_path = optional(string, "requirements.txt") source_path = optional(string, "./src/source.tar.gz") }), null) })">object({…})</code> | | <code title="{ package_config = null source_config = {} }">{…}</code> |
|
||||||
| [description](variables.tf#L101) | The Agent Engine description. | <code>string</code> | | <code>"Terraform managed."</code> |
|
| [description](variables.tf#L102) | The Agent Engine description. | <code>string</code> | | <code>"Terraform managed."</code> |
|
||||||
| [encryption_key](variables.tf#L108) | The full resource name of the Cloud KMS CryptoKey. | <code>string</code> | | <code>null</code> |
|
| [encryption_key](variables.tf#L109) | The full resource name of the Cloud KMS CryptoKey. | <code>string</code> | | <code>null</code> |
|
||||||
| [managed](variables.tf#L114) | Whether the Terraform module should control the code updates. | <code>bool</code> | | <code>true</code> |
|
| [managed](variables.tf#L115) | Whether the Terraform module should control the code updates. | <code>bool</code> | | <code>true</code> |
|
||||||
| [service_account_config](variables-serviceaccount.tf#L18) | Service account configurations. | <code title="object({ create = optional(bool, true) display_name = optional(string) email = optional(string) name = optional(string) roles = optional(list(string), [ "roles/aiplatform.user", "roles/storage.objectViewer", "roles/viewer" ]) })">object({…})</code> | | <code>{}</code> |
|
| [service_account_config](variables-serviceaccount.tf#L18) | Service account configurations. | <code title="object({ create = optional(bool, true) display_name = optional(string) email = optional(string) name = optional(string) roles = optional(list(string), [ "roles/aiplatform.user", "roles/storage.objectViewer", "roles/viewer" ]) })">object({…})</code> | | <code>{}</code> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|||||||
@@ -88,10 +88,22 @@ resource "google_vertex_ai_reasoning_engine" "managed" {
|
|||||||
for_each = var.deployment_files.package_config != null ? { 1 = 1 } : {}
|
for_each = var.deployment_files.package_config != null ? { 1 = 1 } : {}
|
||||||
|
|
||||||
content {
|
content {
|
||||||
python_version = var.agent_engine_config.python_version
|
python_version = var.agent_engine_config.python_version
|
||||||
dependency_files_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.dependencies[0].name}"
|
dependency_files_gcs_uri = (
|
||||||
requirements_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.requirements[0].name}"
|
var.deployment_files.package_config.are_paths_local
|
||||||
pickle_object_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.pickle[0].name}"
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.dependencies[0].name}"
|
||||||
|
: var.deployment_files.package_config.dependencies_path
|
||||||
|
)
|
||||||
|
requirements_gcs_uri = (
|
||||||
|
var.deployment_files.package_config.are_paths_local
|
||||||
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.requirements[0].name}"
|
||||||
|
: var.deployment_files.package_config.requirements_path
|
||||||
|
)
|
||||||
|
pickle_object_gcs_uri = (
|
||||||
|
var.deployment_files.package_config.are_paths_local
|
||||||
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.pickle[0].name}"
|
||||||
|
: var.deployment_files.package_config.pickle_path
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,10 +88,22 @@ resource "google_vertex_ai_reasoning_engine" "unmanaged" {
|
|||||||
for_each = var.deployment_files.package_config == null ? {} : { 1 = 1 }
|
for_each = var.deployment_files.package_config == null ? {} : { 1 = 1 }
|
||||||
|
|
||||||
content {
|
content {
|
||||||
python_version = var.agent_engine_config.python_version
|
python_version = var.agent_engine_config.python_version
|
||||||
dependency_files_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.dependencies[0].name}"
|
dependency_files_gcs_uri = (
|
||||||
requirements_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.requirements[0].name}"
|
var.deployment_files.package_config.are_paths_local
|
||||||
pickle_object_gcs_uri = "gs://${local.bucket_name}/${google_storage_bucket_object.pickle[0].name}"
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.dependencies[0].name}"
|
||||||
|
: var.deployment_files.package_config.dependencies_path
|
||||||
|
)
|
||||||
|
requirements_gcs_uri = (
|
||||||
|
var.deployment_files.package_config.are_paths_local
|
||||||
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.requirements[0].name}"
|
||||||
|
: var.deployment_files.package_config.requirements_path
|
||||||
|
)
|
||||||
|
pickle_object_gcs_uri = (
|
||||||
|
var.deployment_files.package_config.are_paths_local
|
||||||
|
? "gs://${local.bucket_name}/${google_storage_bucket_object.pickle[0].name}"
|
||||||
|
: var.deployment_files.package_config.pickle_path
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ resource "google_storage_bucket" "default" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_storage_bucket_object" "dependencies" {
|
resource "google_storage_bucket_object" "dependencies" {
|
||||||
count = var.deployment_files.package_config != null ? 1 : 0
|
count = (
|
||||||
|
var.deployment_files.package_config != null
|
||||||
|
&& var.deployment_files.package_config.are_paths_local ? 1 : 0
|
||||||
|
)
|
||||||
name = "dependencies.tar.gz"
|
name = "dependencies.tar.gz"
|
||||||
bucket = local.bucket_name
|
bucket = local.bucket_name
|
||||||
source = try(var.deployment_files.package_config.dependencies_path, null)
|
source = try(var.deployment_files.package_config.dependencies_path, null)
|
||||||
@@ -77,7 +80,10 @@ resource "google_storage_bucket_object" "dependencies" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_storage_bucket_object" "pickle" {
|
resource "google_storage_bucket_object" "pickle" {
|
||||||
count = var.deployment_files.package_config != null ? 1 : 0
|
count = (
|
||||||
|
var.deployment_files.package_config != null
|
||||||
|
&& var.deployment_files.package_config.are_paths_local ? 1 : 0
|
||||||
|
)
|
||||||
name = "pickle.pkl"
|
name = "pickle.pkl"
|
||||||
bucket = local.bucket_name
|
bucket = local.bucket_name
|
||||||
source = try(var.deployment_files.package_config.pickle_path, null)
|
source = try(var.deployment_files.package_config.pickle_path, null)
|
||||||
@@ -87,7 +93,10 @@ resource "google_storage_bucket_object" "pickle" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "google_storage_bucket_object" "requirements" {
|
resource "google_storage_bucket_object" "requirements" {
|
||||||
count = var.deployment_files.package_config != null ? 1 : 0
|
count = (
|
||||||
|
var.deployment_files.package_config != null
|
||||||
|
&& var.deployment_files.package_config.are_paths_local ? 1 : 0
|
||||||
|
)
|
||||||
name = "requirements.txt"
|
name = "requirements.txt"
|
||||||
bucket = local.bucket_name
|
bucket = local.bucket_name
|
||||||
source = try(var.deployment_files.package_config.requirements_path, null)
|
source = try(var.deployment_files.package_config.requirements_path, null)
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ variable "deployment_files" {
|
|||||||
description = "The to source files path and names."
|
description = "The to source files path and names."
|
||||||
type = object({
|
type = object({
|
||||||
package_config = optional(object({
|
package_config = optional(object({
|
||||||
|
are_paths_local = optional(bool, true)
|
||||||
dependencies_path = optional(string, "./src/dependencies.tar.gz")
|
dependencies_path = optional(string, "./src/dependencies.tar.gz")
|
||||||
pickle_path = optional(string, "./src/pickle.pkl")
|
pickle_path = optional(string, "./src/pickle.pkl")
|
||||||
requirements_path = optional(string, "./src/requirements.txt")
|
requirements_path = optional(string, "./src/requirements.txt")
|
||||||
|
|||||||
72
tests/modules/agent_engine/examples/pickle-gcs.yaml
Normal file
72
tests/modules/agent_engine/examples/pickle-gcs.yaml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Copyright 2026 Google LLC
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
values:
|
||||||
|
module.agent_engine.google_project_iam_member.default["roles/aiplatform.user"]:
|
||||||
|
condition: []
|
||||||
|
member: serviceAccount:my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
project: project-id
|
||||||
|
role: roles/aiplatform.user
|
||||||
|
module.agent_engine.google_project_iam_member.default["roles/storage.objectViewer"]:
|
||||||
|
condition: []
|
||||||
|
member: serviceAccount:my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
project: project-id
|
||||||
|
role: roles/storage.objectViewer
|
||||||
|
module.agent_engine.google_project_iam_member.default["roles/viewer"]:
|
||||||
|
condition: []
|
||||||
|
member: serviceAccount:my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
project: project-id
|
||||||
|
role: roles/viewer
|
||||||
|
module.agent_engine.google_service_account.service_account[0]:
|
||||||
|
account_id: my-agent
|
||||||
|
create_ignore_already_exists: null
|
||||||
|
description: null
|
||||||
|
disabled: false
|
||||||
|
display_name: my-agent
|
||||||
|
email: my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
member: serviceAccount:my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
project: project-id
|
||||||
|
timeouts: null
|
||||||
|
module.agent_engine.google_vertex_ai_reasoning_engine.managed[0]:
|
||||||
|
description: Terraform managed.
|
||||||
|
display_name: my-agent
|
||||||
|
encryption_spec: []
|
||||||
|
project: project-id
|
||||||
|
region: europe-west8
|
||||||
|
spec:
|
||||||
|
- agent_framework: google-adk
|
||||||
|
class_methods: null
|
||||||
|
deployment_spec: []
|
||||||
|
package_spec:
|
||||||
|
- dependency_files_gcs_uri: dependencies.tar.gz
|
||||||
|
pickle_object_gcs_uri: pickle.pkl
|
||||||
|
python_version: '3.12'
|
||||||
|
requirements_gcs_uri: requirements.txt
|
||||||
|
service_account: my-agent@project-id.iam.gserviceaccount.com
|
||||||
|
source_code_spec: []
|
||||||
|
timeouts: null
|
||||||
|
module.agent_engine.time_sleep.wait_5_minutes:
|
||||||
|
create_duration: 5m
|
||||||
|
destroy_duration: null
|
||||||
|
triggers: null
|
||||||
|
|
||||||
|
counts:
|
||||||
|
google_project_iam_member: 3
|
||||||
|
google_service_account: 1
|
||||||
|
google_vertex_ai_reasoning_engine: 1
|
||||||
|
modules: 1
|
||||||
|
resources: 6
|
||||||
|
time_sleep: 1
|
||||||
|
|
||||||
|
outputs: {}
|
||||||
Reference in New Issue
Block a user