Skip to content

Commit

Permalink
chore: point to pk/NR-76861 in client-go and refactor broken code
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-new-relic committed Jan 6, 2024
1 parent 9276cbd commit 5b7c52d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.27.0
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.23.0
// TEMPORARILY POINTING TO THE LATEST COMMIT OF https://github.com/newrelic/newrelic-client-go/pull/981/commits
// TO BE DISCARDED BEFORE MERGE
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240106031842-ca20407fc56f
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ github.com/newrelic/go-agent/v3 v3.27.0 h1:Z3XB49d8FKjRcGzCyViCO9itBxiLPSpwjY1Hl
github.com/newrelic/go-agent/v3 v3.27.0/go.mod h1:TUzePinDc0BMH4Sui66rl4SBe6yOKJ5X/bRJekwuAtM=
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
github.com/newrelic/newrelic-client-go/v2 v2.23.0 h1:ULqiPv4Z0QVLjMjX6uP13wSxPDL3uiKTt5U8vFsvpCQ=
github.com/newrelic/newrelic-client-go/v2 v2.23.0/go.mod h1:VPWTvEfKvnTZLunAC7fiW33y4e0srznNfN5HJH2cOp8=
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240105192613-7907c0bd50e3 h1:YkAH35QuPwQsaI83F5sYNnW68bWY1k16u3Ouq1/1JeU=
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240105192613-7907c0bd50e3/go.mod h1:VPWTvEfKvnTZLunAC7fiW33y4e0srznNfN5HJH2cOp8=
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240106031842-ca20407fc56f h1:EQ0ZEbx+6v8/yjeubhj8qe1F7pjMe+q9ey5B07TUjw0=
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240106031842-ca20407fc56f/go.mod h1:VPWTvEfKvnTZLunAC7fiW33y4e0srznNfN5HJH2cOp8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
23 changes: 12 additions & 11 deletions newrelic/resource_newrelic_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func resourceNewRelicUserGroupCreate(ctx context.Context, d *schema.ResourceData
DisplayName: d.Get("name").(string),
}
created, err := client.UserManagement.UserManagementCreateGroupWithContext(ctx, createInput)

if err != nil {
return diag.FromErr(err)
}
Expand All @@ -68,13 +67,14 @@ func resourceNewRelicUserGroupCreate(ctx context.Context, d *schema.ResourceData
return resourceNewRelicUserGroupRead(ctx, d, meta)
}

// Read a created group
func resourceNewRelicUserGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConfig := meta.(*ProviderConfig)
client := providerConfig.NewClient

groupId := d.Id()
authenticationDomainId := d.Get("authentication_domain_id").(string)
group, err := getUserGroupID(ctx, client, authenticationDomainId, groupId)
groupID := d.Id()
authenticationDomainID := d.Get("authentication_domain_id").(string)
group, err := getUserGroupID(ctx, client, authenticationDomainID, groupID)

if err != nil && group == nil {
d.SetId("")
Expand All @@ -92,25 +92,26 @@ func resourceNewRelicUserGroupRead(ctx context.Context, d *schema.ResourceData,
return nil
}

func getUserGroupID(ctx context.Context, client *newrelic.NewRelic, authId string, groupId string) (groups *usermanagement.UserManagementGroup, err error) {
id := []string{authId}
// Iterate through groups associated with the authentication domain
func getUserGroupID(ctx context.Context, client *newrelic.NewRelic, authID string, groupID string) (groups *usermanagement.UserManagementGroup, err error) {
id := []string{authID}
resp, err := client.UserManagement.GetAuthenticationDomainsWithContext(ctx, id)
if err != nil {
return nil, err
}
for i, groupList := range *resp {
if i == 0 {
for _, group := range groupList.Groups.Groups {
if group.ID == groupId {
if group.ID == groupID {
return &group, nil
}
}
}
}
return nil, errors.New("err: group is not found")
return nil, errors.New("error: group is not found")
}

// Update the obfuscation expression
// Update a created group
func resourceNewRelicUserGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*ProviderConfig).NewClient
updateInput := usermanagement.UserManagementUpdateGroup{}
Expand All @@ -129,10 +130,10 @@ func resourceNewRelicUserGroupUpdate(ctx context.Context, d *schema.ResourceData
return diag.FromErr(err)
}

return resourceNewRelicObfuscationExpressionRead(ctx, d, meta)
return resourceNewRelicUserGroupRead(ctx, d, meta)
}

// Delete the UserGroup
// Delete a created group
func resourceNewRelicUserGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConfig := meta.(*ProviderConfig)
client := providerConfig.NewClient
Expand Down
1 change: 1 addition & 0 deletions newrelic/structures_newrelic_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package newrelic
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/newrelic/newrelic-client-go/v2/pkg/ai"
"github.com/newrelic/newrelic-client-go/v2/pkg/workflows"
Expand Down

0 comments on commit 5b7c52d

Please sign in to comment.