Skip to content

Add env var for optional fields in prebuilt configs for cloud-sql-mysql #1232

@iofirag

Description

@iofirag

Prerequisites


What are you trying to do that currently feels hard or impossible?

I want to run the official Toolbox Docker image with the prebuilt cloud-sql-mysql configuration, in order to connect to a Cloud SQL MySQL instance under a VPC using private IP.

When I run the image with:

docker run -p 8080:5000 \
    -v "$(pwd)/${GOOGLE_APPLICATION_CREDENTIALS}:/app/credentials.json:ro" \
    -e GOOGLE_APPLICATION_CREDENTIALS="/app/credentials.json" \
    -e CLOUD_SQL_MYSQL_PROJECT="${CLOUD_SQL_MYSQL_PROJECT}" \
    -e CLOUD_SQL_MYSQL_REGION="${CLOUD_SQL_MYSQL_REGION}" \
    -e CLOUD_SQL_MYSQL_INSTANCE="${CLOUD_SQL_MYSQL_INSTANCE}" \
    -e CLOUD_SQL_MYSQL_DATABASE="${CLOUD_SQL_MYSQL_DATABASE}" \
    -e CLOUD_SQL_MYSQL_USER="${CLOUD_SQL_MYSQL_USER}" \
    -e CLOUD_SQL_MYSQL_PASSWORD="${CLOUD_SQL_MYSQL_PASSWORD}" \
    us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest \
    --prebuilt="cloud-sql-mysql" --ui

…it fails with:

ERROR "toolbox failed to initialize: unable to initialize configs:
unable to connect successfully: config error: instance does not have IP of type "PUBLIC"

This happens because the prebuilt configuration assumes a public IP, but my instance only has a private IP.


Workaround

As i saw here https://googleapis.github.io/genai-toolbox/resources/sources/cloud-sql-mysql/
) there is an option to declare ipType in the tools.yaml

So, as a workaround, I copy the cloud-sql-mysql.yaml prebuilt template from your repo
https://github.com/googleapis/genai-toolbox/blob/main/internal/prebuiltconfigs/tools/cloud-sql-mysql.yaml
add ipType: "private", and run with --tools-file instead of --prebuilt.
Example:

sources:
  cloud-sql-mysql-source:
    kind: cloud-sql-mysql
    project: ${CLOUD_SQL_MYSQL_PROJECT}
    region: ${CLOUD_SQL_MYSQL_REGION}
    instance: ${CLOUD_SQL_MYSQL_INSTANCE}
    database: ${CLOUD_SQL_MYSQL_DATABASE}
    user: ${CLOUD_SQL_MYSQL_USER}
    password: ${CLOUD_SQL_MYSQL_PASSWORD}
    ipType: "private"   # <-- added manually
tools:
  execute_sql:
....

This works, but it requires duplicating your prebuilt config just to add one property.


Suggested Solution

Please add support for an environment variable such as IP_TYPE when using --prebuilt="cloud-sql-mysql".

That way, I can run the Docker image without redeclaring the whole YAML:

docker run -p 8080:5000 \
    -v "$(pwd)/${GOOGLE_APPLICATION_CREDENTIALS}:/app/credentials.json:ro" \
    -e GOOGLE_APPLICATION_CREDENTIALS="/app/credentials.json" \
    -e CLOUD_SQL_MYSQL_PROJECT="${CLOUD_SQL_MYSQL_PROJECT}" \
    -e CLOUD_SQL_MYSQL_REGION="${CLOUD_SQL_MYSQL_REGION}" \
    -e CLOUD_SQL_MYSQL_INSTANCE="${CLOUD_SQL_MYSQL_INSTANCE}" \
    -e CLOUD_SQL_MYSQL_DATABASE="${CLOUD_SQL_MYSQL_DATABASE}" \
    -e CLOUD_SQL_MYSQL_USER="${CLOUD_SQL_MYSQL_USER}" \
    -e CLOUD_SQL_MYSQL_PASSWORD="${CLOUD_SQL_MYSQL_PASSWORD}" \
    -e IP_TYPE="private" \
    us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest \
    --prebuilt="cloud-sql-mysql" --ui

This would make it much easier to run Toolbox in private-IP-only environments.


Alternatives Considered

  • Copy-pasting and modifying the prebuilt YAML (works, but not ideal).
  • Using --tools-file exclusively (loses the convenience of --prebuilt).

Additional Details

No response

Metadata

Metadata

Assignees

Labels

priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.status: help wantedStatus: Unplanned work open to contributions from the community.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions