Files
hunfabric/modules/agent-engine
Julio Castillo 2eaa0d5e27 Add support for dynamic tags (#3897)
* Allow creation of dynamic tags

* Extend project factory and related modules to support dynamic values

* Extend folder and organization modules

* project and organization readme

* Simplify dynamic tag support and remove unnecessary restrictions

  • Schemas & Validations: Removed the restriction that forbade combining IAM fields with  allowed_values_regex  on tags. Updated validations in  project  and  organization  modules, and
  simplified all relevant JSON schemas.
  • Module Tag Bindings: Simplified the  tag_value  assignment in  folder ,  project ,  gcs ,  bigquery-dataset , and  kms  modules by removing the defensive  can(regex(...))  check and
  calling  templatestring  directly.
  • Outputs: Removed the  tags_dynamic  output from  project  and  organization  modules, as the same information is now available in  tag_keys .
  • Project Factory: Updated  tag_vars_projects  in  projects.tf  to use the native  namespaced_name  attribute and filtered manually for dynamic tags.

* fix(organization, project): fix linting and tests for dynamic tag support

- Align allowed_values_regex and description extraction in _tags_merged
  locals to use lookup() for consistency with other fields.
- Fix spacing in project context variable (alphabetical ordering).
- Update organization tags test to include the new cost_center tag key
  with allowed_values_regex.
- Update project tags test to include the new cost_center tag key and
  reflect the resolved allowed_values_regex on environment.

* refactor(gcs): refine tag bindings and fix context test

- Add _tag_bindings local to pre-resolve context references, enabling
  templatestring to receive a direct map reference (required by Terraform).
- Use var.context.tag_vars instead of the non-existent local.ctx.tag_vars.
- Fix HCL syntax in context.tfvars (escaped inner quotes).
- Update context test inventory to reflect 3 tag bindings including a
  dynamic value resolved via templatestring.

* refactor: align modules with tag binding context pattern

- Add _tag_bindings local + templatestring dance to cloud-run-v2,
  compute-vm, folder, kms modules (bigquery-dataset already had it)
- Exclude tag_vars from local.ctx in cloud-run-v2, compute-vm, folder,
  kms, project modules (bigquery-dataset already had it)
- Add tag_vars to context variable in cloud-run-v2, compute-vm modules
  (others already had it)
- Update all context tests with dynamic tag binding values using
  var.context.tag_vars

* docs: add module-level tftest.yaml test instructions to GEMINI.md

* docs: regenerate READMEs after tag-regex alignment

- Regenerate variable tables in 7 module READMEs to reflect
  line number shifts from prior tag-regex changes
- Add tag_vars exclusion to gcs ctx local
- Fix whitespace alignment in iam-service-account and
  project-factory tag_vars blocks
- Update tftest resource counts for organization and project
- Remove tags_dynamic from organization/project output tables

* fix(project-factory): update test inventory for tag_bindings module split

- Move tag binding address from folder-2 to folder-2-iam in test
  inventory (tag_bindings moved from creation to IAM modules)
- Update module instance count from 34 to 35
- Regenerate README tables after terraform fmt line shifts
- Apply terraform fmt to variables.tf

* refactor(project-factory): remove unnecessary depends_on from folder-iam modules

Folder IAM modules depend on their own folder creation modules, not
on module.projects. The explicit depends_on was leftover from an
earlier design.

* FAST stages

* Address review comments.

- FAST Stages:
  - Added tag_keys to output-files.tf in 0-org-setup to pass org tags via tfvars.
  - Sorted tag_keys and tag_values in output-files.tf.
  - Updated project-factory, networking, and security stages to use tag_keys.
  - Filtered tag_keys for dynamic tags only.
- Modules:
  - Excluded tag_vars from local.ctx in iam-service-account and organization.
  - Simplified tag_value in iam-service-account.
- Tests:
  - Updated test inventories for 0-org-setup and project-factory.

* Fix tf format

* Fix tfdoc

* docs: add ADR for templatestring vars convention and update status of base path ADR

* More tfdoc

* Update schemas

* Use endswith in context loop

* Address review

* Update FAST readmes

* Update last modules

* Terraform fmt

* Revert alloydb

* Fix whitespace

---------

Co-authored-by: Ludovico Magnocavallo <ludo@qix.it>
2026-04-24 20:45:45 +00:00
..
2026-04-24 20:45:45 +00:00

Agent Engine Module

The module creates Agent Engine and related dependencies.

  • It supports both source based deployments (aka in-line deployment) and serialized object deployment (aka pickle deployment).
  • For serialized object deployment, the module creates a GCS bucket to store the pickled object and related dependencies.
  • It supports Customer Managed Encryption Keys (CMEK) to encrypt both the reasoning engine and the GCS bucket.
  • It provides support for both managed and unmanaged (Terraform doesn't track updates to code) deployments.
  • It provides support for VPC-SC (via PSC-I).
  • It provides support for custom and default service accounts.
  • It provides support for environment variables and secrets from Secret Manager.
  • It supports both Python-based and container-based deployments.

TOC

Minimal deployment

This example shows how to deploy an agent engine with minimal configuration, using source code from a local path.

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }
}
# tftest inventory=minimal.yaml

You can change the name of the tar.gz package, of the requirement file, the name of the Python file and the name of the agent function by using the deployment_config.source_files_config variable.

You can also provide custom build arguments for the container image by using the deployment_config.source_files_config.image_spec variable.

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
      image_spec = {
        build_args = {
          "ENV" = "production"
        }
      }
    }
  }
}
# tftest inventory=image-spec.yaml

Serialized Object Deployment

You can also manually serialize your agent by using the cloudpickle library and pass the pickle.pkl, dependencies.tar.gz and requirements.txt files to the module.

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"
  }

  deployment_config = {
    package_config = {
      pickle_path       = "assets/src/pickle.pkl"
      dependencies_path = "assets/src/dependencies.tar.gz"
      requirements_path = "assets/src/requirements.txt"
    }
  }
}
# tftest inventory=minimal-pickle.yaml

If the files are already in a GCS bucket, you can pass the GCS URIs to the module.

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"
  }

  deployment_config = {
    package_config = {
      are_paths_local   = false
      pickle_path       = "gs://my-bucket/pickle.pkl"
      dependencies_path = "gs://my-bucket/dependencies.tar.gz"
      requirements_path = "gs://my-bucket/requirements.txt"
    }
  }
}
# tftest inventory=pickle-gcs.yaml

Unmanaged deployments

If you want to use the module just to bootstrap the infrastructure and then manage the code updates yourself, you can set the managed variable to false.

module "agent_engine" {
  source     = "./fabric/modules/agent-engine"
  name       = "my-agent"
  project_id = var.project_id
  region     = var.region
  managed    = false

  agent_engine_config = {
    agent_framework = "google-adk"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }
}
# tftest inventory=unmanaged.yaml

Service accounts

You can choose to use a custom service account or let the module create one for you.

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }
}
# tftest inventory=sa-default.yaml

Using a custom service account.

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }

  service_account_config = {
    create = false
    email  = "my-agent@project-id.iam.gserviceaccount.com"
  }
}
# tftest inventory=sa-custom.yaml

Private networking: setup PSC-I

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }

  networking_config = {
    network_attachment_id = "projects/project-id/regions/europe-west8/networkAttachments/my-nat"
    dns_peering_configs = {
      "googleapis.com." = {
        target_network_name = "my-network"
      }
    }
  }
}
# tftest inventory=psc-i.yaml

Specify an encryption key

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }

  encryption_key = "projects/project-id/locations/europe-west8/keyRings/my-keyring/cryptoKeys/my-key"
}
# tftest inventory=encryption.yaml

Define environment variables and use secrets

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"
    environment_variables = {
      FOO = "bar"
    }
    secret_environment_variables = {
      MY_SECRET = {
        secret_id = "projects/project-id/secrets/my-secret"
      }
    }
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }
}
# tftest inventory=environment.yaml

Container-based deployment

You can deploy your agent as a custom Docker image.

module "agent_engine" {
  source     = "./fabric/modules/agent-engine"
  name       = "my-agent"
  project_id = var.project_id
  region     = var.region

  agent_engine_config = {
    environment_variables = {
      FOO = "bar"
    }
  }

  deployment_config = {
    container_config = {
      image_uri = "us-central1-docker.pkg.dev/my-project/my-repo/my-image:latest"
    }
  }
}
# tftest inventory=container.yaml

Memory Bank

You can optionally configure a Memory Bank to provide long-term persistent memory for your agent.

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"
  }

  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }

  memory_bank_config = {
    disable_memory_revisions = false
    generation_config = {
      model = "projects/my-project/locations/us-central1/publishers/google/models/gemini-2.0-flash-001"
    }
    similarity_search_config = {
      embedding_model = "projects/my-project/locations/us-central1/publishers/google/models/text-embedding-005"
    }
    ttl_config = {
      default_ttl = "2592000s" # 30 days
    }
  }
}

Getting values from context

The module allows you to dynamically reference context values for resources created outside this module, through the context variable. This includes the definition of custom roles, iam_principals, locations, networks, psc_network_attachments, kms_keys, models and project ids.

module "agent_engine" {
  source     = "./fabric/modules/agent-engine"
  name       = "my-agent"
  project_id = "$project_ids:main-project"
  region     = "$locations:primary"
  agent_engine_config = {
    agent_framework = "google-adk"
  }
  deployment_config = {
    source_files_config = {
      source_path = "assets/src/source.tar.gz"
    }
  }
  networking_config = {
    network_attachment_id = "$psc_network_attachments:primary"
    dns_peering_configs = {
      "example.com" = {
        target_network_name = "$networks:vpc-1"
      }
      "my-company.local" = {
        target_network_name = "$networks:vpc-2"
        target_project_id   = "$project_ids:dns-project"
      }
    }
  }
  service_account_config = {
    create = false
    email  = "$iam_principals:my-custom-sa"
  }
  context = {
    iam_principals = {
      my-custom-sa = "my-sa@$test-project-1.iam.gserviceaccount.com"
    }
    locations = {
      primary = "europe-west1"
    }
    networks = {
      vpc-1 = "my-vpc-1"
      vpc-2 = "my-vpc-2"
    }
    project_ids = {
      main-project = "test-project-1"
      dns-project  = "company-dns-project"
    }
    psc_network_attachments = {
      primary = "projects/test-project-1/regions/europe-west1/networkAttachments/core-service"
    }
  }
}
# tftest inventory=context.yaml

Disable deletion protection

By default you can't neither delete your agent if it has session or your GCS bucket if it has files inside. For testing, you can anyway force the deletion of these resources:

module "agent_engine" {
  source                     = "./fabric/modules/agent-engine"
  name                       = "my-agent"
  project_id                 = var.project_id
  region                     = var.region
  enable_deletion_protection = false

  agent_engine_config = {
    agent_framework = "google-adk"
  }

  deployment_config = {
    package_config = {
      pickle_path       = "assets/src/pickle.pkl"
      dependencies_path = "assets/src/dependencies.tar.gz"
      requirements_path = "assets/src/requirements.txt"
    }
  }
}
# tftest inventory=deletion-protection.yaml

Variables

name description type required default
name The name of the agent. string
project_id The id of the project where to deploy the agent. string
region The region where to deploy the agent. string
agent_engine_config The agent configuration. Supported values for agent_framework: 'google-adk', 'langchain', 'langgraph', 'ag2', 'llama-index', 'custom'. object({…}) {}
bucket_config The GCS bucket configuration. object({…}) {}
context Context-specific interpolations. object({…}) {}
deployment_config The deployment configuration. object({…}) {}
description The Agent Engine description. string "Terraform managed."
enable_deletion_protection Whether deletion protection should be enabled. bool true
encryption_key The full resource name of the Cloud KMS CryptoKey. string null
managed Whether the Terraform module should control the code updates. bool true
memory_bank_config Configuration for the memory bank. object({…}) null
networking_config Networking configuration. object({…}) null
service_account_config Service account configurations. object({…}) {}

Outputs

name description sensitive
agent The Agent Engine object.
id Fully qualified Agent Engine id.
service_account Service account resource.