Skip to content

Commit

Permalink
Merge pull request #1041 from okta/exitcode0_custom_profile_attributes
Browse files Browse the repository at this point in the history
Exitcode0 custom profile attributes
  • Loading branch information
monde authored Mar 31, 2022
2 parents 5cf6aa9 + 2378f6e commit b7c676f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
17 changes: 17 additions & 0 deletions examples/okta_groups/datasource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ resource "okta_group" "test_2" {
data "okta_groups" "test" {
q = "testAcc_"
}

data "okta_groups" "app_groups" {
type = "APP_GROUP"
}

output "special_groups" {
# This is an example of syntax only. Okta API only adds group of type OKTA_GROUP
# and so the example resource groups in this example above will be of that type.
# OTKA_GROUP groups only have "name" and "description" properties which are
# removed from okta-sdk-golang GroupProfileMap that is used to populate the bare
# JSON custom_profile_attributes on the group data.

# Groups of type APP_GROUP have customizable profile properties and a more
# meaningful lookup example could be done like so:
value = join(",", [for group in data.okta_groups.app_groups.groups : group.name
if lookup(jsondecode(group.custom_profile_attributes), "some_attribute", "") == "Some Value"])
}
18 changes: 14 additions & 4 deletions okta/data_source_okta_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package okta

import (
"context"
"encoding/json"
"fmt"
"hash/crc32"

Expand Down Expand Up @@ -51,6 +52,10 @@ func dataSourceGroups() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"custom_profile_attributes": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -80,11 +85,16 @@ func dataSourceGroupsRead(ctx context.Context, d *schema.ResourceData, m interfa
d.SetId(fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(qp.String()))))
arr := make([]map[string]interface{}, len(groups))
for i := range groups {
customProfile, err := json.Marshal(groups[i].Profile.GroupProfileMap)
if err != nil {
return diag.Errorf("failed to read custom profile attributes from group: %s", groups[i].Profile.Name)
}
arr[i] = map[string]interface{}{
"id": groups[i].Id,
"name": groups[i].Profile.Name,
"type": groups[i].Type,
"description": groups[i].Profile.Description,
"id": groups[i].Id,
"name": groups[i].Profile.Name,
"type": groups[i].Type,
"description": groups[i].Profile.Description,
"custom_profile_attributes": string(customProfile),
}
}
_ = d.Set("groups", arr)
Expand Down
2 changes: 2 additions & 0 deletions okta/data_source_okta_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestAccOktaDataSourceGroups_read(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.okta_groups.test", "id"),
resource.TestCheckResourceAttr("data.okta_groups.test", "groups.#", "2"),
// the example enumeration doesn't match anything so as a string the output will be a blank string
resource.TestCheckOutput("special_groups", ""),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ data "okta_groups" "example" {
- `name` - Group name.
- `description` - Group description.
- `type` - Group type.
- `custom_profile_attributes` - raw JSON containing all custom profile attributes. Likely only useful on groups of type `APP_GROUP`.

0 comments on commit b7c676f

Please sign in to comment.