Skip to content
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

feat: support setting instance_termination_action for Spot VMs #346

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
| source\_image\_family | Source image family. If neither source\_image nor source\_image\_family is specified, defaults to the latest public CentOS image. | `string` | `"centos-7"` | no |
| source\_image\_project | Project where the source image comes from. The default project contains CentOS images. | `string` | `"centos-cloud"` | no |
| spot | Provision a SPOT instance | `bool` | `false` | no |
| spot\_instance\_termination\_action | Action to take when Compute Engine preempts a Spot VM. | `string` | `"STOP"` | no |
| stack\_type | The stack type for this network interface to identify whether the IPv6 feature is enabled or not. Values are `IPV4_IPV6` or `IPV4_ONLY`. Default behavior is equivalent to IPV4\_ONLY. | `string` | `null` | no |
| startup\_script | User startup script to run when instances spin up | `string` | `""` | no |
| subnetwork | The name of the subnetwork to attach this interface to. The subnetwork must exist in the same region this instance will be created in. Either network or subnetwork must be provided. | `string` | `""` | no |
Expand Down
2 changes: 1 addition & 1 deletion modules/instance_template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ resource "google_compute_instance_template" "tpl" {
automatic_restart = local.automatic_restart
on_host_maintenance = local.on_host_maintenance
provisioning_model = var.spot ? "SPOT" : null
instance_termination_action = var.spot ? "STOP" : null
instance_termination_action = var.spot ? var.spot_instance_termination_action : null
}

advanced_machine_features {
Expand Down
11 changes: 11 additions & 0 deletions modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ variable "on_host_maintenance" {
default = "MIGRATE"
}

variable "spot_instance_termination_action" {
description = "Action to take when Compute Engine preempts a Spot VM."
type = string
default = "STOP"

validation {
condition = contains(["STOP", "DELETE"], var.spot_instance_termination_action)
error_message = "Allowed values for spot_instance_termination_action are: \"STOP\" or \"DELETE\"."
}
}

variable "region" {
type = string
description = "Region where the instance template should be created."
Expand Down