Skip to content

Enable extensions to participate in infra generate - #10899

Closed
Richard Park (richardpark-msft) wants to merge 12 commits into
Azure:mainfrom
richardpark-msft:azd-infra-gen-for-all
Closed

Richard Park (richardpark-msft) wants to merge 12 commits into
Azure:mainfrom
richardpark-msft:azd-infra-gen-for-all

Conversation

@richardpark-msft

@richardpark-msft Richard Park (richardpark-msft) commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Extensions, like azure.resources need to be able to generate infra (via azd infra generate). For resources, especially, this is a key step for users - it's how they go from the simplified resources they've been using to the more advanced scenarios, where they want to dive into the bicep.

Currently infra gen only works against it's own internal sources, so this PR makes it so you can register an infra gen provider-equivalent, and get called when the user calls infra generate.

@azure-pipelines

azure-pipelines Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
25 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added the ext-x microsoft.azd.extensions developer extension (azd x) label Nov 11, 2026
@richardpark-msft
Richard Park (richardpark-msft) marked this pull request as ready for review November 12, 2026 22:00
Copilot AI max review requested due to automatic review settings November 12, 2026 22:00
@richardpark-msft Richard Park (richardpark-msft) changed the title (DO NOT MERGE) infra gen, for extensions Enable extensions to participate in infra generate Nov 12, 2026
@richardpark-msft

Copy link
Copy Markdown
Member Author

(moving to this PR: #10931, needed to move the branch to Azure/azure-dev for vally evals)

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.

🟡 Changes recommended

An outdated constructor call prevents test compilation, and generation can silently overwrite edited manifests or overwrite another entry’s files through colliding output paths.

8 open issues
What changed in this PR

Enables extensions to participate in azd infra generate independently of provisioning, with azure.resources exporting resource declarations to editable Bicep sources.

Changes:

  • Adds a beta-only generation contract, SDK registration, and authenticated provider routing.
  • Integrates targeted extension activation and validated project configuration updates into infrastructure generation.
  • Implements resources-to-Bicep export with path and overwrite checks, tests, and documentation.

Extension user-contract review: blocked — 14 extension files inspected; 0 new contract comments; review history unavailable for existing-thread verification.

File Description
docs/​reference/​feature-status.md Lists infrastructure generation as beta-only.
docs/​guides/​creating-an-extension.md Documents generator registration and responsibilities.
docs/​architecture/​extension-framework.md Adds generation capability and service documentation.
cli/​azd/​pkg/​project/​infra_generation.go Coordinates generation, validation, and configuration replacement.
cli/​azd/​pkg/​project/​infra_generation_test.go Covers generation and configuration preservation.
cli/​azd/​pkg/​project/​importer.go Adds a comment directing extension generation to the new manager.
cli/​azd/​pkg/​extensions/​validate_registry.go Accepts the generation capability.
cli/​azd/​pkg/​extensions/​resolution.go Maps generation capability to provider type.
cli/​azd/​pkg/​extensions/​resolution_test.go Tests capability and provider-type matching.
cli/​azd/​pkg/​extensions/​registry.go Defines generation capability and provider identifiers.
cli/​azd/​pkg/​azdext/​service_target_preview_manager_test.go Reuses the host receiver lifecycle helper.
cli/​azd/​pkg/​azdext/​provider_registry.go Adds synchronized named-provider registration.
cli/​azd/​pkg/​azdext/​provider_registry_test.go Tests registration, rollback, and concurrency.
cli/​azd/​pkg/​azdext/​provider_manifest.go Checks generator registrations against manifests.
cli/​azd/​pkg/​azdext/​infra_generation_manager.go Routes SDK generation requests to providers.
cli/​azd/​pkg/​azdext/​infra_generation_envelope.go Implements generation message and error handling.
cli/​azd/​pkg/​azdext/​extension_host.go Integrates generators into host lifecycle management.
cli/​azd/​pkg/​azdext/​extension_host_lifecycle_test.go Covers readiness, registration, and shutdown.
cli/​azd/​pkg/​azdext/​contracts/​v1beta/​infra_generation.pb.go Adds generated beta message types.
cli/​azd/​pkg/​azdext/​contracts/​v1beta/​infra_generation_grpc.pb.go Adds generated beta clients and servers.
cli/​azd/​pkg/​azdext/​beta_service_event_manager_test.go Asserts stream cleanup after host shutdown.
cli/​azd/​pkg/​azdext/​azd_client.go Exposes the beta generation client.
cli/​azd/​internal/​grpcserver/​versioned_services.go Supplies the native beta service implementation.
cli/​azd/​internal/​grpcserver/​versioned_services_test.go Verifies beta service registration.
cli/​azd/​internal/​grpcserver/​versioned_services_generated.go Registers the generated beta-only service.
cli/​azd/​internal/​grpcserver/​server.go Adds the generation service dependency.
cli/​azd/​internal/​grpcserver/​server_test.go Updates fixtures and verifies beta-only exposure.
cli/​azd/​internal/​grpcserver/​provider_stream_registry.go Tracks provider ownership by stream.
cli/​azd/​internal/​grpcserver/​provider_stream_registry_test.go Tests ownership, cleanup, and duplicate registration.
cli/​azd/​internal/​grpcserver/​prompt_service_test.go Updates the server fixture.
cli/​azd/​internal/​grpcserver/​project_service_beta_e2e_test.go Updates the server fixture.
cli/​azd/​internal/​grpcserver/​infra_generation_service.go Authorizes providers and forwards generation requests.
cli/​azd/​internal/​grpcserver/​infra_generation_service_test.go Covers authorization, cleanup, and SDK routing.
cli/​azd/​internal/​grpcserver/​beta_event_service_test.go Updates the server fixture.
cli/​azd/​internal/​grpcserver/​account_service_test.go Updates the server fixture.
cli/​azd/​grpc/​README.md Documents the beta generation protocol.
cli/​azd/​grpc/​proto/​azd/​extensions/​v1beta/​infra_generation.proto Defines generation requests, responses, and streaming.
cli/​azd/​extensions/​registry.schema.json Allows generation capability and provider declarations.
cli/​azd/​extensions/​microsoft.azd.extensions/​tools/​proto-generator/​Dockerfile Improves architecture detection and script permission setup.
cli/​azd/​extensions/​extension.schema.json Adds generation manifest authoring support.
cli/​azd/​extensions/​azure.resources/​README.md Documents Bicep export and configuration conversion.
cli/​azd/​extensions/​azure.resources/​main_test.go Checks both manifest provider declarations.
cli/​azd/​extensions/​azure.resources/​internal/​resources/​layers_test.go Uses the shared synthesis function.
cli/​azd/​extensions/​azure.resources/​internal/​resources/​extension.go Exposes synthesis as GenerateFromConfig.
cli/​azd/​extensions/​azure.resources/​internal/​resources/​extension_test.go Updates synthesis tests for the function API.
cli/​azd/​extensions/​azure.resources/​internal/​provider/​provider.go Reuses synthesis during provisioning.
cli/​azd/​extensions/​azure.resources/​internal/​provider/​provider_test.go Updates provisioning fixtures after the synthesis refactor.
cli/​azd/​extensions/​azure.resources/​internal/​provider/​generation.go Writes exported Bicep and returns replacement configuration.
cli/​azd/​extensions/​azure.resources/​internal/​provider/​generation_test.go Covers export, overwrite protection, and path safety.
cli/​azd/​extensions/​azure.resources/​internal/​cmd/​root.go Registers the resources generator.
cli/​azd/​extensions/​azure.resources/​extension.yaml Declares the generation capability and provider.
cli/​azd/​docs/​extensions/​extension-sdk-reference.md Documents generation APIs and ownership rules.
cli/​azd/​docs/​extensions/​extension-framework.md Explains provider activation and generation lifecycle.
cli/​azd/​docs/​extensions/​contract-versioning.md Lists generation among native beta-only services.
cli/​azd/​cmd/​middleware/​middleware_test.go Checks generation listener capability membership.
cli/​azd/​cmd/​middleware/​extensions.go Recognizes generation-capable listeners.
cli/​azd/​cmd/​middleware/​extensions_start_test.go Updates the server fixture.
cli/​azd/​cmd/​middleware/​extension_activator.go Adds targeted generator activation.
cli/​azd/​cmd/​middleware/​extension_activator_test.go Tests generator selection, reuse, and cleanup.
cli/​azd/​cmd/​infra_generate.go Integrates generation dispatch, confirmation, and writing.
cli/​azd/​cmd/​infra_generate_test.go Updates command and overwrite-confirmation tests.
cli/​azd/​cmd/​infra_generate_extension_test.go Covers extension-backed command execution.
cli/​azd/​cmd/​extension_action_test.go Updates the server fixture.
cli/​azd/​cmd/​container.go Registers generation manager and service dependencies.

Review effort: Max

if err := root.MkdirAll(filepath.Dir(name), osutil.PermissionDirectory); err != nil {
return err
}
return root.WriteFile(name, contents, osutil.PermissionFile)
Comment on lines +59 to +61
files, err := resources.GenerateFromConfig(ctx, resources.GenerateRequest{
Name: entry.Name, Config: entry.Config.AsMap(),
})
validationService azdext.ValidationServiceServer,
telemetryService azdext.TelemetryServiceServer,
commandResultService v1beta.CommandResultServiceServer,
infraGenerationService v1beta.InfraGenerationServiceServer,
Comment on lines +141 to +143
if err := runGenerators(ctx, pending); err != nil {
return nil, err
}
Comment on lines +127 to +132
func() project.InfrastructureGenerator {
return &externalInfrastructureGenerator{
extension: extension,
broker: broker,
}
},
return nil, fmt.Errorf("generation cannot combine top-level resources with extension infrastructure entries")
}

projectFile := filepath.Join(config.Path, "azure.yaml")
// entry generates into.
func generationOutputPath(entry provisioning.Options) string {
if entry.Path != "" {
return filepath.ToSlash(entry.Path)

sequence, err := yamlnode.Find(document, sequencePath)
if err != nil {
if entry.Name == "" && entry.Layer == "" {
Copilot AI max review requested due to automatic review settings November 12, 2026 22:22

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.

🟡 Changes recommended

Unresolved critical issues can silently overwrite user-edited infrastructure files and lose saved AI deployment-location mappings, causing subsequent noninteractive provisioning to fail.

10 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid starting generation-only extensions for unrelated commands

cli/​azd/​cmd/​middleware/​extensions.go:34

Adding this capability starts every installed generation-only extension during unrelated commands that use ExtensionsMiddleware, adding a process launch and readiness wait even when no generation occurs. infra generate already activates matching generators through EnsureInfraGenerationProviders, so remove this entry from the general listener list. Update middleware_test.go:908–910 accordingly.

Medium severity Clear broker and provider registrations when closing the host

cli/​azd/​pkg/​azdext/​infra_generation_manager.go:119

Close retains the closed broker, so a later run of the same host reuses a dead stream instead of reconnecting. Reset the broker and clear provider registrations so the same names can be advertised again, matching the cleanup in cli/azd/pkg/azdext/provisioning_manager.go:80–90. Resetting only the broker leaves registration retries failing as duplicates.

Review effort: Max

if !force {
// When the user accepts, generators (including extensions) may overwrite existing files.
var err error
force, err = a.confirmOverwrite(ctx)
Comment on lines +141 to +143
if err := runGenerators(ctx, pending); err != nil {
return nil, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-x microsoft.azd.extensions developer extension (azd x)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants