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

Implement optional support for "name" and "id" fields in data sources #53

Merged
merged 9 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions cloudconnexa/data_source_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func dataSourceUserGroup() *schema.Resource {
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Required: true,
Description: "The user group ID.",
},
"name": {
Type: schema.TypeString,
Required: true,
Computed: true,
Description: "The user group name.",
},
"vpn_region_ids": {
Expand Down Expand Up @@ -66,13 +66,13 @@ func dataSourceUserGroup() *schema.Resource {
func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*cloudconnexa.Client)
var diags diag.Diagnostics
userGroupName := d.Get("name").(string)
userGroup, err := c.UserGroups.GetByName(userGroupName)
userGroupId := d.Get("id").(string)
userGroup, err := c.UserGroups.Get(userGroupId)
if err != nil {
return append(diags, diag.FromErr(err)...)
}
if userGroup == nil {
return append(diags, diag.Errorf("User group with name %s was not found", userGroupName)...)
return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...)
}
d.SetId(userGroup.ID)
d.Set("name", userGroup.Name)
Expand Down
Loading