diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 8fa374306..78141bed4 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -93,13 +93,23 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if c.ImageDescription == "" { c.ImageDescription = "Created by Packer" } - // Possible values: - // "MIGRATE" - // "TERMINATE" - if c.OnHostMaintenance == "" { + // Setting OnHostMaintenance Correct Defaults + // "MIGRATE" : Possible if Preemptible is false + // "TERMINATE": Posssible if Preemptible is true + if c.OnHostMaintenance == "" && c.Preemptible { c.OnHostMaintenance = "MIGRATE" } + if c.OnHostMaintenance == "" && !c.Preemptible { + c.OnHostMaintenance = "TERMINATE" + } + + // Make sure user sets a valid value for on_host_maintenance option + if !(c.OnHostMaintenance == "MIGRATE" || c.OnHostMaintenance == "TERMINATE") { + errs = packer.MultiErrorAppend(errs, + errors.New("on_host_maintenance must be one of MIGRATE or TERMINATE.")) + } + if c.ImageName == "" { img, err := interpolate.Render("packer-{{timestamp}}", nil) if err != nil { diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index 210601948..e65da2794 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -117,7 +117,7 @@ func TestConfigPrepare(t *testing.T) { { "on_host_maintenance", "SO VERY BAD", - false, + true, }, { "preemptible", diff --git a/website/source/docs/builders/googlecompute.html.md b/website/source/docs/builders/googlecompute.html.md index a54099418..571fe1b6c 100644 --- a/website/source/docs/builders/googlecompute.html.md +++ b/website/source/docs/builders/googlecompute.html.md @@ -178,6 +178,13 @@ builder. `use_internal_ip` must be true if this property is true. - `preemptible` (boolean) - If true, launch a preembtible instance. +- 'on_host_maintenance' (string) - Sets Host Maintenance Option + valid strings "MIGRATE" and "TERMINATE" please see + [GCE Instance Scheduling Options](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options) + Not all machine_type in google support MIGRATE (machines with gpu) + also preemptiblity will impact available options + - preemptible == true , defaults to TERMINATE + - preemptible == false , defaults to MIGRATE - `region` (string) - The region in which to launch the instance. Defaults to to the region hosting the specified `zone`.