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

Fixes issues resolving azure resource manager for vs-server #4299

Merged
merged 2 commits into from
Sep 5, 2024
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
2 changes: 1 addition & 1 deletion cli/azd/internal/vsrpc/environment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *environmentService) DeleteEnvironmentAsync(
// Enable force and purge options
destroyOptions := provisioning.NewDestroyOptions(true, true)
_, err = c.provisionManager.Destroy(ctx, destroyOptions)
if errors.Is(err, infra.ErrDeploymentsNotFound) {
if errors.Is(err, infra.ErrDeploymentsNotFound) || errors.Is(err, infra.ErrDeploymentResourcesNotFound) {
_ = observer.OnNext(ctx, newInfoProgressMessage("No Azure resources were found"))
} else if err != nil {
return false, fmt.Errorf("deleting infrastructure: %w", err)
Expand Down
18 changes: 9 additions & 9 deletions cli/azd/internal/vsrpc/environment_service_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func (s *environmentService) refreshEnvironmentAsync(
}

var c struct {
projectManager project.ProjectManager `container:"type"`
projectConfig *project.ProjectConfig `container:"type"`
importManager *project.ImportManager `container:"type"`
bicep provisioning.Provider `container:"name"`
azureResourceManager *infra.AzureResourceManager `container:"type"`
resourceService *azapi.ResourceService `container:"type"`
resourceManager project.ResourceManager `container:"type"`
serviceManager project.ServiceManager `container:"type"`
envManager environment.Manager `container:"type"`
projectManager project.ProjectManager `container:"type"`
projectConfig *project.ProjectConfig `container:"type"`
importManager *project.ImportManager `container:"type"`
bicep provisioning.Provider `container:"name"`
azureResourceManager infra.ResourceManager `container:"type"`
resourceService *azapi.ResourceService `container:"type"`
resourceManager project.ResourceManager `container:"type"`
serviceManager project.ServiceManager `container:"type"`
envManager environment.Manager `container:"type"`
}

container.MustRegisterScoped(func() internal.EnvFlag {
Expand Down
3 changes: 2 additions & 1 deletion cli/azd/pkg/infra/deployment_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

var (
ErrDeploymentsNotFound = errors.New("no deployments found")
ErrDeploymentsNotFound = errors.New("no deployments found")
ErrDeploymentResourcesNotFound = errors.New("no resources found for deployment")
)

type DeploymentManager struct {
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/infra/provisioning/bicep/bicep_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (p *BicepProvider) Destroy(
}

if len(groupedResources) == 0 {
return nil, fmt.Errorf("no resources found for deployment, '%s'", deploymentToDelete.Name())
return nil, fmt.Errorf("%w, '%s'", infra.ErrDeploymentResourcesNotFound, deploymentToDelete.Name())
}

keyVaults, err := p.getKeyVaultsToPurge(ctx, groupedResources)
Expand Down
13 changes: 9 additions & 4 deletions cli/azd/pkg/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/azapi"
"github.com/azure/azure-dev/cli/azd/pkg/azure"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/infra"
"github.com/azure/azure-dev/cli/azd/test/mocks"
"github.com/azure/azure-dev/cli/azd/test/mocks/mockarmresources"
"github.com/azure/azure-dev/cli/azd/test/mocks/mockazcli"
Expand Down Expand Up @@ -58,7 +59,8 @@ services:
projectConfig, err := Parse(*mockContext.Context, testProj)
require.NoError(t, err)

resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)
targetResource, err := resourceManager.GetTargetResource(
*mockContext.Context, env.GetSubscriptionId(), projectConfig.Services["api"])
require.NoError(t, err)
Expand Down Expand Up @@ -105,7 +107,8 @@ services:
projectConfig, err := Parse(*mockContext.Context, testProj)
require.NoError(t, err)

resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)
targetResource, err := resourceManager.GetTargetResource(
*mockContext.Context, env.GetSubscriptionId(), projectConfig.Services["api"])
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +165,8 @@ services:
projectConfig, err := Parse(*mockContext.Context, testProj)
require.NoError(t, err)

resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)

for _, svc := range projectConfig.Services {
targetResource, err := resourceManager.GetTargetResource(*mockContext.Context, env.GetSubscriptionId(), svc)
Expand Down Expand Up @@ -223,7 +227,8 @@ services:
projectConfig, err := Parse(*mockContext.Context, testProj)
require.NoError(t, err)

resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)
targetResource, err := resourceManager.GetTargetResource(
*mockContext.Context, env.GetSubscriptionId(), projectConfig.Services["api"])
require.NoError(t, err)
Expand Down
21 changes: 12 additions & 9 deletions cli/azd/pkg/project/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ type ResourceManager interface {
}

type resourceManager struct {
env *environment.Environment
deploymentService *azapi.StandardDeployments
resourceService *azapi.ResourceService
env *environment.Environment
deploymentService *azapi.StandardDeployments
resourceService *azapi.ResourceService
azureResourceManager infra.ResourceManager
}

// NewResourceManager creates a new instance of the project resource manager
func NewResourceManager(
env *environment.Environment,
deploymentService *azapi.StandardDeployments,
resourceService *azapi.ResourceService) ResourceManager {
resourceService *azapi.ResourceService,
azureResourceManager infra.ResourceManager,
) ResourceManager {
return &resourceManager{
env: env,
deploymentService: deploymentService,
resourceService: resourceService,
env: env,
deploymentService: deploymentService,
resourceService: resourceService,
azureResourceManager: azureResourceManager,
}
}

Expand Down Expand Up @@ -89,8 +93,7 @@ func (rm *resourceManager) GetResourceGroupName(
return envResourceGroupName, nil
}

resourceManager := infra.NewAzureResourceManager(rm.resourceService, rm.deploymentService)
resourceGroupName, err := resourceManager.FindResourceGroupForEnvironment(ctx, subscriptionId, rm.env.Name())
resourceGroupName, err := rm.azureResourceManager.FindResourceGroupForEnvironment(ctx, subscriptionId, rm.env.Name())
if err != nil {
return "", err
}
Expand Down
4 changes: 3 additions & 1 deletion cli/azd/pkg/project/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/azure/azure-dev/cli/azd/pkg/azapi"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/infra"
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/azure/azure-dev/cli/azd/test/mocks"
"github.com/azure/azure-dev/cli/azd/test/mocks/mockazcli"
Expand Down Expand Up @@ -112,7 +113,8 @@ func Test_ResourceManager_GetTargetResource(t *testing.T) {

setupGetResourceMock(mockContext, expectedResource)

resourceManager := NewResourceManager(tt.env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(tt.env, deploymentService, resourceService, azureResourceManager)
targetResource, err := resourceManager.GetTargetResource(
*mockContext.Context,
tt.env.GetSubscriptionId(),
Expand Down
4 changes: 3 additions & 1 deletion cli/azd/pkg/project/service_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/exec"
"github.com/azure/azure-dev/cli/azd/pkg/ext"
"github.com/azure/azure-dev/cli/azd/pkg/infra"
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/azure/azure-dev/cli/azd/pkg/tools"
"github.com/azure/azure-dev/cli/azd/test/mocks"
Expand Down Expand Up @@ -44,7 +45,8 @@ func createServiceManager(
) ServiceManager {
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)

alphaManager := alpha.NewFeaturesManagerWithConfig(config.NewConfig(
map[string]any{
Expand Down
4 changes: 3 additions & 1 deletion cli/azd/pkg/project/service_target_containerapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/azure/azure-dev/cli/azd/pkg/containerapps"
"github.com/azure/azure-dev/cli/azd/pkg/containerregistry"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/infra"
"github.com/azure/azure-dev/cli/azd/pkg/tools/azcli"
"github.com/azure/azure-dev/cli/azd/pkg/tools/docker"
"github.com/azure/azure-dev/cli/azd/test/mocks"
Expand Down Expand Up @@ -167,7 +168,8 @@ func createContainerAppServiceTarget(
)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)
resourceService := azapi.NewResourceService(credentialProvider, mockContext.ArmClientOptions)
resourceManager := NewResourceManager(env, deploymentService, resourceService)
azureResourceManager := infra.NewAzureResourceManager(resourceService, deploymentService)
resourceManager := NewResourceManager(env, deploymentService, resourceService, azureResourceManager)

return NewContainerAppTarget(
env,
Expand Down
Loading
Loading