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

Get attribute of TypeSet from terraform.State for tests #1158

Open
tylerFowler opened this issue Feb 25, 2023 · 3 comments
Open

Get attribute of TypeSet from terraform.State for tests #1158

tylerFowler opened this issue Feb 25, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework.

Comments

@tylerFowler
Copy link

Currently there seems to be no way to retrieve an attribute (specifically a computed attribute but not limited to that) of type schema.TypeSet as a schema.Set given an object of type terraform.State.

Use-cases

The Set methods would be highly useful for use in resource.TestCheckFuncs and result in cleaner, slimmer test check functions.

@tylerFowler tylerFowler added the enhancement New feature or request label Feb 25, 2023
@bflad bflad added the subsystem/tests Issues and feature requests related to the testing framework. label Feb 28, 2023
@bflad
Copy link
Contributor

bflad commented Feb 28, 2023

Hi @tylerFowler 👋 Thank you for raising this feature request.

It would be super helpful if you could discuss more about what you are looking to check in your testing?

If you haven't seen already, there are already a few built-in TypeSet specific TestCheckFunc available in the helper/resource package already, such as TestCheckTypeSetElemAttr and TestCheckTypeSetElemNestedAttrs. For checking a set contains expected values, these should cover most use cases.

@bflad bflad added the waiting-response Issues or pull requests waiting for an external response label Feb 28, 2023
@bflad bflad self-assigned this Feb 28, 2023
@tylerFowler
Copy link
Author

Yeah, I was thinking more in the vein of custom test check funcs, where I want to simply range over set items in a custom function, perhaps calling APIs for each one to verify state, etc...

@github-actions github-actions bot removed the waiting-response Issues or pull requests waiting for an external response label Mar 1, 2023
@bflad
Copy link
Contributor

bflad commented Mar 2, 2023

Thank you for that additional context, @tylerFowler.

The baked in terraform.State for TestCheckFunc usage is a vestige from Terraform 0.11 and earlier, where the testing code re-implemented logic from the core Terraform logic and the type system was very limited. I would imagine that it is more likely (due to the effort versus gains) that the testing code would provide a different type of abstraction (e.g. one from the state JSON) rather than refactor/enhance the old Terraform state code specifically for terraform-plugin-sdk concepts. We recently introduced the terraform-plugin-testing Go module and a future major version of that will likely remove terraform-plugin-sdk specifics so it is explicitly generic to work with any Go SDK (terraform-plugin-framework, terraform-plugin-go, terraform-plugin-sdk, or other hypothetical Go SDKs).

Is the API lookup available via data source(s) in the provider? In those cases, either using TestCheckTypeSetElemAttrPair or Terraform configuration postcondition checks may be possible solutions that exist today, but tackle the use case in a different manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework.
Projects
None yet
Development

No branches or pull requests

2 participants