rgl / packer-plugin-windows-update

Packer plugin for installing Windows updates
Mozilla Public License 2.0
307 stars 71 forks source link

Conditional values for SearchCriteria and Filters #128

Open raptorrico opened 1 year ago

raptorrico commented 1 year ago

I need to conditionally define the parameter values for SearchCriteria and Filters. Would I need to run the windows-update.ps1 script rather than using the provisioner?

For example, set variables for both and then call the script

$varSearchCriteria = 'IsInstalled=0' $varFilters = @('include:$true')

windows-update.ps1 -SearchCriteria $varCriteria -Filters $varFilters

Is it possible to achieve the above using the provisioner?

saily commented 3 months ago

Hi @raptorrico, not sure this helps with your use-case, but I override the value of my variable update (which is true by default) using packer build -var update=false ... to skip updates for faster testing, see below:


provisioner "windows-update" {
    search_criteria = "IsInstalled=0"
    filters = var.update ? ["exclude:$true"] : [
      "exclude:$_.Title -like '*Preview*'",
      "exclude:$_.Title -like '*Silverlight*'",
      "exclude:$_.InstallationBehavior.CanRequestUserInput",
      "include:$true"
    ]
}
´´´