@@ -394,7 +394,7 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
394394 if provision .Mode == ProvisionModeDependency && provision .SkipDefaultDependencyResolution == nil {
395395 provision .SkipDefaultDependencyResolution = ptr .Of (false )
396396 }
397- if out , err := executeGuestTemplate (provision .Script , instDir ); err == nil {
397+ if out , err := executeGuestTemplate (provision .Script , instDir , y . Param ); err == nil {
398398 provision .Script = out .String ()
399399 } else {
400400 logrus .WithError (err ).Warnf ("Couldn't process provisioning script %q as a template" , provision .Script )
@@ -460,17 +460,22 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
460460 if probe .Description == "" {
461461 probe .Description = fmt .Sprintf ("user probe %d/%d" , i + 1 , len (y .Probes ))
462462 }
463+ if out , err := executeGuestTemplate (probe .Script , instDir , y .Param ); err == nil {
464+ probe .Script = out .String ()
465+ } else {
466+ logrus .WithError (err ).Warnf ("Couldn't process probing script %q as a template" , probe .Script )
467+ }
463468 }
464469
465470 y .PortForwards = append (append (o .PortForwards , y .PortForwards ... ), d .PortForwards ... )
466471 for i := range y .PortForwards {
467- FillPortForwardDefaults (& y .PortForwards [i ], instDir )
472+ FillPortForwardDefaults (& y .PortForwards [i ], instDir , y . Param )
468473 // After defaults processing the singular HostPort and GuestPort values should not be used again.
469474 }
470475
471476 y .CopyToHost = append (append (o .CopyToHost , y .CopyToHost ... ), d .CopyToHost ... )
472477 for i := range y .CopyToHost {
473- FillCopyToHostDefaults (& y .CopyToHost [i ], instDir )
478+ FillCopyToHostDefaults (& y .CopyToHost [i ], instDir , y . Param )
474479 }
475480
476481 if y .HostResolver .Enabled == nil {
@@ -669,6 +674,18 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
669674 }
670675 y .Env = env
671676
677+ param := make (map [string ]string )
678+ for k , v := range d .Param {
679+ param [k ] = v
680+ }
681+ for k , v := range y .Param {
682+ param [k ] = v
683+ }
684+ for k , v := range o .Param {
685+ param [k ] = v
686+ }
687+ y .Param = param
688+
672689 if y .CACertificates .RemoveDefaults == nil {
673690 y .CACertificates .RemoveDefaults = d .CACertificates .RemoveDefaults
674691 }
@@ -735,15 +752,16 @@ func fixUpForPlainMode(y *LimaYAML) {
735752 y .TimeZone = ptr .Of ("" )
736753}
737754
738- func executeGuestTemplate (format , instDir string ) (bytes.Buffer , error ) {
755+ func executeGuestTemplate (format , instDir string , param map [ string ] string ) (bytes.Buffer , error ) {
739756 tmpl , err := template .New ("" ).Parse (format )
740757 if err == nil {
741758 user , _ := osutil .LimaUser (false )
742- data := map [string ]string {
743- "Home" : fmt .Sprintf ("/home/%s.linux" , user .Username ),
744- "Name" : filepath .Base (instDir ),
745- "UID" : user .Uid ,
746- "User" : user .Username ,
759+ data := map [string ]interface {}{
760+ "Home" : fmt .Sprintf ("/home/%s.linux" , user .Username ),
761+ "Name" : filepath .Base (instDir ),
762+ "UID" : user .Uid ,
763+ "User" : user .Username ,
764+ "Param" : param ,
747765 }
748766 var out bytes.Buffer
749767 if err := tmpl .Execute (& out , data ); err == nil {
@@ -753,18 +771,19 @@ func executeGuestTemplate(format, instDir string) (bytes.Buffer, error) {
753771 return bytes.Buffer {}, err
754772}
755773
756- func executeHostTemplate (format , instDir string ) (bytes.Buffer , error ) {
774+ func executeHostTemplate (format , instDir string , param map [ string ] string ) (bytes.Buffer , error ) {
757775 tmpl , err := template .New ("" ).Parse (format )
758776 if err == nil {
759777 user , _ := osutil .LimaUser (false )
760778 home , _ := os .UserHomeDir ()
761779 limaHome , _ := dirnames .LimaDir ()
762- data := map [string ]string {
763- "Dir" : instDir ,
764- "Home" : home ,
765- "Name" : filepath .Base (instDir ),
766- "UID" : user .Uid ,
767- "User" : user .Username ,
780+ data := map [string ]interface {}{
781+ "Dir" : instDir ,
782+ "Home" : home ,
783+ "Name" : filepath .Base (instDir ),
784+ "UID" : user .Uid ,
785+ "User" : user .Username ,
786+ "Param" : param ,
768787
769788 "Instance" : filepath .Base (instDir ), // DEPRECATED, use `{{.Name}}`
770789 "LimaHome" : limaHome , // DEPRECATED, use `{{.Dir}}` instead of `{{.LimaHome}}/{{.Instance}}`
@@ -777,7 +796,7 @@ func executeHostTemplate(format, instDir string) (bytes.Buffer, error) {
777796 return bytes.Buffer {}, err
778797}
779798
780- func FillPortForwardDefaults (rule * PortForward , instDir string ) {
799+ func FillPortForwardDefaults (rule * PortForward , instDir string , param map [ string ] string ) {
781800 if rule .Proto == "" {
782801 rule .Proto = TCP
783802 }
@@ -809,14 +828,14 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
809828 }
810829 }
811830 if rule .GuestSocket != "" {
812- if out , err := executeGuestTemplate (rule .GuestSocket , instDir ); err == nil {
831+ if out , err := executeGuestTemplate (rule .GuestSocket , instDir , param ); err == nil {
813832 rule .GuestSocket = out .String ()
814833 } else {
815834 logrus .WithError (err ).Warnf ("Couldn't process guestSocket %q as a template" , rule .GuestSocket )
816835 }
817836 }
818837 if rule .HostSocket != "" {
819- if out , err := executeHostTemplate (rule .HostSocket , instDir ); err == nil {
838+ if out , err := executeHostTemplate (rule .HostSocket , instDir , param ); err == nil {
820839 rule .HostSocket = out .String ()
821840 } else {
822841 logrus .WithError (err ).Warnf ("Couldn't process hostSocket %q as a template" , rule .HostSocket )
@@ -827,16 +846,16 @@ func FillPortForwardDefaults(rule *PortForward, instDir string) {
827846 }
828847}
829848
830- func FillCopyToHostDefaults (rule * CopyToHost , instDir string ) {
849+ func FillCopyToHostDefaults (rule * CopyToHost , instDir string , param map [ string ] string ) {
831850 if rule .GuestFile != "" {
832- if out , err := executeGuestTemplate (rule .GuestFile , instDir ); err == nil {
851+ if out , err := executeGuestTemplate (rule .GuestFile , instDir , param ); err == nil {
833852 rule .GuestFile = out .String ()
834853 } else {
835854 logrus .WithError (err ).Warnf ("Couldn't process guest %q as a template" , rule .GuestFile )
836855 }
837856 }
838857 if rule .HostFile != "" {
839- if out , err := executeHostTemplate (rule .HostFile , instDir ); err == nil {
858+ if out , err := executeHostTemplate (rule .HostFile , instDir , param ); err == nil {
840859 rule .HostFile = out .String ()
841860 } else {
842861 logrus .WithError (err ).Warnf ("Couldn't process host %q as a template" , rule .HostFile )
0 commit comments