Fix azd up --template so it can initialize a new project#1394
Conversation
wbreza
left a comment
There was a problem hiding this comment.
Change looks good for a hotfix & added some feedback on the test.
We should figure out if we need a long term fix for this that still allow us to inject the AzdContext in the commands.
b54bd8b to
ac32fb1
Compare
rajeshkamal5050
left a comment
There was a problem hiding this comment.
Can you also add it to changelog and the version.txt. So that we can do a hot fix from main itself.
In Azure#1296 we changed our logic such that we would inject `AzdContext` as a depenecy of our actions, and expect our IoC container to wire things up. This had the side effect of breaking `azd up --template` to initilize (and then provison and deploy) a new project. The break comes from the fact that the IoC container will call `NewAzdContext` as part of building the `deploy` and `infraCreate` actions, which need to be created because they are dependencies of the `up` composite action. However, `NewAzdContext` should not be called before the project has actually been created (which will happen when the `up` composite action calls the `init` action), because it looks for an existing project and if it doesn't find one it fails. To work around this issue - I've made the infra create and deploy actions explicitly call `NewAzdContext` so the calls can happen at the right time. A regression test has been added (it's a little hacky because we don't actually care about running the `infra create` or `deploy` parts of `up` in this test, we just want to ensure that we correctly initialized via a template. Fixes Azure#1329
ac32fb1 to
5ac503a
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSIContainerDocumentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference (preview)
|
In #1296 we changed our logic such that we would inject
AzdContextas a depenecy of our actions, and expect our IoC container to wire things up.This had the side effect of breaking
azd up --templateto initilize (and then provison and deploy) a new project.The break comes from the fact that the IoC container will call
NewAzdContextas part of building thedeployandinfraCreateactions, which need to be created because they are dependencies of theupcomposite action. However,NewAzdContextshould not be called before the project has actually been created (which will happen when theupcomposite action calls theinitaction), because it looks for an existing project and if it doesn't find one it fails.To work around this issue - I've made the infra create and deploy actions explicitly call
NewAzdContextso the calls can happen at the right time.A regression test has been added (it's a little hacky because we don't actually care about running the
infra createordeployparts ofupin this test, we just want to ensure that we correctly initialized via a template.Fixes #1392