You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Values for start and end_date does not pass the validation.
Debug Output
Expected Behavior
╷
│ Error: value start_date: "test2" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 132, in data "datasourcename" "name":
│ 132: start_date = "test2"
│
╵
╷
│ Error: value end_date: "test1" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 133, in data "datasourcename" "name":
│ 133: end_date = "test1"
│
Both validation fails and the location of failed places is correct. It's especially useful with big and flat schemas.
Actual Behavior
╷
│ Error: value start_date: "test2" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 131, in data "datasourcename" "name":
│ 131: abc = "abc_value"
│
╵
╷
│ Error: value end_date: "test1" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 131, in data "datasourcename" "name":
│ 131: abc = "abc_value"
│
The location where are the issues are incorrect: it's pointing that it failed on "abc" and "abc" (my duplication here was intended) while it should point to "start_date" and "end_date" where both validations failed. Please note that when trying the terraform plan several times, the incorrect lines reported by diagnostics changes (the bigger the schema is, the more it changes).
Steps to Reproduce
terraform init
terraform plan (often can be tried several times depending on the schema size)
Preanalysis ?
I did brief debugging on that topic and it seems that the root cause is in the validateObject function of the helper/schema/schema.go file. As a parameter it receives path cty.Path (where Path is a slice). As You know slice is actually a view over an array (it'll be needed later). Later (when there is iteration over schema), that path is used to build new path for validate function. If the validate returns something notempty, the it's saved into the diags.
And here where the root cause imo occurs: on next iteration it appends new schema element to path. As a result it overwrites the path value that was already stored into the diags as it's based on the same array. That causes incorrect path and duplication as it'll always show the last element of iterating over schema.
So probably copying path slice in the-over-schema loop and using that fresh copy every time should fix the issue.
Regardless if You find results of my debugging useful it'd be great if You could please take care of that issue.
Best regards,
Wojciech
The text was updated successfully, but these errors were encountered:
SDK version
Relevant provider source code
Terraform Configuration Files
Values for start and end_date does not pass the validation.
Debug Output
Expected Behavior
╷
│ Error: value start_date: "test2" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 132, in data "datasourcename" "name":
│ 132: start_date = "test2"
│
╵
╷
│ Error: value end_date: "test1" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 133, in data "datasourcename" "name":
│ 133: end_date = "test1"
│
Both validation fails and the location of failed places is correct. It's especially useful with big and flat schemas.
Actual Behavior
╷
│ Error: value start_date: "test2" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 131, in data "datasourcename" "name":
│ 131: abc = "abc_value"
│
╵
╷
│ Error: value end_date: "test1" does not match the pattern "^[1-9]\d*$"
│
│ with data.datasourcename.name,
│ on filename.tf line 131, in data "datasourcename" "name":
│ 131: abc = "abc_value"
│
The location where are the issues are incorrect: it's pointing that it failed on "abc" and "abc" (my duplication here was intended) while it should point to "start_date" and "end_date" where both validations failed. Please note that when trying the terraform plan several times, the incorrect lines reported by diagnostics changes (the bigger the schema is, the more it changes).
Steps to Reproduce
terraform init
terraform plan
(often can be tried several times depending on the schema size)Preanalysis ?
I did brief debugging on that topic and it seems that the root cause is in the
validateObject
function of thehelper/schema/schema.go
file. As a parameter it receivespath cty.Path
(where Path is a slice). As You know slice is actually a view over an array (it'll be needed later). Later (when there is iteration overschema
), that path is used to build new path for validate function. If the validate returns something notempty, the it's saved into the diags.And here where the root cause imo occurs: on next iteration it appends new schema element to path. As a result it overwrites the path value that was already stored into the diags as it's based on the same array. That causes incorrect path and duplication as it'll always show the last element of iterating over schema.
So probably copying
path
slice in the-over-schema
loop and using that fresh copy every time should fix the issue.Regardless if You find results of my debugging useful it'd be great if You could please take care of that issue.
Best regards,
Wojciech
The text was updated successfully, but these errors were encountered: