-
Notifications
You must be signed in to change notification settings - Fork 28
Post-Processor: added vagrantfile_template_content option to allow for dynamic Vagrantfile content
#112
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
base: main
Are you sure you want to change the base?
Post-Processor: added vagrantfile_template_content option to allow for dynamic Vagrantfile content
#112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,6 +75,7 @@ type Config struct { | |||||||||||||||||
| OutputPath string `mapstructure:"output"` | ||||||||||||||||||
| Override map[string]interface{} | ||||||||||||||||||
| VagrantfileTemplate string `mapstructure:"vagrantfile_template"` | ||||||||||||||||||
| VagrantfileTemplateContent string `mapstructure:"vagrantfile_template_content"` | ||||||||||||||||||
| VagrantfileTemplateGenerated bool `mapstructure:"vagrantfile_template_generated"` | ||||||||||||||||||
| ProviderOverride string `mapstructure:"provider_override"` | ||||||||||||||||||
| Architecture string `mapstructure:"architecture"` | ||||||||||||||||||
|
|
@@ -190,12 +191,20 @@ func (p *PostProcessor) PostProcessProvider(name string, provider Provider, ui p | |||||||||||||||||
| var customVagrantfile string | ||||||||||||||||||
| if config.VagrantfileTemplate != "" { | ||||||||||||||||||
| ui.Message(fmt.Sprintf("Using custom Vagrantfile: %s", config.VagrantfileTemplate)) | ||||||||||||||||||
| customBytes, err := ioutil.ReadFile(config.VagrantfileTemplate) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, false, err | ||||||||||||||||||
|
|
||||||||||||||||||
| var templateContent string | ||||||||||||||||||
| if config.VagrantfileTemplateContent != "" { | ||||||||||||||||||
| templateContent = config.VagrantfileTemplateContent | ||||||||||||||||||
| } else { | ||||||||||||||||||
| customBytes, err := ioutil.ReadFile(config.VagrantfileTemplate) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, false, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| templateContent = string(customBytes) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| customVagrantfile, err = interpolate.Render(string(customBytes), &config.ctx) | ||||||||||||||||||
| customVagrantfile, err = interpolate.Render(templateContent, &config.ctx) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| return nil, false, err | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -292,6 +301,10 @@ func (p *PostProcessor) configureSingle(c *Config, raws ...interface{}) error { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| var errs *packersdk.MultiError | ||||||||||||||||||
| if c.VagrantfileTemplateContent != "" && c.VagrantfileTemplate == "" { | ||||||||||||||||||
| errs = packersdk.MultiErrorAppend(errs, fmt.Errorf( | ||||||||||||||||||
| "'vagrantfile_template' should be provided to use 'vagrantfile_template_content'")) | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+304
to
+307
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am of the understanding that you would want to specify just the content with no filepath needed. Is that not the case? If they are mutually exclusive I would rewrite the logic to be as follows:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||
| if c.VagrantfileTemplate != "" && c.VagrantfileTemplateGenerated == false { | ||||||||||||||||||
| _, err := os.Stat(c.VagrantfileTemplate) | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
|
|
||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 believe this condition might be nested in a conflicting if statement.
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.
@nywilken could you please see the below comment #112 (comment) and let me know if this is still needs to be changed !!