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

Comments to clarify TestCheckResourceAttrSet() #887

Closed
wants to merge 1 commit into from

Conversation

justinTM
Copy link
Contributor

@justinTM justinTM commented Feb 9, 2022

closes #885

@justinTM justinTM requested a review from a team as a code owner February 9, 2022 01:39
Copy link
Member

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Hi @justinTM 👋 Thank you for submitting this.

It's technically possible to inspect any type of state value using the various TestCheck* and TestMatch functions; it requires knowing Terraform 0.11 and older syntax in certain cases. Those cases are documented at the bottom of the Builtin Check Functions section of the acceptance testing documentation, however if only seeing the Go documentation, it can certainly be hard to know that, which we probably should adjust for future travelers. 😅

I believe in this case, we'd probably want to include the special cases to all the TestCheck and TestMatch function Go documentation. Copy-pasting comments like this is certainly less than ideal, but preferable over putting a very specific documentation URL which can change over time and is hard to check/maintain.

Appending something like the following Go documentation to the following functions should help:

  • TestCheckResourceAttrSet
  • TestCheckResourceAttr
  • TestCheckNoResourceAttr
  • TestMatchResourceAttr
  • TestCheckResourceAttrPtr
  • TestCheckResourceAttrPair
// ... existing Go documentation ...
//
// Use the following special key syntax to inspect list and map values
// of an attribute:
//   .{NUMBER}: List value at index, e.g. .0 to inspect the first element
//   .{KEY}: Map value at key, e.g. .example to inspect the example key value
//   .#: Number of elements in list or set
//   .%: Number of elements in map

Thanks again for raising this and please reach out with any questions.

@bflad
Copy link
Member

bflad commented Feb 10, 2022

Thinking about this more, one complication here is that indeed checking the list/set/map attribute itself, not one of the special sub-keys, will likely not be represented in the flatmap state. I'm wondering if it might be best to mention both things in that case by having a statement such as "Collection attributes can only be inspected by the special key syntax, not the attribute key itself."

@bflad
Copy link
Member

bflad commented Mar 11, 2022

Hi again, @justinTM 👋 Since I haven't heard back from you for awhile, I'm going to close this. I'll submit the above suggestions separately so the Go documentation is updated appropriately. Thanks again for raising this.

@bflad bflad closed this Mar 11, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Apr 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testCheckResourceAttrSet() is broken for all but TypeString attributes
2 participants