Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azd down] ux updates #1924

Merged
merged 21 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions cli/azd/cmd/actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,15 @@ type ActionInitializer[T Action] func() (T, error)
func ToUxItem(actionResult *ActionResult, err error) ux.UxItem {
if err != nil {
return &ux.ActionResult{
SuccessMessage: "",
FollowUp: "",
Err: err,
Err: err,
}
}

if actionResult == nil {
return &ux.ActionResult{
SuccessMessage: "",
FollowUp: "",
Err: nil,
}
return &ux.ActionResult{}
}
if actionResult.Message == nil {
return &ux.ActionResult{
SuccessMessage: "",
FollowUp: "",
Err: nil,
}
return &ux.ActionResult{}
}
return &ux.ActionResult{
SuccessMessage: actionResult.Message.Header,
Expand Down
61 changes: 44 additions & 17 deletions cli/azd/cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
"github.com/azure/azure-dev/cli/azd/pkg/input"
"github.com/azure/azure-dev/cli/azd/pkg/output"
"github.com/azure/azure-dev/cli/azd/pkg/output/ux"
"github.com/azure/azure-dev/cli/azd/pkg/project"
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -97,34 +98,38 @@ func newDownAction(
}

func (a *downAction) Run(ctx context.Context) (*actions.ActionResult, error) {
infraManager, err := provisioning.NewManager(
ctx,
a.env,
a.projectConfig.Path,
a.projectConfig.Infra,
a.console.IsUnformatted(),
a.azCli,
a.console,
a.commandRunner,
a.accountManager,
a.userProfileService,
a.subResolver,
a.alphaFeatureManager,
)

// silent manager for running Plan()
infraManager, err := createProvisioningManager(ctx, a, &project.MutedConsole{ParentConsole: a.console})
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, fmt.Errorf("creating provisioning manager: %w", err)
}

// Command title
a.console.MessageUxItem(ctx, &ux.MessageTitle{
Title: "Deleting all resources and deployed code on Azure (azd down)",
TitleNote: "Local application code is not deleted when running 'azd down'.",
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
})

spinnerMsg := "Fetching resources groups."
a.console.ShowSpinner(ctx, spinnerMsg, input.Step)

deploymentPlan, err := infraManager.Plan(ctx)
a.console.StopSpinner(ctx, spinnerMsg, input.GetStepResultFormat(err))
a.console.Message(ctx, "")
if err != nil {
return nil, fmt.Errorf("planning destroy: %w", err)
}

// re-create manager with output capabilities to handle output
infraManager, err = createProvisioningManager(ctx, a, a.console)
if err != nil {
return nil, fmt.Errorf("creating provisioning manager: %w", err)
}

destroyOptions := provisioning.NewDestroyOptions(a.flags.forceDelete, a.flags.purgeDelete)
destroyResult, err := infraManager.Destroy(ctx, &deploymentPlan.Deployment, destroyOptions)
if err != nil {
return nil, fmt.Errorf("destroying infrastructure: %w", err)
return nil, fmt.Errorf("deleting infrastructure: %w", err)
}

// Remove any outputs from the template from the environment since destroying the infrastructure
Expand All @@ -137,7 +142,29 @@ func (a *downAction) Run(ctx context.Context) (*actions.ActionResult, error) {
return nil, fmt.Errorf("saving environment: %w", err)
}

return nil, nil
return &actions.ActionResult{
Message: &actions.ResultMessage{
Header: "Your Azure resources have been deleted.",
},
}, nil
}

func createProvisioningManager(ctx context.Context, a *downAction, console input.Console) (*provisioning.Manager, error) {
infraManager, err := provisioning.NewManager(
ctx,
a.env,
a.projectConfig.Path,
a.projectConfig.Infra,
a.console.IsUnformatted(),
a.azCli,
console,
a.commandRunner,
a.accountManager,
a.userProfileService,
a.subResolver,
a.alphaFeatureManager,
)
return infraManager, err
}

func getCmdDownHelpDescription(*cobra.Command) string {
Expand Down
5 changes: 3 additions & 2 deletions cli/azd/cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ func (p *provisionAction) Run(ctx context.Context) (*actions.ActionResult, error

return &actions.ActionResult{
Message: &actions.ResultMessage{
Header: "Your project has been provisioned!",
FollowUp: getResourceGroupFollowUp(ctx, p.formatter, p.projectConfig, p.resourceManager, p.env),
Header: "Your project has been provisioned!",
FollowUp: getResourceGroupFollowUp(
ctx, p.formatter, p.projectConfig, p.resourceManager, p.env),
},
}, nil
}
Expand Down
1 change: 0 additions & 1 deletion cli/azd/cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func (u *upAction) Run(ctx context.Context) (*actions.ActionResult, error) {
if err != nil {
return nil, err
}

return deployResult, nil
}

Expand Down
Loading