When using azd infra generate with PublishAsAzureContainerApp, bicep module and param files are in split locations and point to incorrect file paths
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
I recently added PublishAsAzureContainerApp to my AppHost project in order to configure specific settings for certain services that are deployed.
However, when using azd infra generate, it generates the appropriate files, it just doesn't put them in the correct places. I'll post an example of my current file structure:
infra/
├── main.bicep
├── main.parameters.json
├── resources.bicep
├── core-service/
│ └── core-service.module.bicep
├── core-service-identity/
│ └── core-service-identity.module.bicep
├── core-service-roles-server-sql/
│ └── core-service-roles-ourservice-sql.module.bicep
aspire/OurSolution.Aspire.AppHost/infra/
├── core-service/
│ └── core-service.tmpl.bicepparam
(other files in root) azure.yaml OurSolution.sln
The generated .bicepparam files use a 'using './core-service.module.bicep' reference at the top - a reference to a file that does not exist (or rather, is in a different location).
Here's the output of the azd infra generate command:
azd infra generate Warning: The following files would be overwritten by generated versions:
- aspire\OurService.Aspire.AppHost\infra\core-service\core-service.tmpl.bicepparam
- infra\core-service\core-service.module.bicep
- infra\core-service-identity\core-service-identity.module.bicep
- infra\core-service-roles-ourservice-sql\core-service-roles-ourservice-sql.module.bicep
- infra\main.bicep
- infra\main.parameters.json
- infra\ourservice-sql\ourservice-sql.module.bicep
- infra\resources.bicep ? What would you like to do with these files? Keep my existing files unchanged
Expected Behavior
The problem with this is that the .bicepparam files that are generated require that the module.bicep files be in the same infra folder as themselves.
The workaround is to manually move the generated files into the same folder as the .bicepparam files after generation.
Steps To Reproduce
Create a project that matches our project's file structure, initialize a new .NET project via aspire, then add .PublishAsAzureContainerApp with any config (like CPU/Memory) to its configuration. Then, run azd infra generate.
Exceptions (if any)
This worked well enough when we were using the previously generated .tmpl.yaml files that are generated when PublishAsAzureContainerApp is not used, because that all is contained in a single file (even though it was in a separate infra folder location).
.NET Version info
9.0.301
Anything else?
.NET Aspire version 9.3.2 .NET 9
Can you provide a repro project?
Can you provide a repro project?
Unfortunately, this project is hosted entirely in a private ADO repository by our company.
I'd be glad to provide you as much as I can, anonymized.
If you can make a project that reproduces the problem, that would be enough for us to figure out how to fix it. It doesn't reproduce with any project so figuring out the delta would be super helpful (and avoid us playing telephone 😄).
If you can make a project that reproduces the problem, that would be enough for us to figure out how to fix it. It doesn't reproduce with any project so figuring out the delta would be super helpful (and avoid us playing telephone 😄).
I've set up a brand new public project that simulates our folder structure and recreated the bug. Again, let me know if you need anything more!
https://github.com/antiphon0/AspireExampleApp/tree/main
cc @vhvb1989
@antiphon0 it seems like you're running from the repository root and that might be causing the issue yeah?
Hello @antiphon0, I was able to reproduce the issue you mentioned. Thank you for creating and sharing that sample repo.
From AZD perspective, this is working as expected. If you run azd up after azd infra generate, azd will not return and errors and will publish your app to Azure:
As @davidfowl mentioned, the file structure you see after azd infra generate is becase you are running azd from the top of you repo, next to the aspire folder. People usually runs AZD inside the AppHost folder (azd init + azd up) and have the azure.yaml created inside the AppHost folder.
However, AZD supports running from both, the root and inside the AppHost folder, but infra generate is distributing the files the way you see.
You might want to try running from inside the AppHost folder.
Also, you might want to fully switch to Aspire taking control of the environment by using builder.AddAzureContainerAppEnvironment("infra"); @davidfowl should have links to docs about it and notes about why this would be better
@vhvb1989 Thanks for your excellent reply - just tested by moving a modified copy (had to update file path to the AppHost project) of the azure.yaml into the apphost and ran azd infra gen while inside the AppHost folder and it put the modules and templates where I expected.
For additional context, I'm using the commands I'm using because they're the ones used in the default Azure DevOps pipeline for Aspire - I typically do this process: azd infra gen (getting changes if a new resource was added, while maintaining the manual modifications I have to make for things I'm not 100% on how to configure via the AppHost) azd provision --preview (just as a sanity check) azd provision (used in pipeline) azd deploy (used in pipeline)
Definitely willing to chalk it up to Aspire ignorance (I'm a DevOps person picking up Aspire/.NET to make deployments work across environments and resource groups properly, with the naming scheme that I want, with different scaling settings per env, and also accounting for per-environment app configs, etc), so I thank you for pointing me in the right direction, and am definitely looking forward to the information about .AddAzureContainerAppEnvironment.