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

aws_cognito_user_pool_client data source missing 'name' attribute #22593

Closed
keitharogers opened this issue Jan 14, 2022 · 9 comments · Fixed by #22615
Closed

aws_cognito_user_pool_client data source missing 'name' attribute #22593

keitharogers opened this issue Jan 14, 2022 · 9 comments · Fixed by #22615
Labels
documentation Introduces or discusses updates to documentation.
Milestone

Comments

@keitharogers
Copy link

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

Terraform CLI and Terraform AWS Provider Version

Terraform v1.1.3
on darwin_arm64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v3.72.0
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/integrations/github v4.14.0

Affected Resource(s)

  • aws_cognito_user_pool_client (datasource)
  • aws_cognito_user_pool_clients (datasource)

Terraform Configuration Files

data "aws_cognito_user_pool_clients" "tools" {
  user_pool_id = aws_cognito_user_pool.tools.id
}

data "aws_cognito_user_pool_client" "tools" {
  for_each     = data.aws_cognito_user_pool_clients.tools.client_ids
  client_id    = each.value
  user_pool_id = aws_cognito_user_pool.tools.id
}

output "names" {
  value = data.aws_cognito_user_pool_client.tools.*.name
}

Expected Behaviour

Output should list all Cognito user pool app-client names for given user pool.

Actual Behaviour

Error: Invalid for_each argument
│
│   on opensearch.tf line 6, in data "aws_cognito_user_pool_client" "tools":
│    6:   for_each     = data.aws_cognito_user_pool_clients.tools.client_ids
│     ├────────────────
│     │ data.aws_cognito_user_pool_clients.tools.client_ids is list of string with 2 elements
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type list of string.

Tried to fix this error by utilising toset as follows:

data "aws_cognito_user_pool_client" "tools" {
  for_each     = toset(data.aws_cognito_user_pool_clients.tools.client_ids)
  client_id    = each.value
  user_pool_id = aws_cognito_user_pool.tools.id
}

Which appeared to get past the first error, but then I encountered an unsupported attribute error instead:

Error: Unsupported attribute
│
│   on opensearch.tf line 12, in output "names":
│   12:   value = data.aws_cognito_user_pool_client.tools.*.name
│
│ This object does not have an attribute named "name".

Steps to Reproduce

  1. terraform plan

Important Factoids

This is a brand new datasource released yesterday.

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/cognito labels Jan 14, 2022
@keitharogers
Copy link
Author

@danquack : Thanks for implementing this datasource, but appears there is a bug with it (unless I'm missing something). I've raised this issue accordingly.

@danquack
Copy link
Contributor

danquack commented Jan 14, 2022

This is bad documentation on my part. data "aws_cognito_user_pool_client" "client" is outputting as {clientId: client properties}. Ive solved this in the past with looping, but I am not sure that's the cleanest way.

I just ran this locally and was able to get a list of client names, but there might be a cleaner solution:

resource "aws_cognito_user_pool" "pool" {
  name = "pool"
}

data "aws_cognito_user_pool_clients" "main" {
  user_pool_id = aws_cognito_user_pool.pool.id
}

data "aws_cognito_user_pool_client" "client" {
  for_each     = toset(data.aws_cognito_user_pool_clients.main.client_ids)
  client_id    = each.value
  user_pool_id = aws_cognito_user_pool.pool.id
}

output "names" {
  value = [
      for k,v in data.aws_cognito_user_pool_client.client : v
  ].*.name
}

@keitharogers
Copy link
Author

@danquack : I've copied and pasted what you put in your output section changing it out for my use case and it's returned exactly what I needed. Thanks for that!!

@danquack
Copy link
Contributor

danquack commented Jan 14, 2022

@keitharogers Any chance you can PR to improve the docs with your code? I feel more folks will have a similar use case.
https://github.com/hashicorp/terraform-provider-aws/blob/main/website/docs/d/cognito_user_pool_client.markdown

@keitharogers
Copy link
Author

Yep, I was planning on it, more than happy to do!

@justinretzolk justinretzolk added documentation Introduces or discusses updates to documentation. and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 14, 2022
@github-actions github-actions bot added this to the v3.73.0 milestone Jan 18, 2022
@danquack
Copy link
Contributor

I've pull requested the above solution, but your example would be way better @keitharogers, if youre still considering contributing !

@keitharogers
Copy link
Author

Thanks @danquack . Yep, I was still planning on contributing, although due to a bit of a chicken and egg situation, my solution is breaking the traditional good practices of how Terraform should work and it's quite messy!! I only just came up with it yesterday as well so wanted to review it again before committing to putting something out there, but yes, very much looking to contribute where I can, just want to make sure it's understandable and following best practice so I don't muddy any waters :-)

Thanks again for your help with all this!

@github-actions
Copy link

This functionality has been released in v3.73.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants