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

Feat: data_okta_app_group_assignments add priority and profile to schema #2047

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
68 changes: 47 additions & 21 deletions okta/data_source_okta_app_group_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package okta

import (
"context"
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -13,17 +14,36 @@ func dataSourceAppGroupAssignments() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAppGroupAssignmentsRead,
Schema: map[string]*schema.Schema{
"id": {
"app_id": {
Type: schema.TypeString,
Required: true,
Description: "ID of the Okta App being queried for groups",
ForceNew: true,
},
"groups": {
Type: schema.TypeSet,
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "List of groups IDs assigned to the app",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"app_id": {
Type: schema.TypeString,
Computed: true,
Description: "Id of the group associated with the application",
},
"priority": {
Type: schema.TypeInt,
Computed: true,
Description: "Priority of group assignment",
},
"profile": {
Type: schema.TypeString,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: "JSON document containing the assigned group's [profile](https://developer.okta.com/docs/reference/api/apps/#profile-object)",
},
},
},
},
},
Description: "Get a set of groups assigned to an Okta application.",
Expand All @@ -32,31 +52,37 @@ func dataSourceAppGroupAssignments() *schema.Resource {

func dataSourceAppGroupAssignmentsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := getOktaClientFromMetadata(m)
id := d.Get("id").(string)
appId := d.Get("app_id").(string)

groupAssignments, resp, err := client.Application.ListApplicationGroupAssignments(ctx, id, &query.Params{})
groupAssignments, resp, err := client.Application.ListApplicationGroupAssignments(ctx, appId, &query.Params{})
if err != nil {
return diag.Errorf("unable to query for groups from app (%s): %s", id, err)
return diag.Errorf("unable to query for groups from app (%s): %s", appId, err)
}

for {
var moreAssignments []*sdk.ApplicationGroupAssignment
if resp.HasNextPage() {
resp, err = resp.Next(ctx, &moreAssignments)
if err != nil {
return diag.Errorf("unable to query for groups from app (%s): %s", id, err)
}
groupAssignments = append(groupAssignments, moreAssignments...)
} else {
break
for resp.HasNextPage() {
var additionalGroups []*sdk.ApplicationGroupAssignment
resp, err = resp.Next(ctx, &additionalGroups)
if err != nil {
return diag.Errorf("unable to query for groups from app (%s): %s", appId, err)
}
groupAssignments = append(groupAssignments, additionalGroups...)
}

var groups []string
for _, assignment := range groupAssignments {
groups = append(groups, assignment.Id)
groups := make([]map[string]interface{}, len(groupAssignments))
for i, group := range groupAssignments {
profile, err := json.Marshal(group.Profile)
if err != nil {
return diag.Errorf("unable to marshal app group profile: %s", err)
}
groups[i] = map[string]interface{}{
"id": group.Id,
"priority": group.Priority,
// "profile": group.Profile,
"profile": string(profile),
}
}
_ = d.Set("groups", convertStringSliceToSet(groups))
d.SetId(id)

d.Set("groups", groups)
d.SetId(appId)
return nil
}
4 changes: 2 additions & 2 deletions okta/data_source_okta_log_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestAccDataSourceOktaLogStream_read(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
//resource.TestCheckResourceAttrSet(awsDataSource, "id"),
// resource.TestCheckResourceAttrSet(awsDataSource, "id"),
resource.TestCheckResourceAttr(awsDataSource, "name", fmt.Sprintf("%s AWS", buildResourceName(mgr.Seed))),
resource.TestCheckResourceAttr(awsDataSource, "type", "aws_eventbridge"),
resource.TestCheckResourceAttr(awsDataSource, "status", "ACTIVE"),
resource.TestCheckResourceAttr(awsDataSource, "settings.account_id", "123456789012"),
resource.TestCheckResourceAttr(awsDataSource, "settings.region", "eu-west-3"),
resource.TestCheckResourceAttr(awsDataSource, "settings.event_source_name", fmt.Sprintf("%s_AWS", buildResourceName(mgr.Seed))),

//resource.TestCheckResourceAttrSet(splunkDataSource, "id"),
// resource.TestCheckResourceAttrSet(splunkDataSource, "id"),
resource.TestCheckResourceAttr(splunkDataSource, "name", fmt.Sprintf("%s Splunk", buildResourceName(mgr.Seed))),
resource.TestCheckResourceAttr(splunkDataSource, "type", "splunk_cloud_logstreaming"),
resource.TestCheckResourceAttr(splunkDataSource, "status", "ACTIVE"),
Expand Down
1 change: 0 additions & 1 deletion okta/resource_okta_idp_oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,4 @@ resource "okta_idp_oidc" "test" {
},
},
})

}
2 changes: 1 addition & 1 deletion okta/resource_okta_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func (r *logStreamResource) Read(ctx context.Context, req resource.ReadRequest,

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *logStreamResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var state logStreamModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &state)...)
Expand Down Expand Up @@ -343,7 +344,6 @@ func (r *logStreamResource) Update(ctx context.Context, req resource.UpdateReque
// change detection there
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
// don't need to check for error, we are returning already

}

func (r *logStreamResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/v2_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (m *AuthenticatorResource) CreateAuthenticator(ctx context.Context, body Au
return authenticator, resp, nil
}

func (m *AuthenticatorResource) SetSettingsOTP(ctx context.Context, body OTP, authenticatorId string)(*Response, error){
func (m *AuthenticatorResource) SetSettingsOTP(ctx context.Context, body OTP, authenticatorId string) (*Response, error) {
url := fmt.Sprintf("/api/v1/authenticators/%v/methods/otp", authenticatorId)

rq := m.client.CloneRequestExecutor()
Expand Down
2 changes: 1 addition & 1 deletion sdk/v2_identityProviderCredentialsClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package sdk
type IdentityProviderCredentialsClient struct {
ClientId string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
PKCERequired *bool `json:"pkce_required"`
PKCERequired *bool `json:"pkce_required"`
}
4 changes: 2 additions & 2 deletions sdk/v2_okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

type Client struct {
// NOTE: do not create and add new resources to this local sdk
// NOTE: do not create and add new resources to this local sdk
config *config
requestExecutor *RequestExecutor
resource resource
Expand Down Expand Up @@ -45,7 +45,7 @@ type Client struct {
UserFactor *UserFactorResource
UserSchema *UserSchemaResource
UserType *UserTypeResource
// NOTE: do not create and add new resources to this local sdk
// NOTE: do not create and add new resources to this local sdk
}

type resource struct {
Expand Down