The data source’s ValidateConfig() method rejects this configuration because 3 is an odd number and must_be_even is true. So far, so good.
I can point the user-facing error to the problem using AddAttributeError()'s path.Path argument, but not with as much specificity as I’d expected.
Using path.Root("number_list").AtListIndex(i) does what I expect: It cites line 3 (the beginning of the nested list item at index i) as the problem spot:
╷
│ Error: invalid attribute combination
│
│ with data.path_example.e,
│ on main.tf line 3, in data "path_example" "e":
│ 3: {
│ 4: number = "3"
│ 5: must_be_even = true
│ 6: }
│
│ number must be even when must_be_even is true
╵
But I’d prefer it point at the number attribute on line 4. Using path.Root("number_list").AtListIndex(i).AtName("number") does not do what I expect.
Instead of pointing at the number attribute within the nested object at index i, it points to the top of the resource block:
╷
│ Error: invalid attribute combination
│
│ with data.path_example.e,
│ on main.tf line 1, in data "path_example" "e":
│ 1: data "path_example" "e" {
│
│ number must be even when must_be_even is true
╵
Is this expected behavior? Perhaps I’m not expressing the path correctly?
Thanks!
There’s a skeleton provider which demonstrates the situation here.
That behavior does not sound correct, but we’ll need to figure out whether it is an issue on the provider side of the protocol (e.g. a bug in terraform-plugin-framework or terraform-plugin-go) or in the human readable output of Terraform core after it receives the provider path information. Enabling trace logging (e.g. TF_LOG=trace) should include a ValidateDataSourceConfig RPC response message with the error diagnostic you generated. I believe that log message should include path information if the provider included it with the diagnostic. If the path looks like you would expect there, I would raise an issue in the Terraform core issue tracker.
Do you happen to know what term should I use to refer to this feature where config validation errors cite relevant sections of the .tf config files? I figure the citation engine has a name…
I personally would interpret AttributeName("number_list").ElementKeyInt(0).AttributeName("number") there to be correct given the prior information in this post, but you would know best based on the configuration you’re giving it (e.g. the diagnostic is intended to be reported is actually on the number_list attribute that is a list, at the first element index that is an object, at the number attribute).
The plan output handling is done by the “plan renderer” and this appears to be an issue where the renderer is not getting (or properly using) the associated configuration source information given by a provider diagnostic’s “attribute path” data. I don’t think it has any special name.