Uh oh!
There was an error while loading. Please reload this page.
docs: fix inaccurate APIs and workflow in Customize Azure resources - #951
docs: fix inaccurate APIs and workflow in Customize Azure resources#951David Pine (IEvangelist) wants to merge 1 commit into
Conversation
The Customize Azure resources page had three concrete inaccuracies that
broke copy-paste use of the snippets:
- The custom Bicep example called `AddAzureBicepResource(name:...,
bicepFilePath:...)`, which doesn't exist. Replace it with the real
`AddBicepTemplate("storage", "./custom-storage.bicep")` API.
- The `PrivateEndpoint` snippet used a fictional `SubnetReference` type
and omitted the required `PrivateLinkServiceConnections`. Fix it to
match the actual `Azure.Provisioning.Network` pattern used by
`AddPrivateEndpoint`, and add an aside pointing readers at that
first-class extension as the recommended path.
- "Open the ./infra directory" is wrong — Bicep is emitted only at
publish time. Replace the steps with `aspire publish -o ./publish`
and accurately describe the emitted `main.bicep` and
`<resource-name>.module.bicep` files.
Also adds a "Bicep samples in the dotnet/aspire repo" link to the See
also list (explicitly requested by the reporter).
Verified:
- pnpm build (Astro + Starlight) passes, starlight-links-validator
reports all internal links valid.
- pnpm test:unit: 163/163 pass, including twoslash-blocks tests.
- Live preview confirms rendered HTML contains AddBicepTemplate, the
AddPrivateEndpoint aside, `aspire publish -o ./publish`, and the
Bicep samples link, with no remaining AddAzureBicepResource.
Fixes#246
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>There was a problem hiding this comment.
Pull request overview
Fixes three concrete inaccuracies on the "Customize Azure resources" docs page: a nonexistent AddAzureBicepResource API, an invalid PrivateEndpoint snippet, and an incorrect "open ./infra" inspection workflow. Also adds a pointer to the first-class AddPrivateEndpoint extension and a link to upstream Bicep samples.
Changes:
- Rewrite the
PrivateEndpointexample to useSubnet.Id+PrivateLinkServiceConnections.Add(...)and add an Aside recommendingAddPrivateEndpoint. - Replace
AddAzureBicepResource(name:, bicepFilePath:)with the realAddBicepTemplate("storage", "./custom-storage.bicep")API. - Replace the "Open
./infra" workflow withaspire publish -o ./publishand add a link to the dotnet/aspire Bicep samples.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Location = "eastus", | ||
| Subnet = new SubnetReference | ||
| var privateEndpoint = new PrivateEndpoint("storagepe"); | ||
| privateEndpoint.Subnet.Id = "/subscriptions/.../subnets/mysubnet"; |
There was a problem hiding this comment.
These properties are BicepValue<ResourceIdentifier>; bare strings don't compile. #942's resource/parameter shape is closer to the product code, so I think this is another reason to consolidate there.
| var storage = builder.AddAzureBicepResource( | ||
| name: "storage", | ||
| bicepFilePath: "./custom-storage.bicep") | ||
| var storage = builder.AddBicepTemplate("storage", "./custom-storage.bicep") |
There was a problem hiding this comment.
Changing this to AddBicepTemplate still leaves the unchanged webapp.WithReference(storage) below with no matching overload. Could we use GetOutput("connectionString") with WithEnvironment, and compile the complete sample?
| 1. Run your AppHost locally. | ||
| 2. Open the `./infra` directory inside your AppHost project. | ||
| 3. Review the generated `.bicep` files to verify your customizations. | ||
| Aspire writes a `main.bicep` for the deployment, plus a `<resource-name>.module.bicep` file per Azure resource, into the output directory you specify. Open each `.module.bicep` to verify that your `ConfigureInfrastructure` changes were applied. |
There was a problem hiding this comment.
This is the intermediate filename, not the published layout. aspire publish writes each module to <resource-name>/<resource-name>.bicep; could we use that path instead?
Fixes#246
Problem
The Customize Azure resources page contains three concrete inaccuracies, each verified against the
dotnet/aspiresource and the live aspire.dev site:builder.AddAzureBicepResource(name: ..., bicepFilePath: ...), which doesn't exist onIDistributedApplicationBuilder. The real API isAddBicepTemplate(name, bicepFile).PrivateEndpointsnippet: The "Add Azure resources to the infrastructure" example usedSubnet = new SubnetReference { Id = ... }(no such type) and omittedPrivateLinkServiceConnections, which is mandatory. The correct pattern (perAzurePrivateEndpointExtensions.cs#L122-L138) ispe.Subnet.Id = "..."; pe.PrivateLinkServiceConnections.Add(new NetworkPrivateLinkServiceConnection { ... }). Also, Aspire ships a first-classAddPrivateEndpointextension that should be the recommended path for this scenario../infradirectory inside your AppHost project" is incorrect. Aspire emits Bicep only at publish time viaaspire publish -o <dir>, producing amain.bicepplus one<resource-name>.module.bicepper Azure resource. No./infra/folder is created at run time.Changes
PrivateEndpointexample (### Add Azure resources to the infrastructure):using Azure.Provisioning.Network;to the snippet.Subnetassignment to useprivateEndpoint.Subnet.Id = "...".PrivateLinkServiceConnections.Add(new NetworkPrivateLinkServiceConnection { Name, PrivateLinkServiceId, GroupIds })call.<Aside type="tip">pointing readers at the first-classAddPrivateEndpointextension fromAspire.Hosting.Azure.Networkas the recommended path.### Use custom Bicep files):AddAzureBicepResource(name: ..., bicepFilePath: ...)with the real APIAddBicepTemplate("storage", "./custom-storage.bicep").### Inspect generated Bicep):./infra" steps with the actual workflow:aspire publish -o ./publish, then inspect the emittedmain.bicepand<resource-name>.module.bicepfiles.Evidence
Before (captured from https://aspire.dev/integrations/cloud/azure/customize-resources/):
After (this PR; verified via local
pnpm previewagainst the rendered HTML):builder.AddBicepTemplate("storage", "./custom-storage.bicep").PrivateEndpointsnippet uses the correctSubnet.Id/PrivateLinkServiceConnections.Add(...)pattern and an Aside points toAddPrivateEndpoint.Terminalcodeblock withaspire publish -o ./publish.How I verified
dotnet/aspire):AddBicepTemplate/AddBicepTemplateStringsignatures fromsrc/Aspire.Hosting.Azure/AzureBicepResourceExtensions.cs.PrivateEndpointusage pattern fromsrc/Aspire.Hosting.Azure.Network/AzurePrivateEndpointExtensions.cs#L122-L138.src/Aspire.Hosting.Azure/AzurePublishingContext.csand the real artifacts inplayground/bicep/BicepSample.AppHost/*.module.bicep.pnpm build(full Astro + Starlight build, 12,226 pages) — passed;starlight-links-validator: All internal links are valid.pnpm test:unit— 163/163 tests passed, includingtwoslash-blocks.vitest.test.ts.pnpm preview+ grep over rendered HTML confirms all four changes (AddBicepTemplate,AddPrivateEndpointaside,aspire publish -o ./publish, Bicep samples link) are present in the final output, with no remaining occurrences ofAddAzureBicepResource.#add-private-endpointsonazure-virtual-networkwas confirmed to resolve by the build's link validator.Out of scope (follow-up candidates)
The reporter also mentioned that the page is "lacking" coverage of customizing parameters/outputs and adding existing resources. That's a content addition rather than a correctness fix, so it's not included here — happy to file a follow-up issue if useful.