Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
393 stars 187 forks source link

Running `azd init` on an existing project should allow me to use my existing Bicep files #3039

Open mcollier opened 9 months ago

mcollier commented 9 months ago

Output from azd version azd version 1.5.0 (commit 012ae734904e0c376ce5074605a6d0d3f05789ee)

Describe the bug When attempting to "azd-ify" an existing app, consisting of Python Azure Function code and Bicep, I want AZD to set up the necessary AZD configuration (azure.yaml and AZD environment variables). Currently AZD is taking me through a generation flow to seemingly create new Bicep files. I'd like to use the existing Bicep files in the solution directory.

To Reproduce Assume a directory structure as follows:

.devcontainer/
customskills/
  - functionA/
  - functionB/
  - host.json
  - requirements.txt
infra/
  - modules/
  - main.bicep

Run the azd init command to "azd-ify" an existing app. AZD correctly discovers Python in the customskills folder. However, it assumes that the app should be hosted in Azure Container Apps and prompts to "generate the files necessary to host your app on Azure using Azure Container Apps". I am presented with three options:

I don't want any of the above options, as I already have Bicep files to host my app on Azure Functions.

Expected behavior Allow me to use my existing Bicep files. No additional Bicep files need to be created.

Environment Version: 1.84.2 (user setup) Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e Date: 2023-11-09T10:51:52.184Z Electron: 25.9.2 ElectronBuildId: 24603566 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Windows_NT x64 10.0.23545

Additional context

image

vhvb1989 commented 9 months ago

@weikanglim , is this already supported somehow? or would it be a new feature for easy-init?

weikanglim commented 9 months ago

@mcollier For azdevifying scenarios, have you tried "Select a template -> Minimal"? This will provide the minimal azure.yaml, and gives you a main.bicep.azd with some hints on how to perform azd's resource tagging.

The "initialize from app code" currently assumes "app code only", we can likely bridge the gap over time, but there's definitely more considerations. FYI @savannahostrowski

To put some more concreteness, we've been meaning to make the detection of local projects and generating azure.yaml part of the default bootstrap experience to reduce keystrokes. I think we'll likely want to make some UX adjustments to the prompt options if we want to surface this better -- "Minimal" probably doesn't belong under the template category.

mcollier commented 9 months ago

@weikanglim It didn't occur to me to pursue selecting a minimal template, as I already have the Bicep files (and in an infra folder already, thus aligning with AZD's directory structure).

I was following the doc at Make your project compatible with Azure Developer CLI and the "Use code in the current directory" approach. I assumed that AZD would create the azure.yaml and give me an option to not generate the Bicep since I already had an AZD-compatible directory structure (an existing infra folder with existing .bicep files).

In this case, I'd like azd init to generate the azure.yaml, set up the AZD environment, and get the minimum required environment variables in place.