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: Resource group crash #2809

Merged
merged 1 commit into from
Jul 5, 2021
Merged
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
25 changes: 13 additions & 12 deletions ibm/data_source_ibm_resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ func dataSourceIBMResourceGroup() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Description: "Resource group name",
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"is_default"},
Description: "Resource group name",
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: []string{"is_default", "name"},
},
"is_default": {
Description: "Default Resource group",
Type: schema.TypeBool,
Optional: true,
ConflictsWith: []string{"name"},
Description: "Default Resource group",
Type: schema.TypeBool,
Optional: true,
ExactlyOneOf: []string{"is_default", "name"},
},
},
}
Expand Down Expand Up @@ -62,7 +62,10 @@ func dataSourceIBMResourceGroupRead(d *schema.ResourceData, meta interface{}) er
grp, err = rsGroup.List(&resourceGroupQuery)

if err != nil {
return fmt.Errorf("Error retrieving default resource group: %s", err)
return fmt.Errorf("[ERROR] Error retrieving default resource group: %s", err)
}
if len(grp) < 1 {
return fmt.Errorf("[ERROR] No Default resource group found: %s", err)
}
d.SetId(grp[0].ID)

Expand All @@ -72,12 +75,10 @@ func dataSourceIBMResourceGroupRead(d *schema.ResourceData, meta interface{}) er
}
grp, err := rsGroup.FindByName(resourceGroupQuery, name)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a condition check of len(grp) < 1 here also

Copy link
Collaborator Author

@kavya498 kavya498 Jul 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindByName function is already checking the condition..

return fmt.Errorf("Error retrieving resource group %s: %s", name, err)
return fmt.Errorf("[ERROR] Error retrieving resource group %s: %s", name, err)
}
d.SetId(grp[0].ID)

} else {
return fmt.Errorf("Missing required properties. Need a resource group name, or the is_default true")
}

return nil
Expand Down