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

Adding type to data okta group #217

Merged

Conversation

dangoslen
Copy link
Contributor

Re-creating this PR from #155 since I royally screwed up a merge. I believe I have merged this much better now and should be only additions for the functionality I'm attempting to implement.


Description for original PR:

This PR adds the ability to filter by a type in the okta_group data entity.

This is useful in cases were Okta is managed groups from multiple sources (LDAP, Google groups, etc.) that have the same name but different types.

It additionally returns the type as an attribute of the entity.

@tgoodsell-tempus
Copy link
Contributor

https://github.com/oktadeveloper/terraform-provider-okta/blob/7231dbe0ca30154c8f40508da6b51c95091f9fb3/okta/data_source_okta_group.go#L63

This should be changed to optionally include the type if used, maybe something like:

if err != nil {
		return fmt.Errorf("failed to query for groups: %v", err)
	} else if len(groups) < 1 {
                if d.Get("type") != nil {
                    return fmt.Errorf("Group \"%s\" not found with type \"%s\"", name, d.Get("type").(string))
               } else {
	           return fmt.Errorf("Group \"%s\" not found", name)
              }
	}

@dangoslen
Copy link
Contributor Author

@tgoodsell-tempus mind taking another look at this? TY

Copy link
Contributor

@tgoodsell-tempus tgoodsell-tempus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

examples/okta_group/datasource.tf Outdated Show resolved Hide resolved
examples/okta_group/datasource.tf Outdated Show resolved Hide resolved
examples/okta_group/datasource.tf Outdated Show resolved Hide resolved
okta/data_source_okta_group_test.go Show resolved Hide resolved
okta/data_source_okta_group.go Outdated Show resolved Hide resolved
"type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is interface{}, so it will set 0 as a default group type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm trying to read up on where that comes from - can you give me an article or documentation reference to look at?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has something to do with how the terraform converts values from the interface into the value. Because type is schema.TypeString, I think it just represents false as 0 (because false internally is just integer) and then converts it into the string (using strings.Itoa I guess), which is "0".

@bogdanprodan-okta bogdanprodan-okta merged commit 03a43be into okta:master Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants