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

Document why for_each in okta_app_group_assignments is discouraged #2209

Open
MIJOTHY-V2 opened this issue Feb 6, 2025 · 1 comment
Open
Labels
enhancement Asking for new behavior or feature

Comments

@MIJOTHY-V2
Copy link

MIJOTHY-V2 commented Feb 6, 2025

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

The current documentation for okta_app_group_assignments states

Important: Do not use in conjunction with for_each

It is not clear why this is the case and if this applies to all for_each usage.

For example, this seems like an obvious "bad" usage of for_each, because a dynamic block achieves the same without clobbering other group assignments:

resource "okta_app_bookmark" "this" {
  label = "https://internet.com"
  url   = "https://internet.com"
}

resource "okta_app_group_assignments" "this" {
  # Naughty, use `dynamic` instead
  for_each = ["group-a", "group-b"]

  app_id = okta_app_bookmark.this.id

  group {
    id = each.value
  }
}

However, in the below example, a user is creating multiple applications, and assigning the same group to those multiple applications. This can't be achieved with dynamic, and seems like a logical usage of for_each. Does the recommendation to "not use in conjunction with for_each" also apply here?

resource "okta_app_bookmark" "this" {
  for_each = ["https://internet.com", "https://website.com"]

  label = each.value
  url   = each.value
}

resource "okta_app_group_assignments" "this" {
  # Why is this naughty?
  for_each = ["https://internet.com", "https://website.com"]

  app_id = okta_app_bookmark.this[each.value].id

  group {
    id = "group-a"
  }
}

New or Affected Resource(s)

  • okta_app_group_assignments

References

@MIJOTHY-V2 MIJOTHY-V2 added the enhancement Asking for new behavior or feature label Feb 6, 2025
@exitcode0
Copy link
Contributor

For example, this seems like an obvious "bad" usage of for_each, because a dynamic block achieves the same without clobbering other group assignments:

resource "okta_app_bookmark" "this" {
  label = "https://internet.com"
  url   = "https://internet.com"
}

resource "okta_app_group_assignments" "this" {
  # Naughty, use `dynamic` instead
  for_each = ["group-a", "group-b"]

  app_id = okta_app_bookmark.this.id

  group {
    id = each.value
  }
}

This approach would likely cause you issues because okta_app_group_assignments assumes that it will manage ALL Okta groups assigned to an application, thus this approach would leave you with only group-b assigned to the Okta application


However, in the below example, a user is creating multiple applications, and assigning the same group to those multiple applications. This can't be achieved with dynamic, and seems like a logical usage of for_each. Does the recommendation to "not use in conjunction with for_each" also apply here?

resource "okta_app_bookmark" "this" {
  for_each = ["https://internet.com", "https://website.com"]

  label = each.value
  url   = each.value
}

resource "okta_app_group_assignments" "this" {
  # Why is this naughty?
  for_each = ["https://internet.com", "https://website.com"]

  app_id = okta_app_bookmark.this[each.value].id

  group {
    id = "group-a"
  }
}

Based on my understanding of the resource's implementation, I don't see an issue with this approach, it looks like this was introduced in #2009, perhaps @duytiennguyen-okta can shed some light on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Asking for new behavior or feature
Projects
None yet
Development

No branches or pull requests

2 participants