From 7a7c76bcdac41fcb54a4de3146996c34d5908a2c Mon Sep 17 00:00:00 2001 From: hbc Date: Tue, 28 Nov 2023 14:30:58 -0800 Subject: [PATCH] fix: query resource group under giving subscription id --- pkg/providers/azure.go | 2 +- pkg/providers/providersutils.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/providers/azure.go b/pkg/providers/azure.go index 715fc188..99de537b 100644 --- a/pkg/providers/azure.go +++ b/pkg/providers/azure.go @@ -203,7 +203,7 @@ func (sc *SetUpCmd) ValidateSetUpConfig() error { return err } - if err := isValidResourceGroup(sc.ResourceGroupName); err != nil { + if err := isValidResourceGroup(sc.SubscriptionID, sc.ResourceGroupName); err != nil { return err } diff --git a/pkg/providers/providersutils.go b/pkg/providers/providersutils.go index 4205b42a..2961d261 100644 --- a/pkg/providers/providersutils.go +++ b/pkg/providers/providersutils.go @@ -167,16 +167,19 @@ func IsSubscriptionIdValid(subscriptionId string) error { return nil } -func isValidResourceGroup(resourceGroup string) error { +func isValidResourceGroup( + subscriptionId string, + resourceGroup string, +) error { if resourceGroup == "" { return errors.New("resource group cannot be empty") } query := fmt.Sprintf("[?name=='%s']", resourceGroup) - getResourceGroupCmd := exec.Command("az", "group", "list", "--query", query) + getResourceGroupCmd := exec.Command("az", "group", "list", "--subscription", subscriptionId, "--query", query) out, err := getResourceGroupCmd.CombinedOutput() if err != nil { - log.Errorf("failed to validate resourcegroup: %s", err) + log.Errorf("failed to validate resource group %q from subscription %q: %s", resourceGroup, subscriptionId, err) return err } @@ -186,7 +189,7 @@ func isValidResourceGroup(resourceGroup string) error { } if len(rg) == 0 { - return errors.New("resource group not found") + return fmt.Errorf("resource group %q not found from subscription %q", resourceGroup, subscriptionId) } return nil