Skip to content

Commit

Permalink
allow for second infra
Browse files Browse the repository at this point in the history
  • Loading branch information
weikanglim committed Nov 18, 2024
1 parent d2f6b26 commit 5f035a9
Show file tree
Hide file tree
Showing 9 changed files with 556 additions and 364 deletions.
7 changes: 7 additions & 0 deletions cli/azd/pkg/azapi/resource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package azapi

import (
"context"
"errors"
"fmt"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/azure/azure-dev/cli/azd/pkg/account"
Expand Down Expand Up @@ -194,6 +196,11 @@ func (rs *ResourceService) DeleteResourceGroup(ctx context.Context, subscription
}

poller, err := client.BeginDelete(ctx, resourceGroupName, nil)
var respErr *azcore.ResponseError
if errors.As(err, &respErr) && respErr.StatusCode == 404 { // Resource group is already deleted
return nil
}

if err != nil {
return fmt.Errorf("beginning resource group deletion: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cli/azd/pkg/azapi/standard_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/url"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewStandardDeployments(
// unix time to the environment name (separated by a hyphen) to provide a unique name for each deployment. If the resulting
// name is longer than the ARM limit, the longest suffix of the name under the limit is returned.
func (ds *StandardDeployments) GenerateDeploymentName(baseName string) string {
log.Printf("Generating deployment name %s", baseName)
name := fmt.Sprintf("%s-%d", baseName, ds.clock.Now().Unix())
if len(name) <= cArmDeploymentNameLengthMax {
return name
Expand Down
5 changes: 5 additions & 0 deletions cli/azd/pkg/azure/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const (
// TagKeyAzdEnvName is the name of the key in the tags map of a resource
// used to store the azd environment a resource is associated with.
TagKeyAzdEnvName = "azd-env-name"

// TagKeyAzdModuleName is the name of the key in the tags map of a resource
// used to store the Bicep module a resource is associated with.
TagKeyAzdModuleName = "azd-module-name"

/* #nosec G101 - Potential hardcoded credentials - false positive */
// TagKeyAzdDeploymentStateParamHashName is the name of the key in the tags map of a deployment
// used to store the parameters hash.
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/devcenter/provision_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (p *ProvisionProvider) pollForProgress(ctx context.Context, deployment infr
}

// Report incremental progress
progressDisplay := p.deploymentManager.ProgressDisplay(deployment)
progressDisplay := p.deploymentManager.ProgressDisplay([]infra.Deployment{deployment})

initialDelay := 3 * time.Second
regularDelay := 10 * time.Second
Expand Down
22 changes: 19 additions & 3 deletions cli/azd/pkg/infra/deployment_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log"
"slices"
"strings"

Expand Down Expand Up @@ -47,7 +48,7 @@ func (dm *DeploymentManager) CalculateTemplateHash(
return dm.deploymentService.CalculateTemplateHash(ctx, subscriptionId, template)
}

func (dm *DeploymentManager) ProgressDisplay(deployment Deployment) *ProvisioningProgressDisplay {
func (dm *DeploymentManager) ProgressDisplay(deployment []Deployment) *ProvisioningProgressDisplay {
return NewProvisioningProgressDisplay(dm.resourceManager, dm.console, deployment)
}

Expand Down Expand Up @@ -77,6 +78,7 @@ func (dm *DeploymentManager) CompletedDeployments(
ctx context.Context,
scope Scope,
envName string,
moduleName string,
hint string,
) ([]*azapi.ResourceDeployment, error) {
deployments, err := scope.ListDeployments(ctx)
Expand Down Expand Up @@ -106,8 +108,22 @@ func (dm *DeploymentManager) CompletedDeployments(
continue
}

// Match on current azd strategy (tags) or old azd strategy (deployment name)
if v, has := deployment.Tags[azure.TagKeyAzdEnvName]; has && *v == envName || deployment.Name == envName {
// Match on current azd strategy (tags)
if v, has := deployment.Tags[azure.TagKeyAzdEnvName]; has && *v == envName {
moduleVal, hasModuleTag := deployment.Tags[azure.TagKeyAzdModuleName]
if moduleName != "" && hasModuleTag && *moduleVal == moduleName {
log.Printf(
"completedDeployments: matched deployment '%s' using moduleName: %s", deployment.Name, moduleName)
return []*azapi.ResourceDeployment{deployment}, nil
}

if moduleName == "" && (!hasModuleTag || moduleVal == nil || *moduleVal == "") {
return []*azapi.ResourceDeployment{deployment}, nil
}
}

// LEGACY: match on deployment name
if deployment.Name == envName {
return []*azapi.ResourceDeployment{deployment}, nil
}

Expand Down
Loading

0 comments on commit 5f035a9

Please sign in to comment.