Adding OnHostMaintenance option for googlecompue builder

This commit is contained in:
Dimitri Rudnev 2017-02-10 10:58:57 -08:00
parent e04f87effe
commit bab590c177
5 changed files with 26 additions and 1 deletions

View File

@ -39,6 +39,7 @@ type Config struct {
Network string `mapstructure:"network"`
NetworkProjectId string `mapstructure:"network_project_id"`
OmitExternalIP bool `mapstructure:"omit_external_ip"`
OnHostMaintenance string `mapstructure:"on_host_maintenance"`
Preemptible bool `mapstructure:"preemptible"`
RawStateTimeout string `mapstructure:"state_timeout"`
Region string `mapstructure:"region"`
@ -92,6 +93,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
if c.ImageDescription == "" {
c.ImageDescription = "Created by Packer"
}
// Possible values:
// "MIGRATE"
// "TERMINATE"
if c.OnHostMaintenance == "" {
c.OnHostMaintenance = "MIGRATE"
}
if c.ImageName == "" {
img, err := interpolate.Render("packer-{{timestamp}}", nil)

View File

@ -104,6 +104,21 @@ func TestConfigPrepare(t *testing.T) {
"SO VERY BAD",
true,
},
{
"on_host_maintenance",
nil,
false,
},
{
"on_host_maintenance",
"TERMINATE",
false,
},
{
"on_host_maintenance",
"SO VERY BAD",
false,
},
{
"preemptible",
nil,

View File

@ -69,6 +69,7 @@ type InstanceConfig struct {
Network string
NetworkProjectId string
OmitExternalIP bool
OnHostMaintenance string
Preemptible bool
Region string
Scopes []string

View File

@ -386,7 +386,8 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
},
},
Scheduling: &compute.Scheduling{
Preemptible: c.Preemptible,
OnHostMaintenance: c.OnHostMaintenance,
Preemptible: c.Preemptible,
},
ServiceAccounts: []*compute.ServiceAccount{
{

View File

@ -110,6 +110,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
Network: c.Network,
NetworkProjectId: c.NetworkProjectId,
OmitExternalIP: c.OmitExternalIP,
OnHostMaintenance: c.OnHostMaintenance,
Preemptible: c.Preemptible,
Region: c.Region,
ServiceAccountEmail: c.Account.ClientEmail,