-
Notifications
You must be signed in to change notification settings - Fork 232
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
Verify e.g. ExactlyOneOf
later so argument can be null when count = 0
#894
Comments
Very briefly -- My understanding of this situation is that providers (via the SDK) cannot determine the number of resource/data source instances during If Terraform CLI should not be calling the Validate*Config RPC on these types of configurations, that would need to be changed upstream. (I believe it should be calling these RPCs in that situation because otherwise it could leave a potentially awkward situation where One option on the provider-side is to skip the schema configuration of Another option on the SDK-side could be changing this type of validation to only being performed during |
Closing out as the above is satisfactory for now. 👍 |
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. |
SDK version
Use-cases
Use case is for evaluation order of
ExactlyOneOf
(et al.) to allow it to be a short circuit operand. Practitioners want to short circuit in cases wherecount = 0
. However, current evaluation order prevents this from happening.For example, currently, in the configuration below, if
local.cidr
isnull
, we don't want thetest
resource at all. Only ifcount > 0
do we want to verify thatExactlyOneOf
three arguments (i.e.,destination_cidr_block
,destination_ipv6_cidr_block
, ordestination_prefix_list_id
) is set:The current evaluation order is roughly equivalent to this backwards Go statement. We're calling, e.g.,
diags.HasError()
, before checking to see ifdiags
isnil
.The way it should work is if
count = 0
, the resource short circuits. Similarly, if, e.g.,diags
is nil, we drop out of the&&
operation before thediags.HasError()
call creates anil
pointer panic.In order for this to work,
diags.HasError()
must be able to pass compile-time evaluation. Similarly,ExactlyOneOf
could have a compile-time check to ensure syntactic correctness but not fully evaluate until the short circuit condition is passed at runtime.As it is now, since
count = 0
is not evaluating like a short circuit operator, practitioners are getting this error even whencount
will evaluate to0
:Attempted Solutions
Prior to AWS Provider v4, we allowed these arguments (e.g.,
destination_cidr_block
) to be empty strings, subverting the correct validation that exactly one of 3 arguments needed to be set to a non-empty value. Practitioners used the empty string as an out to avoid an error whencount = 0
.With v4, we corrected the validation but broke some configurations. We published the change as breaking since configurations would need to use
null
instead of an empty string. Unfortunately, that also inadvertently took away the "out" that practitioners were using to allow the combination ofdestination_cidr_block = ""
withcount = 0
to pass validation.Proposal
Evaluate
ExactlyOneOf
later in the process so that it is evaluated aftercount > 0
is determined.References
The text was updated successfully, but these errors were encountered: