-
Notifications
You must be signed in to change notification settings - Fork 233
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
Enable TF_SCHEMA_PANIC_ON_ERROR Only During Acceptance Testing #451
Comments
I wonder, instead of panicking at all, if maybe the acceptance testing framework could instead capture this issue, allow the testing to continue as normal, then report it at the end of the
Panics will likely leave dangling testing resources. |
I think |
Oh sorry, I misunderstood what you were saying. I think the thing is we would need some hook down in |
Reference: #9184 Reference: #9190 Reference: #9189 Reference: #13439 Reference: hashicorp/terraform-plugin-sdk#344 Reference: hashicorp/terraform-plugin-sdk#451 The `result_map` attribute was created as a workaround for Terraform 0.11 and earlier not having native JSON decoding abilities. This attribute came with the caveat that it only worked when the JSON was only a flat map of strings, where we otherwise ignore the `(helper/schema.ResourceData).Set()` error and instead return a warning log. In Terraform Plugin SDK v2, this error will now panic in the acceptance testing as these errors are generally indicative of resource bugs, which is unavoidable in this case. Practitioners should instead opt for the Terraform 0.12 and later `jsondecode()` function against the `result` attribute, which can handle much more arbitrary JSON structures. This has been documented in the `aws_lambda_invocation` data source for awhile now. For JSON structures not compliant with Terraform's JSON decoding, the `result` attribute's string value can still be passed to other processing logic, such as calling the `jq` tool.
…3492) Reference: #9184 Reference: #9190 Reference: #9189 Reference: #13439 Reference: hashicorp/terraform-plugin-sdk#344 Reference: hashicorp/terraform-plugin-sdk#451 The `result_map` attribute was created as a workaround for Terraform 0.11 and earlier not having native JSON decoding abilities. This attribute came with the caveat that it only worked when the JSON was only a flat map of strings, where we otherwise ignore the `(helper/schema.ResourceData).Set()` error and instead return a warning log. In Terraform Plugin SDK v2, this error will now panic in the acceptance testing as these errors are generally indicative of resource bugs, which is unavoidable in this case. Practitioners should instead opt for the Terraform 0.12 and later `jsondecode()` function against the `result` attribute, which can handle much more arbitrary JSON structures. This has been documented in the `aws_lambda_invocation` data source for awhile now. For JSON structures not compliant with Terraform's JSON decoding, the `result` attribute's string value can still be passed to other processing logic, such as calling the `jq` tool.
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. |
SDK version
Use-cases
For a long time, the acceptance testing framework has accepted the
TF_SCHEMA_PANIC_ON_ERROR
environment variable as a way to tease out state setting and drift detection issues in resources where the(*helper/schema.ResourceData).Set()
call is not error checked, e.g.In the upcoming SDK v2, the value has been flipped on by default, which is great for catching provider bugs, but unfortunately at the potential expense of very poor user experience. When a resource panics, it makes the resource practically unusable (since this affects refresh) and potentially can leave the user's Terraform state in an errant state (depending on how Terraform CLI handles the panic). Considering that it can be fairly easy for larger providers to miss failing acceptance testing during merges and before releases, this can cause a lot of issues to be submitted and an immediate need to cut a bug fix release. Asking users to run with
TF_SCHEMA_PANIC_ON_ERROR
disabled could be problematic in its own right.Proposal
Consider guarding the
TF_SCHEMA_PANIC_ON_ERROR
behavior to only be enabled by default in the acceptance testing framework. For example, acceptance testing today requiresTF_ACC=1
forhelper/resource.Test()
/helper/resource.ParallelTest()
so that could potentially be used.References
The text was updated successfully, but these errors were encountered: