-
Notifications
You must be signed in to change notification settings - Fork 16
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
Getting "Only image or source_instance can be set" even if source_instance defaults to null #180
Comments
Definitely a bit of an odd one. @maveonair any thoughts? |
I built the provider on my machine and added a println and here is what I got fmt.Println(config.SourceInstance)
fmt.Println(config.Image)
/* | <unknown>
| "images:ubuntu/22.04" */ |
I think I understand what's going on The mutual exclusivity check is done too early here. While Image and SourceInstance can still be UNKOWN if they are fed into the resource from variables. if !config.Image.IsNull() && !config.SourceInstance.IsNull() {
resp.Diagnostics.AddError(
"Invalid Configuration",
"Only image or source_instance can be set.",
)
return
} I don't know where exactly is the best place to add the actual check but I suspect it would be
|
Actually, this is exactly what should happen. You can either create an instance from an image or We can try to also check for the unknown state of the values to see if it catches null too. But we need to do it there as we also need this checks for updates. |
This will be true for Since this condition will always (at least most of the times) evaluate to True. |
If we consider the unknown state as well and let it basically overrule the null check, we would need to check again in the actual methods, that perform the operations (create, update), because only then we get the fully resolved resources and only then we can decide, if we have the case, where multiple of the mutual exclusive options (image, source_file and source_instance) are provided.
The code you are referring to is validating, if the given value for |
I created a PR to make use of the Sorry if this is incomplete, I just worked to start a POC and get your opinion on it, then start finishing up the work on the PR and start the review. |
I did more testing and the new behavior is a little bit more interesting For this example:
Using variables with default values, everything works as expected
But when setting the attributes to literals
So what happens is when one of the attribute is set in the resource itself, the other ones should be omitted or set to null explicitly ( |
@Iduoad In general I like the code you have in PR #181, since it replaces the existing logic with two simple Validators and with this does make it more clear and easier to reason about. There is an issue though, since your validators do not exactly the same as the existing logic: Additionally, while your change does make the code better, it does not solve the issue with |
@Iduoad after thinking again, I wonder if the |
Hi,
The following code cannot plan and keeps failing with
Only image or source_instance can be set
even ifsource_instance
variable default tonull
.when I try the following it works
Went through a bit of the source code but couldn't figure out what was the issue
Thank you for the great work
The text was updated successfully, but these errors were encountered: