-
Notifications
You must be signed in to change notification settings - Fork 127
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
d/image: add most_recent filter to support multiple matches #82
Conversation
}) | ||
log.Printf("[DEBUG] got %d images: %#v\n", len(images), images) | ||
|
||
if len(images) > 1 && !mostRecent { |
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.
If we use most_recent
+ name_filter
with Ubuntu
, it will return the most recent image among all ( Xenial
, Bionic
, ...).
Is not it better to check before if all the names are identical ?
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.
this would not return the most recent ubuntu release, but the most recently build ubuntu release; mighy be different!
The linked issue is different tho: the names are identical, but the IDs are not. The issue of identical names with different ids can not be resolved currently.
Do you see a better option to solve this, @xunleii?
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.
(yep, sorry, I meant the most recent build and not the most recent release when I've said it will return the most recent image
)
For me, it's a great option to solve this problem, but it can sometimes behave unexpectedly; as mentioned above, if we use the most_recent
andname_filter = "Ubuntu"
options at the same time, the resulting image will be Ubuntu Xenial
or Ubuntu Bionic
, or whatever, depending on the most recent build date (and doesn't return "The query returned more than one result."
as expected).
This can be easily solved by checking if in images
, all names are the same. If so, we can select the most recent, otherwise simply return "The query returned more than one result."
.
What do you think about this idea, @nicolai86 ?
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.
I agree that name_filter
with most_recent
is most likely a bad combination, but I'm not sure it deserves special handling at this point. What do you think about disallowing the combination altogether and defering a decision until we have more data about this use case?
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.
I think it's a good idea.
Thanks for this review :)
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.
Thank you for the good feedback!
this combination can yield inexpected and undesirable results, e.g. name_filter = "Ubuntu" most_recent = true This would return the most recently build image for ubuntu, which could be very old e.g. because the old images needed to be rebuild due to a security issue.
I'll pull in this change optimistically 8/15 |
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.
otherwise LGTM - but it'd be nice to add a test if possible?
scaleway/data_source_image.go
Outdated
"most_recent": { | ||
Type: schema.TypeBool, | ||
Required: false, | ||
Default: false, |
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.
minor you don't need to specify either of these, since they should be implied (false is the default value for a bool / required will be false since it's optional)
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.
gotcha.
website/docs/d/image.html.markdown
Outdated
@@ -34,6 +34,8 @@ resource "scaleway_server" "base" { | |||
|
|||
* `name` - (Optional) Exact name of desired Image | |||
|
|||
* `most_recent` - (Optional) Return most recent image if multiple exist |
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.
Probably worth suffixing with "this cannot be used with the name_prefix
field"?
tests remain green with adjustments:
|
once merged fixes #81.
Now the data source for images supports
most_recent
to only return the most recent image if multiple matches exist: