Skip to content

Commit

Permalink
chore: update to working go client and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-new-relic committed Jan 5, 2024
1 parent c5ba5f5 commit c4d9127
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/newrelic/go-insights v1.0.3
// 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.20240105021304-d96860faffa7
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240105192613-7907c0bd50e3
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ 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.1-0.20240105021304-d96860faffa7 h1:D9I9bUS5GU/RKCGT2ENOOFVE8eZB7kzv/HIyiKlARIo=
github.com/newrelic/newrelic-client-go/v2 v2.23.1-0.20240105021304-d96860faffa7/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/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
11 changes: 6 additions & 5 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,6 +67,7 @@ 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
Expand All @@ -92,6 +92,7 @@ func resourceNewRelicUserGroupRead(ctx context.Context, d *schema.ResourceData,
return nil
}

// 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)
Expand All @@ -107,10 +108,10 @@ func getUserGroupID(ctx context.Context, client *newrelic.NewRelic, authID strin
}
}
}
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

0 comments on commit c4d9127

Please sign in to comment.