Skip to content
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
24 changes: 22 additions & 2 deletions cli/azd/pkg/containerapps/container_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import (
"log"
"net/http"
"slices"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3"
"github.com/azure/azure-dev/cli/azd/internal"
"github.com/azure/azure-dev/cli/azd/pkg/account"
"github.com/azure/azure-dev/cli/azd/pkg/alpha"
"github.com/azure/azure-dev/cli/azd/pkg/config"
"github.com/azure/azure-dev/cli/azd/pkg/convert"
"github.com/azure/azure-dev/cli/azd/pkg/output"
"github.com/benbjohnson/clock"
"github.com/braydonk/yaml"
)
Expand Down Expand Up @@ -458,7 +461,11 @@ func (cas *containerAppService) getContainerApp(

_, err = appClient.Get(ctx, resourceGroupName, appName, nil)
if err != nil {
return nil, fmt.Errorf("getting container app: %w", err)
err = fmt.Errorf("getting container app: %w", err)
if strings.Contains(err.Error(), "unmarshalling type") {
err = withApiVersionSuggestion(err)
}
return nil, err
}

var containAppMap map[string]any
Expand Down Expand Up @@ -499,7 +506,7 @@ func (cas *containerAppService) updateContainerApp(
var containerAppResource armappcontainers.ContainerApp
if apiVersionPolicy == nil {
if err := json.Unmarshal(containerAppJson, &containerAppResource); err != nil {
return fmt.Errorf("failed to unmarshal container app: %w", err)
return withApiVersionSuggestion(fmt.Errorf("failed to unmarshal container app: %w", err))
}
}

Expand Down Expand Up @@ -603,3 +610,16 @@ func createApiVersionPolicy(options *ContainerAppOptions) *containerAppCustomApi
apiVersion: options.ApiVersion,
}
}

func withApiVersionSuggestion(err error) error {
suggestion := "Suggestion: set 'apiVersion' on your service in azure.yaml to match the API version " +
"in your IaC:\n\n" +
"services:\n" +
" your-service:\n" +
output.WithSuccessFormat(" apiVersion: 2025-02-02-preview")

return &internal.ErrorWithSuggestion{
Err: err,
Suggestion: suggestion,
}
}
25 changes: 17 additions & 8 deletions cli/azd/pkg/infra/azure_resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (

"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/internal"
"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/azureutil"
"github.com/azure/azure-dev/cli/azd/pkg/compare"
"github.com/azure/azure-dev/cli/azd/pkg/output"
)

type AzureResourceManager struct {
Expand Down Expand Up @@ -182,20 +184,27 @@ func (rm *AzureResourceManager) FindResourceGroupForEnvironment(
return rgs[0].Name, nil
}

var msg string

var findErr error
if len(rgs) > 1 {
// We found more than one RG
msg = "more than one possible resource group was found."
findErr = errors.New("more than one possible resource group was found")
} else {
// We didn't find any RGs
msg = "unable to find the environment resource group."
findErr = errors.New("unable to find the environment resource group")
}

return "", fmt.Errorf(
"%s explicitly specify your resource group in azure.yaml or the AZURE_RESOURCE_GROUP environment variable",
msg,
)
suggestion := "Suggestion: explicitly set the AZURE_RESOURCE_GROUP environment variable or specify " +
"your resource group in azure.yaml:\n\n" +
"resourceGroup: your-resource-group\n" +
"# or for a specific service\n" +
"services:\n" +
" your-service:\n" +
output.WithSuccessFormat(" resourceGroup: your-resource-group")

return "", &internal.ErrorWithSuggestion{
Err: findErr,
Suggestion: suggestion,
}
}

func (rm *AzureResourceManager) GetResourceTypeDisplayName(
Expand Down
Loading