Skip to content

Move Foundry remote-tool connection provisioning to Bicep #14

Open

Description

Problem

The postprovision hooks currently create the aigw-github Foundry project connection imperatively with azd ai connection create. Project connections are ARM resources (Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview), so this part of the deployment can potentially be declarative and owned by Bicep.

The original script-based implementation avoided management-plane timing issues and needs the generated AI Gateway API key. Moving it requires a stable, secure way to retrieve and pass that key without exposing it in deployment outputs, logs, or source-controlled configuration.

Proposed work

  • Declare the aigw-github remote-tool project connection in Bicep.
  • Wire its target to the AI Gateway GitHub MCP ToolServer endpoint.
  • Supply the Api-Key custom credential securely from the generated gateway key.
  • Handle the cross-resource-group dependency between the Foundry project and AI Gateway resources.
  • Remove azd ai connection create from both POSIX and PowerShell postprovision hooks after the Bicep path is reliable.
  • Keep toolbox creation in postprovision because toolboxes use the Foundry data-plane API rather than ARM.
  • Keep runtime model-route readiness checks and failed-resource recovery in scripts because they are imperative/data-plane operations.

Acceptance criteria

  • A fresh azd up creates the remote-tool connection without a CLI connection-create step.
  • Re-running azd up is idempotent.
  • The gateway API key is not exposed in Bicep outputs or command logs.
  • The toolbox resolves and attaches the Bicep-created connection successfully.
  • POSIX and Windows deployment paths remain equivalent.
  • Focused deployment/configuration regression coverage and documentation are updated.

Dependency / investigation

Confirm a stable API-key retrieval contract (listSecrets versus listValues) and whether the secret can be referenced safely during ARM deployment before implementing the migration.

Activity

  1. paulyuk commented on Oct 25, 2026

    @paulyuk
    MemberAuthor

    @copilot Please implement this on top of current main (which now provisions Microsoft.ApiManagement/aigateways/apiKeys@2025-09-01-preview (apiKeys/default) declaratively in infra/ai-gateway/main.bicep):

    1. Architecture & Secret Handling:

      • In infra/ai-gateway/main.bicep (or a dedicated child module deployed into the foundry-agents resource group after aiGateway completes), retrieve the generated key from defaultApiKey (Microsoft.ApiManagement/aigateways/apiKeys@2025-09-01-preview) using defaultApiKey.listSecrets().key (and verify whether Bicep/ARM supports listSecrets().key directly on existing or created apiKeys/default without exposing the secret in deployment outputs).
      • Pass the secret only through a @secure() param to a Bicep module scoped to agentsRg that declares Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview named aigw-github (category: 'RemoteTool', authType: 'CustomKeys', target: '${aiGateway.outputs.gatewayUrl}/default/mcp/github/mcp', credentials: { keys: { 'Api-Key': gatewayApiKey } }, isSharedToAll: true, metadata: { type: 'custom_MCP' }).
      • Ensure the gateway API key is never emitted as a Bicep output.
    2. Postprovision Scripts (infra/scripts/configure-ai-gateway.sh & infra/scripts/configure-ai-gateway.ps1):

      • Remove the imperative azd ai connection create call once aigw-github is provisioned by Bicep, while keeping:
        • listSecrets retrieval to save AI_GATEWAY_API_KEY into the local azd environment for local dev (create-dev-env.sh),
        • GitHub MCP toolServers/github registration (which requires the local GH_TOKEN),
        • Model route readiness verification, and
        • Foundry data-plane repo-digest-tools Toolbox creation referencing project_connection_id: "aigw-github".
    3. Tests & Documentation:

      • Update tests/test-ai-gateway-model-registration.sh, IMPLEMENTATION_NOTES.md, and infra/**/README.md to reflect declarative aigw-github connection provisioning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions