Skip to content

feat(agents): provision terraform project connections#9112

Open
hund030 wants to merge 2 commits into
Azure:mainfrom
hund030:terraform-connections-clean
Open

feat(agents): provision terraform project connections#9112
hund030 wants to merge 2 commits into
Azure:mainfrom
hund030:terraform-connections-clean

Conversation

@hund030

@hund030 hund030 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9111.

Terraform infrastructure eject currently omits azure.ai.connection services declared in azure.yaml. This prevents Terraform-based Foundry projects from provisioning project connections alongside the account and project.

Scope

  • Synthesize azure.ai.connection services into Terraform variables.
  • Generate one azapi_resource per connection under the Foundry project.
  • Preserve connection category, target, auth type, credentials, and metadata.
  • Keep credential values out of Terraform plan output and substitute them safely at provision time.
  • Export provisioned connection names through AZURE_AI_PROJECT_CONNECTION_NAMES.
  • Cover generated Terraform files and credential substitution with unit tests.

Acceptance Criteria

  • An azure.ai.connection service is emitted to infra/connections.tf.
  • azd provision creates the Foundry project connection.
  • Credentials and metadata are passed through without transformation.
  • Projects without connections continue to provision successfully.
  • Terraform outputs include the comma-separated connection names.
  • Credential values are not rendered in Terraform plans.

Validation

  • go test ./internal/cmd -run TestEjectInfra_Terraform_EjectsConnectionServices -count=1
  • go test ./pkg/infra/provisioning/terraform -run TestSubstituteInputParameters -count=1

The Bicep eject path already creates connections at provision time; the
Terraform eject path silently dropped the same `connections` param. Adds
`connections.tf` (an `azapi_resource` for_each, mirroring `acr.tf`'s
`acr_connection`) and forwards `connections` through to main.tfvars.json.
Copilot AI review requested due to automatic review settings July 13, 2026 09:53
@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported identify a customer issue label Jul 13, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution @hund030! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Terraform provisioning for azure.ai.connection services in Foundry projects.

Changes:

  • Generates connection resources and Terraform variables.
  • Exports provisioned connection names.
  • Adds eject-path tests and template embedding coverage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
variables.tf Defines connection inputs.
outputs.tf.tmpl Exports connection names.
connections.tf Provisions Foundry connections.
synthesizer_test.go Verifies template embedding.
init_infra.go Writes connections to tfvars.
init_infra_test.go Tests Terraform eject output.

Comment on lines +18 to +28
body = {
properties = merge(
{
category = each.value.category
target = each.value.target
authType = each.value.authType
},
each.value.credentials != null ? { credentials = each.value.credentials } : {},
each.value.metadata != null ? { metadata = each.value.metadata } : {}
)
}
category = string
target = string
authType = string
credentials = optional(map(any))
Comment on lines +620 to +621
if v, ok := params["connections"]; ok {
doc["connections"] = v
assert.Empty(t, conns)
}

func TestEjectInfra_Terraform_EjectsConnectionServices(t *testing.T) {

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes on top of the existing comments.

No CHANGELOG entry. This extension logs every feature/fix under ## 1.0.0-beta.6 (Unreleased) with the PR number, but this PR doesn't add one. The sibling provision-time PR (#9046) is also absent from the changelog, so if the plan is to track the whole connections feature under a single entry later, ignore this. Otherwise, add a line noting that Terraform eject now synthesizes azure.ai.connection services.

On the already-flagged map(any) credentials comment - that's the one I'd prioritize. connections.bicep types credentials as object?, and the synthesized Go value is map[string]any that can hold nested objects (CustomKeys' keys:). Terraform's map(any) unifies to a single element type, so a project mixing an ApiKey connection ({key: "..."}) with a CustomKeys connection ({keys: {...}}) can fail type conversion or coerce the shape. That undercuts the "supports every auth type" intent. optional(any) keeps parity with the Bicep object? contract.

@JeffreyCA JeffreyCA added the ext-agents azure.ai.agents extension label Jul 13, 2026
Copilot AI review requested due to automatic review settings July 14, 2026 03:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment on lines +769 to +772
var value any
if err := json.Unmarshal(parameters, &value); err != nil {
return "", fmt.Errorf("parsing JSON parameters: %w", err)
}
Comment on lines +614 to +616
// top-level placeholders above: azd's Terraform provider substitutes
// ${...} over the whole file's raw text before parsing it, so nesting
// depth does not matter.
Comment on lines +29 to +33
sensitive_body = each.value.credentials != null ? {
properties = {
credentials = each.value.credentials
}
} : null
Comment on lines +7 to +9
- [[#9112]](https://github.com/Azure/azure-dev/pull/9112) Terraform infrastructure eject now synthesizes
`azure.ai.connection` services into Foundry project connection resources, preserving their category, target,
authentication type, credentials, and metadata.

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier concerns are resolved. Credentials now type as optional(any), so a project mixing an ApiKey connection with a CustomKeys connection round-trips its shape instead of hitting a map(any) type-unification error, and moving them into sensitive_body keeps the values out of terraform plan output. The switch from raw envsubst over the whole file to per-leaf foundry.ExpandEnv is the right call and the new tests cover the quote/newline/${{...}} cases that motivated it.

One thing worth a conscious call before this ships: the credential handling now depends on the reworked core substitution path, but the extension still sets requiredAzdVersion: ">=1.27.0", and those releases predate this change. Bumping it to the azd version that actually carries this substitution rework avoids an install on an older host silently falling back to the raw path for credentials containing quotes or newlines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

customer-reported identify a customer issue ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[azure.ai.agents] Terraform eject does not provision azure.ai.connection services

4 participants