-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix potential panics due to nested block contains all optional sub-properties #11452
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome @magodo! LGTM 👍
good to merge once test failure is fixed:
|
@katbyte I've resolved the UT failures. Additionally, I've removed the constraints in the migration files, as they are not necessary to be defined in the migration schemas. |
…d the panic These properties has special meanings when being an empty block. Hence, rather than adding the constraints, make sure there will be no panic when being empty block instead.
…ic (#11464) This PR reverts some of the AtLeastOneOf added in #11452, for which properties that are valid to be left as an empty block. These properties have special meanings when being an empty block. Hence, rather than adding the constraints, make sure there will be no panic when being empty block and add the lint comment instead.
This has been released in version 2.57.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.57.0"
}
# ... other configuration ... |
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. |
For schemas where a non-computed nested block property of
TypeList
that only contains optional-only and non-default child properties, which has noAtLeastOneOf
/ExactlyOneOf
constraint. Then after getting this parent schema fromschema.ResourceData
, it might be a[]interface{}
with onenil
element, which corresponds to the case that users has specify an empty block, like:foo {}
I've created a linter rule to scan all the schemas that is a composite literal, and found ~100 schemas that need special attention. Otherwise, the use case above will cause panic as reported in #11422.
The fix in this PR follows following rules:
MaxItem
to 1), then theseOptional
properties are set theAtLeastOneOf
constraint to invalidate the empty block use case.nil
check. For this case, especially when there are multiple child properties, I'll further ensure there is no pre-size for the expanded arraies. Because we willcontinue
the loop if the element under iteration is nil.Note that there are also some data source which has set the property as
Optional
by mistake, which should beComputed
actually. I've fixed those, too.The lint rule comment is used for my local run, to ensure there are no more warnings. Once bflad/tfproviderlint#236 and bflad/tfproviderlint#237 are merged, then these comments can also benefit our code base, if we enable the rule XS003.
The last thing worth mentioning is that even we resolved all the lint warnings from the XS003, there are still cases that missed, including those schema definitions which are not pure composite literal.