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

fix: query resource group under giving subscription id #238

Merged
merged 1 commit into from
Jan 6, 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 pkg/providers/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/providers/providersutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Loading