Skip to content

Commit 6f74715

Browse files
tpdownesg-awmalik
andauthored
feat: support setting instance_termination_action for Spot VMs (#346)
Co-authored-by: Awais Malik <[email protected]>
1 parent 04fa8f6 commit 6f74715

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

modules/instance_template/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
4747
| 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 |
4848
| source\_image\_project | Project where the source image comes from. The default project contains CentOS images. | `string` | `"centos-cloud"` | no |
4949
| spot | Provision a SPOT instance | `bool` | `false` | no |
50+
| spot\_instance\_termination\_action | Action to take when Compute Engine preempts a Spot VM. | `string` | `"STOP"` | no |
5051
| 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 |
5152
| startup\_script | User startup script to run when instances spin up | `string` | `""` | no |
5253
| 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 |

modules/instance_template/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ resource "google_compute_instance_template" "tpl" {
177177
automatic_restart = local.automatic_restart
178178
on_host_maintenance = local.on_host_maintenance
179179
provisioning_model = var.spot ? "SPOT" : null
180-
instance_termination_action = var.spot ? "STOP" : null
180+
instance_termination_action = var.spot ? var.spot_instance_termination_action : null
181181
}
182182

183183
advanced_machine_features {

modules/instance_template/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ variable "on_host_maintenance" {
8080
default = "MIGRATE"
8181
}
8282

83+
variable "spot_instance_termination_action" {
84+
description = "Action to take when Compute Engine preempts a Spot VM."
85+
type = string
86+
default = "STOP"
87+
88+
validation {
89+
condition = contains(["STOP", "DELETE"], var.spot_instance_termination_action)
90+
error_message = "Allowed values for spot_instance_termination_action are: \"STOP\" or \"DELETE\"."
91+
}
92+
}
93+
8394
variable "region" {
8495
type = string
8596
description = "Region where the instance template should be created."

0 commit comments

Comments
 (0)