$npx -y skills add VeerMuchandi/rad-skills --skill agent_engine_terraform_deployerDeploys ADK agents to Vertex AI Agent Engine using the standard Terraform pattern.
| 1 | # Agent Engine Terraform Deployer Skill |
| 2 | |
| 3 | This skill helps you deploy your Agent Development Kit (ADK) agent to Vertex AI Agent Engine using a robust, self-contained Terraform pattern. It implements the "Golden Project Structure" and automated packaging logic recommended by the ADK team. |
| 4 | |
| 5 | ## Official References |
| 6 | - **Module Source:** [github.com/GoogleCloudPlatform/cloud-foundation-fabric/modules/agent-engine](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/tree/master/modules/agent-engine) |
| 7 | - **Documentation:** [Agent Engine Module README](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/blob/master/modules/agent-engine/README.md) |
| 8 | |
| 9 | ## Capabilities |
| 10 | - **Intelligent Preparation**: Intelligently scans and updates `.ae_ignore`, `requirements.txt`, and `.env` for deployment readiness. |
| 11 | - **Initialize Deployment**: Sets up a `deploy/` directory with the golden `main.tf` template. |
| 12 | - **Support for Multiple Sources**: |
| 13 | - **Local Source**: Deploys from your local machine (ideal for dev). |
| 14 | - **GitHub Source**: Deploys directly from a GitHub repository (ideal for CI/CD). |
| 15 | - **Auto-Packaging**: Automatically packages your agent code, excluding bulky files. |
| 16 | - **Non-Intrusive Wrapping**: Dynamically generates an `app.py` wrapper during deployment. |
| 17 | |
| 18 | ## Prerequisites |
| 19 | - **Terraform Version**: |
| 20 | - **Minimum**: `v1.12.2` |
| 21 | - **Recommended**: `v1.14.4` |
| 22 | - [Download Terraform](https://releases.hashicorp.com/terraform/) if needed. |
| 23 | - **GCP Project**: Access to a Google Cloud Project with billing enabled. |
| 24 | - **Permissions**: |
| 25 | - `roles/aiplatform.user` |
| 26 | - `roles/storage.objectViewer` |
| 27 | - `roles/serviceusage.serviceUsageConsumer` |
| 28 | - `roles/cloudtrace.agent` |
| 29 | |
| 30 | ## 1. Golden Project Structure |
| 31 | Always separate your deployment logic from your agent code. This prevents Terraform from accidentally zipping up its own bulky provider binaries. |
| 32 | |
| 33 | ```text |
| 34 | my_project/ |
| 35 | ├── .ae_ignore # Patterns to exclude (caching, env files, etc.) |
| 36 | ├── my_agent_package/ # YOUR AGENT FOLDER (must have __init__.py) |
| 37 | │ ├── agent.py # Root agent logic |
| 38 | │ ├── requirements.txt # Dependencies |
| 39 | │ └── ... |
| 40 | └── deploy/ # DEDICATED DEPLOYMENT FOLDER |
| 41 | └── main.tf # Self-contained Terraform logic |
| 42 | ``` |
| 43 | |
| 44 | ## 2. Configuration Reference |
| 45 | |
| 46 | ### Environment Variables (.env) |
| 47 | Ensure your agent's `.env` includes the following for proper observability: |
| 48 | ```bash |
| 49 | # Enables agent traces and logs (excludes prompts/responses) |
| 50 | GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY=true |
| 51 | |
| 52 | # Enables logging of input prompts and output responses |
| 53 | OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true |
| 54 | ``` |
| 55 | |
| 56 | ### Dependencies (requirements.txt) |
| 57 | Your agent's `requirements.txt` **MUST** include: |
| 58 | ```text |
| 59 | google-cloud-aiplatform[agent_engines,adk] |
| 60 | ``` |
| 61 | |
| 62 | ## 3. Workflow |
| 63 | |
| 64 | ### Step 0: Intelligent Agent Preparation (Automated) |
| 65 | Instead of manually creating files, run the provided helper script. It will intelligently scan your agent directory and generate/update `.ae_ignore`, `requirements.txt`, and `.env` with the correct configurations. |
| 66 | |
| 67 | ```bash |
| 68 | # Run the preparation script pointing to your agent directory (replace /path/to/your/agent) |
| 69 | python3 scripts/prepare_agent.py /path/to/your/agent |
| 70 | ``` |
| 71 | |
| 72 | This script will: |
| 73 | 1. **Exclude Junk**: Add robust exclusions to `.ae_ignore` (git, venve, terraform, `*.zip`, `*.pkl`, etc.). |
| 74 | 2. **Ensure Dependencies**: Add `google-cloud-aiplatform[agent_engines,adk]` to `requirements.txt` if missing. |
| 75 | 3. **Enable Telemetry**: Inject observability env vars into `.env` if not present. |
| 76 | |
| 77 | ### Option A: Local Deployment (Development) |
| 78 | Use this when you have the code on your machine. |
| 79 | |
| 80 | 1. **Initialize**: |
| 81 | ```bash |
| 82 | mkdir -p deploy |
| 83 | # Copy templates/main_local.tf to deploy/main.tf |
| 84 | ``` |
| 85 | 2. **Configure** (`deploy/terraform.tfvars`): |
| 86 | ```hcl |
| 87 | project_id = "your-project-id" |
| 88 | region = "us-central1" |
| 89 | agent_engine_name = "epp-telecom-concierge" |
| 90 | agent_folder_name = "epp_telecom_concierge" |
| 91 | ``` |
| 92 | 3. **Deploy**: |
| 93 | ```bash |
| 94 | cd deploy && terraform init && terraform apply |
| 95 | ``` |
| 96 | |
| 97 | ### Option B: GitHub Deployment (CI/CD) |
| 98 | Use this to deploy code from a remote repository. |
| 99 | |
| 100 | 1. **Initialize**: |
| 101 | ```bash |
| 102 | mkdir -p deploy |
| 103 | # Copy templates/main_github.tf to deploy/main.tf |
| 104 | ``` |
| 105 | 2. **Configure** (`deploy/terraform.tfvars`): |
| 106 | ```hcl |
| 107 | project_id = "your-project-id" |
| 108 | region = "us-central1" |
| 109 | agent_engine_name = "epp-telecom-concierge" |
| 110 | github_repo = "username/repo" |
| 111 | github_branch = "main" |
| 112 | agent_package_name = "epp_telecom_concierge" |
| 113 | ``` |
| 114 | 3. **Deploy**: |
| 115 | ```bash |
| 116 | cd deploy && terraform init && terraform apply |
| 117 | ``` |
| 118 | |
| 119 | ## 4. Critical Learnings & Troubleshooting |
| 120 | |
| 121 | ### A. The "ResourceExhausted" (256MB) Limit |
| 122 | **The Issue**: Terraform's `inline_source` |