provider/google: Added `preemtible` flag to `instance_template`
This commit is contained in:
parent
b19953e48c
commit
2da1ba0118
|
@ -163,12 +163,42 @@ func resourceComputeInstanceTemplate() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: true,
|
Default: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
Deprecated: "Please use `scheduling.automatic_restart` instead",
|
||||||
},
|
},
|
||||||
|
|
||||||
"on_host_maintenance": &schema.Schema{
|
"on_host_maintenance": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
Deprecated: "Please use `scheduling.on_host_maintenance` instead",
|
||||||
|
},
|
||||||
|
|
||||||
|
"scheduling": &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"preemptible": &schema.Schema{
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"automatic_restart": &schema.Schema{
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"on_host_maintenance": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"service_account": &schema.Schema{
|
"service_account": &schema.Schema{
|
||||||
|
@ -352,14 +382,38 @@ func resourceComputeInstanceTemplateCreate(d *schema.ResourceData, meta interfac
|
||||||
}
|
}
|
||||||
instanceProperties.NetworkInterfaces = networks
|
instanceProperties.NetworkInterfaces = networks
|
||||||
|
|
||||||
instanceProperties.Scheduling = &compute.Scheduling{
|
instanceProperties.Scheduling = &compute.Scheduling{}
|
||||||
AutomaticRestart: d.Get("automatic_restart").(bool),
|
|
||||||
}
|
|
||||||
instanceProperties.Scheduling.OnHostMaintenance = "MIGRATE"
|
instanceProperties.Scheduling.OnHostMaintenance = "MIGRATE"
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("automatic_restart"); ok {
|
||||||
|
instanceProperties.Scheduling.AutomaticRestart = v.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("on_host_maintenance"); ok {
|
if v, ok := d.GetOk("on_host_maintenance"); ok {
|
||||||
instanceProperties.Scheduling.OnHostMaintenance = v.(string)
|
instanceProperties.Scheduling.OnHostMaintenance = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("scheduling"); ok {
|
||||||
|
_schedulings := v.([]interface{})
|
||||||
|
if len(_schedulings) > 1 {
|
||||||
|
return fmt.Errorf("Error, at most one `scheduling` block can be defined")
|
||||||
|
}
|
||||||
|
_scheduling := _schedulings[0].(map[string]interface{})
|
||||||
|
|
||||||
|
if vp, okp := _scheduling["automatic_restart"]; okp {
|
||||||
|
instanceProperties.Scheduling.AutomaticRestart = vp.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if vp, okp := _scheduling["on_host_maintenance"]; okp {
|
||||||
|
instanceProperties.Scheduling.OnHostMaintenance = vp.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if vp, okp := _scheduling["preemptible"]; okp {
|
||||||
|
instanceProperties.Scheduling.Preemptible = vp.(bool)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
serviceAccountsCount := d.Get("service_account.#").(int)
|
serviceAccountsCount := d.Get("service_account.#").(int)
|
||||||
serviceAccounts := make([]*compute.ServiceAccount, 0, serviceAccountsCount)
|
serviceAccounts := make([]*compute.ServiceAccount, 0, serviceAccountsCount)
|
||||||
for i := 0; i < serviceAccountsCount; i++ {
|
for i := 0; i < serviceAccountsCount; i++ {
|
||||||
|
|
|
@ -218,6 +218,11 @@ resource "google_compute_instance_template" "foobar" {
|
||||||
network = "default"
|
network = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheduling {
|
||||||
|
preemptible = false
|
||||||
|
automatic_restart = true
|
||||||
|
}
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,13 +86,14 @@ The following arguments are supported:
|
||||||
This can be specified multiple times for multiple networks. Structure is
|
This can be specified multiple times for multiple networks. Structure is
|
||||||
documented below.
|
documented below.
|
||||||
|
|
||||||
* `automatic_restart` - (Optional) Specifies whether the instance should be
|
* `automatic_restart` - (Optional, Deprecated - see `scheduling`)
|
||||||
|
Specifies whether the instance should be
|
||||||
automatically restarted if it is terminated by Compute Engine (not
|
automatically restarted if it is terminated by Compute Engine (not
|
||||||
terminated by a user).
|
terminated by a user).
|
||||||
This defaults to true.
|
This defaults to true.
|
||||||
|
|
||||||
* `on_host_maintenance` - (Optional) Defines the maintenance behavior for this
|
* `on_host_maintenance` - (Optional, Deprecated - see `scheduling`)
|
||||||
instance.
|
Defines the maintenance behavior for this instance.
|
||||||
|
|
||||||
* `service_account` - (Optional) Service account to attach to the instance.
|
* `service_account` - (Optional) Service account to attach to the instance.
|
||||||
|
|
||||||
|
@ -150,6 +151,18 @@ The `service_account` block supports:
|
||||||
* `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
|
* `scopes` - (Required) A list of service scopes. Both OAuth2 URLs and gcloud
|
||||||
short names are supported.
|
short names are supported.
|
||||||
|
|
||||||
|
The `scheduling` block supports:
|
||||||
|
|
||||||
|
* `automatic_restart` - (Optional) Specifies whether the instance should be
|
||||||
|
automatically restarted if it is terminated by Compute Engine (not
|
||||||
|
terminated by a user).
|
||||||
|
This defaults to true.
|
||||||
|
|
||||||
|
* `on_host_maintenance` - (Optional) Defines the maintenance behavior for this instance.
|
||||||
|
|
||||||
|
* `preemptible` - (Optional) Allows instance to be preempted. Read
|
||||||
|
more on this [here](https://cloud.google.com/compute/docs/instances/preemptible).
|
||||||
|
|
||||||
## Attributes Reference
|
## Attributes Reference
|
||||||
|
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
Loading…
Reference in New Issue