$npx -y skills add VeerMuchandi/rad-skills --skill cloud_scheduler_setupProvisions a scheduled Cloud Scheduler job with secure OIDC token authentication to invoke HTTP targets (such as Reasoning Engine endpoints) using Terraform.
| 1 | # Cloud Scheduler Setup Skill |
| 2 | |
| 3 | This skill allows you to easily provision a scheduled cron job using Cloud Scheduler on Google Cloud Platform via Terraform. It automatically enables required APIs, configures a secure HTTP target call, and hooks up secure OIDC token authentication using a specified service account to allow triggering private endpoints (like Vertex AI Reasoning Engines). |
| 4 | |
| 5 | ## Prerequisites |
| 6 | - **Terraform Version**: `v1.5+` (Recommended `v1.14+`) |
| 7 | - **GCP Project**: Active Google Cloud Project with billing enabled. |
| 8 | - **Permissions**: |
| 9 | - `roles/cloudscheduler.admin` (to manage Cloud Scheduler) |
| 10 | - `roles/serviceusage.serviceUsageConsumer` (to enable services) |
| 11 | - The target Service Account must have `roles/iam.serviceAccountUser` assigned or be callable by the scheduler. |
| 12 | |
| 13 | ## Skill Directory Structure |
| 14 | ```text |
| 15 | cloud_scheduler_setup/ |
| 16 | ├── SKILL.md # This instructions file |
| 17 | ├── resources/ |
| 18 | │ └── templates/ |
| 19 | │ ├── main.tf # Core Cloud Scheduler resources |
| 20 | │ ├── variables.tf # Customizable variables |
| 21 | │ └── outputs.tf # Job name and state outputs |
| 22 | └── scripts/ |
| 23 | └── deploy_scheduler.py # Helper Python script to orchestrate deployment |
| 24 | ``` |
| 25 | |
| 26 | ## 1. How to Use this Skill (Step-by-Step) |
| 27 | |
| 28 | ### Step 1: Initialize the Deployment Workspace |
| 29 | Create a dedicated deployment directory outside your agent code package to prevent Terraform state/binaries from being packaged with the agent. |
| 30 | |
| 31 | ```bash |
| 32 | mkdir -p deploy_scheduler |
| 33 | ``` |
| 34 | |
| 35 | ### Step 2: Copy the Templates |
| 36 | Copy the templates from this skill to your new `deploy_scheduler` folder. |
| 37 | *(Note: Replace `<path_to_skill>` with the path of this skill folder, e.g. `skills/cloud_scheduler_setup`)* |
| 38 | |
| 39 | ```bash |
| 40 | cp -r <path_to_skill>/resources/templates/* deploy_scheduler/ |
| 41 | ``` |
| 42 | |
| 43 | ### Step 3: Configure Deployment (`deploy_scheduler/terraform.tfvars`) |
| 44 | Create a file named `deploy_scheduler/terraform.tfvars` and set the following parameters: |
| 45 | |
| 46 | ```hcl |
| 47 | project_id = "your-gcp-project-id" |
| 48 | region = "us-central1" |
| 49 | job_name = "my-daily-agent-trigger" |
| 50 | schedule = "0 9 * * *" # Daily at 9:00 AM |
| 51 | time_zone = "America/New_York" |
| 52 | target_uri = "https://us-central1-aiplatform.googleapis.com/v1/projects/your-gcp-project-id/locations/us-central1/reasoningEngines/your-engine-id:streamQuery" |
| 53 | http_method = "POST" |
| 54 | body = "{\"class_method\": \"stream_query\", \"input\": {\"message\": \"Process daily sales data\"}}" |
| 55 | service_account_email = "your-agent-service-account@your-gcp-project-id.iam.gserviceaccount.com" |
| 56 | ``` |
| 57 | |
| 58 | ### Step 4: Run Terraform |
| 59 | Navigate to the `deploy_scheduler` directory, initialize, and deploy the resources: |
| 60 | |
| 61 | ```bash |
| 62 | cd deploy_scheduler |
| 63 | terraform init |
| 64 | terraform apply -auto-approve |
| 65 | ``` |
| 66 | |
| 67 | ### Step 5: Capture Output |
| 68 | Upon successful completion, Terraform outputs the created job ID and state: |
| 69 | ```hcl |
| 70 | job_id = "projects/your-project/locations/us-central1/jobs/my-daily-agent-trigger" |
| 71 | job_state = "ENABLED" |
| 72 | ``` |
| 73 | |
| 74 | --- |
| 75 | |
| 76 | ### Option B: Using the Orchestration Helper Script (Recommended) |
| 77 | You can automate the deployment in a single step using the helper Python script. |
| 78 | |
| 79 | Run the script: |
| 80 | ```bash |
| 81 | python3 <path_to_skill>/scripts/deploy_scheduler.py \ |
| 82 | --project "your-gcp-project-id" \ |
| 83 | --job-name "my-daily-agent-trigger" \ |
| 84 | --schedule "0 9 * * *" \ |
| 85 | --target-uri "https://us-central1-aiplatform.googleapis.com/v1/projects/your-project/locations/us-central1/reasoningEngines/your-engine-id:streamQuery" \ |
| 86 | --service-account "your-service-account@your-project.iam.gserviceaccount.com" \ |
| 87 | --body "{\"class_method\": \"stream_query\", \"input\": {\"message\": \"Process daily sales data\"}}" \ |
| 88 | --work-dir "deploy_scheduler" |
| 89 | ``` |
| 90 | |
| 91 | To destroy the job later: |
| 92 | ```bash |
| 93 | python3 <path_to_skill>/scripts/deploy_scheduler.py \ |
| 94 | --project "your-gcp-project-id" \ |
| 95 | --job-name "my-daily-agent-trigger" \ |
| 96 | --schedule "0 9 * * *" \ |
| 97 | --target-uri "https://us-central1-aiplatform.googleapis.com/v1/projects/your-project/locations/us-central1/reasoningEngines/your-engine-id:streamQuery" \ |
| 98 | --service-account "your-service-account@your-project.iam.gserviceaccount.com" \ |
| 99 | --work-dir "deploy_scheduler" \ |
| 100 | --destroy |
| 101 | ``` |
| 102 | |
| 103 | --- |
| 104 | |
| 105 | ## 2. Best Practices & Security |
| 106 | - **OIDC Token Auth**: Always specify a service account with the minimal roles required to call the target endpoint (e.g. `roles/aiplatform.user` for Vertex AI Agent Engine). |
| 107 | - **Deadlines**: The default deadline is set to `320s` to accommodate longer-running Reasoning Engine tasks (e.g. processing large GCS datasets or running database migrations). |