Skip to content
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

Get VM template by regexp and most_recent #322

Closed
ghost opened this issue Aug 6, 2022 · 9 comments · Fixed by #388
Closed

Get VM template by regexp and most_recent #322

ghost opened this issue Aug 6, 2022 · 9 comments · Fixed by #388

Comments

@ghost
Copy link

ghost commented Aug 6, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

It's will be good idea:

New or Affected Resource(s)

  • opennebula_template

Potential Terraform Configuration

data "opennebula_template" "example" {
  most_recent      = true
  name_regex       = "^myopennebula-\\d{3}"
}
@frousselet
Copy link
Collaborator

Thanks for the suggestion.

In the AWS AMI case, the most_recent attribute is useful since an AMI is versioned, which is not the case with an OpenNebula template.

So with this regex attribute you will get an array of templates. Maybe we can add an attribute to choose what key is used to order the array?

But anyway, if the data can return more than one attribute (which is a use case of a regex search), it should be opennebula_templates (with an 's') along side opennebula_template, because opennebula_template should return zero or one template and not zero or N.

@frousselet frousselet changed the title Get VM template by regexp and most_resent Get VM template by regexp and most_recent Aug 8, 2022
@ghost
Copy link
Author

ghost commented Aug 9, 2022

Hi @frousselet!
Thanks for reply. Yes, I mean that searcing by regex can return more than one opennebula_template - in our case opennebula_templates.
And, I think, that most_recent can be ordered by Registration time, i.e. last uploaded template

@frousselet
Copy link
Collaborator

frousselet commented Aug 10, 2022

Hello,

So we can think about something like this:

data "opennebula_templates" "example" {
  name_regex = "^myopennebula-\\d{3}"

  order_by = [
    "register_time",
    "<second_level_order>",
    # ...
  ]
  order_direction = "DESC"
}

Then you can select the first result of the array.

@treywelsh, what do you think?

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity and it has not the 'status: confirmed' label or it is not in a milestone. Remove the 'status: stale' label or comment, or this will be closed in 5 days.

@Prakharkarsh1
Copy link

Hii @ghost i want to contribute to fix this issue

@deynekoaa
Copy link

Hi @Prakharkarsh1!
It will be great, if you can fix this issue

@frousselet
Copy link
Collaborator

Hello @Prakharkarsh1,

Sorry for the late reply.
It would be great if you can contribute.

This issue probably apply to other data sources.

@frousselet frousselet added this to the 1.2.0 milestone Oct 3, 2022
@treywelsh
Copy link
Collaborator

treywelsh commented Jan 4, 2023

by most_recent, we means the most recent creation date (regardless of the template updates), right ?
It seems that the Register time field of the template in OpenNebula could be used to compare creation date.

Else I'm ok with @frousselet proposal, but do we need to order based on several fields ?
In addition, the datasource you propose seems closer to aws_ami_ids than the initially mentionned resource aws_ami which seems to pick the first AMI of the list

@treywelsh
Copy link
Collaborator

treywelsh commented Jan 5, 2023

I made a minimal draft implementation that works in a similar way that @frousselet proposed (it's a quickly written stuff so it's easy to make it crash, be careful) in #388.
The goal of this draft is only to show a way to do, I'm open to fully rewrite it if it's not useful.

This allows something like:

data "opennebula_templates" "test" {
  name_regex = "^myopennebula-\\d{3}"
  has_cpu    = true
  order_by   = "register_date"
  order      = "DESC"
}

resource "opennebula_virtual_machine" "example2" {
  name        = "test2"
  description = "VM"

  memory      = 64
  cpu         = 0.1

  template_id = data.opennebula_templates.test.templates[2].id
}

The implementation store a list of templates data (don't know if all of these data are useful but I had in mind that this could be used to chose a template based on it's datas when automating stuffs).

Feel free to test it and give feedback it's helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants